|
| 1 | +// |
| 2 | +// WindowCloseCommandTests.swift |
| 3 | +// CodeEditUITests |
| 4 | +// |
| 5 | +// Created by Khan Winter on 7/21/24. |
| 6 | +// |
| 7 | + |
| 8 | +import XCTest |
| 9 | + |
| 10 | +/// Tests for window closing commands. |
| 11 | +/// - Note: feel free to add on in the future and change this test name. |
| 12 | +final class WindowCloseCommandTests: XCTestCase { |
| 13 | + // swiftier api (expectation(that: , on:, willEqual:) doesn't work :( |
| 14 | + let notExistsPredicate = NSPredicate(format: "exists == false") |
| 15 | + |
| 16 | + var application: XCUIApplication! |
| 17 | + |
| 18 | + func testWorkspaceWindowCloses() { |
| 19 | + application = App.launchWithCodeEditWorkspace() |
| 20 | + let window = Query.getWindow(application) |
| 21 | + XCTAssertTrue(window.waitForExistence(timeout: 5.0), "Workspace didn't open") |
| 22 | + window.toolbars.firstMatch.click() |
| 23 | + |
| 24 | + let expectation = expectation(for: notExistsPredicate, evaluatedWith: window) |
| 25 | + application.typeKey("w", modifierFlags: .command) |
| 26 | + wait(for: [expectation], timeout: 5.0) |
| 27 | + } |
| 28 | + |
| 29 | + func testWorkspaceTabCloses() { |
| 30 | + application = App.launchWithCodeEditWorkspace() |
| 31 | + let window = Query.getWindow(application) |
| 32 | + XCTAssertTrue(window.waitForExistence(timeout: 5.0), "Workspace didn't open") |
| 33 | + |
| 34 | + window.toolbars.firstMatch.click() |
| 35 | + |
| 36 | + let navigator = Query.Window.getProjectNavigator(window) |
| 37 | + let readmeRow = Query.Navigator.getProjectNavigatorRow(fileTitle: "README.md", navigator) |
| 38 | + XCTAssertTrue(navigator.exists) |
| 39 | + XCTAssertTrue(readmeRow.exists) |
| 40 | + readmeRow.click() |
| 41 | + |
| 42 | + let tabBar = Query.Window.getTabBar(window) |
| 43 | + XCTAssertTrue(tabBar.exists) |
| 44 | + let readmeTab = Query.TabBar.getTab(labeled: "README.md", tabBar) |
| 45 | + XCTAssertTrue(readmeTab.exists) |
| 46 | + XCTAssertEqual(tabBar.descendants(matching: .group).count, 1) |
| 47 | + |
| 48 | + let tabCloseExpectation = expectation(for: notExistsPredicate, evaluatedWith: readmeTab) |
| 49 | + application.typeKey("w", modifierFlags: .command) |
| 50 | + wait(for: [tabCloseExpectation], timeout: 5.0) |
| 51 | + XCTAssertEqual(tabBar.descendants(matching: .group).count, 0) |
| 52 | + |
| 53 | + let windowCloseExpectation = expectation(for: notExistsPredicate, evaluatedWith: window) |
| 54 | + application.typeKey("w", modifierFlags: .command) |
| 55 | + wait(for: [windowCloseExpectation], timeout: 5.0) |
| 56 | + } |
| 57 | + |
| 58 | + func testWorkspaceClosesWithTabStillOpen() { |
| 59 | + application = App.launchWithCodeEditWorkspace() |
| 60 | + let window = Query.getWindow(application) |
| 61 | + XCTAssertTrue(window.waitForExistence(timeout: 5.0), "Workspace didn't open") |
| 62 | + |
| 63 | + window.toolbars.firstMatch.click() |
| 64 | + |
| 65 | + let navigator = Query.Window.getProjectNavigator(window) |
| 66 | + let readmeRow = Query.Navigator.getProjectNavigatorRow(fileTitle: "README.md", navigator) |
| 67 | + XCTAssertTrue(navigator.exists) |
| 68 | + XCTAssertTrue(readmeRow.exists) |
| 69 | + readmeRow.click() |
| 70 | + |
| 71 | + let tabBar = Query.Window.getTabBar(window) |
| 72 | + XCTAssertTrue(tabBar.exists) |
| 73 | + let readmeTab = Query.TabBar.getTab(labeled: "README.md", tabBar) |
| 74 | + XCTAssertTrue(readmeTab.exists) |
| 75 | + XCTAssertEqual(tabBar.descendants(matching: .group).count, 1) |
| 76 | + |
| 77 | + let windowCloseExpectation = expectation(for: notExistsPredicate, evaluatedWith: window) |
| 78 | + application.typeKey("w", modifierFlags: [.shift, .command]) |
| 79 | + wait(for: [windowCloseExpectation], timeout: 5.0) |
| 80 | + } |
| 81 | + |
| 82 | + func testSettingsWindowCloses() { |
| 83 | + application = App.launch() |
| 84 | + let window = Query.getSettingsWindow(application) |
| 85 | + application.typeKey(",", modifierFlags: .command) |
| 86 | + XCTAssertTrue(window.waitForExistence(timeout: 5.0), "Settings didn't open") |
| 87 | + |
| 88 | + let expectation = expectation(for: notExistsPredicate, evaluatedWith: window) |
| 89 | + application.typeKey("w", modifierFlags: .command) |
| 90 | + wait(for: [expectation], timeout: 5.0) |
| 91 | + } |
| 92 | + |
| 93 | + func testWelcomeWindowCloses() { |
| 94 | + application = App.launch() |
| 95 | + let window = Query.getWelcomeWindow(application) |
| 96 | + application.typeKey("1", modifierFlags: [.shift, .command]) |
| 97 | + XCTAssertTrue(window.waitForExistence(timeout: 5.0), "Welcome didn't open") |
| 98 | + |
| 99 | + let expectation = expectation(for: notExistsPredicate, evaluatedWith: window) |
| 100 | + application.typeKey("w", modifierFlags: .command) |
| 101 | + wait(for: [expectation], timeout: 5.0) |
| 102 | + } |
| 103 | + |
| 104 | + func testAboutWindowCloses() { |
| 105 | + application = App.launch() |
| 106 | + let window = Query.getAboutWindow(application) |
| 107 | + application.typeKey("2", modifierFlags: [.shift, .command]) |
| 108 | + XCTAssertTrue(window.waitForExistence(timeout: 5.0), "About didn't open") |
| 109 | + |
| 110 | + let expectation = expectation(for: notExistsPredicate, evaluatedWith: window) |
| 111 | + application.typeKey("w", modifierFlags: .command) |
| 112 | + wait(for: [expectation], timeout: 5.0) |
| 113 | + } |
| 114 | + |
| 115 | +} |
0 commit comments