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