-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathProjectNavigatorFileManagementUITests.swift
More file actions
133 lines (111 loc) Β· 4.88 KB
/
Copy pathProjectNavigatorFileManagementUITests.swift
File metadata and controls
133 lines (111 loc) Β· 4.88 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//
// ProjectNavigatorFileManagementUITests.swift
// CodeEditUITests
//
// Created by Khan Winter on 1/15/25.
//
import XCTest
final class ProjectNavigatorFileManagementUITests: XCTestCase {
var app: XCUIApplication!
var window: XCUIElement!
var navigator: XCUIElement!
var path: String!
override func setUp() async throws {
// MainActor required for async compatibility which is required to make this method throwing
try await MainActor.run {
if name.contains("testCreateNewFiles") {
(app, path) = App.launchWithAppWritableTempDir()
} else {
(app, path) = try App.launchWithTempDir()
}
window = Query.getWindow(app)
XCTAssertTrue(window.exists, "Window not found")
window.toolbars.firstMatch.click()
navigator = Query.Window.getProjectNavigator(window)
XCTAssertTrue(navigator.exists, "Navigator not found")
XCTAssertEqual(Query.Navigator.getRows(navigator).count, 1, "Found more than just the root file.")
if name.contains("testCreateNewFiles") {
var isDirectory: ObjCBool = false
XCTAssertTrue(
FileManager.default.fileExists(atPath: path, isDirectory: &isDirectory),
"App-writable temp directory was not created at \(path ?? "")"
)
XCTAssertTrue(isDirectory.boolValue, "App-writable temp project path is not a directory")
}
}
}
func testNewFilesAppear() throws {
// Create a few files, one in the base path and one inside a new folder. They should all appear in the navigator
guard FileManager.default.createFile(atPath: path.appending("/newFile.txt"), contents: nil) else {
XCTFail("Failed to create test file")
return
}
try FileManager.default.createDirectory(
atPath: path.appending("/New Folder"),
withIntermediateDirectories: true
)
guard FileManager.default.createFile(
atPath: path.appending("/New Folder/My New JS File.jsx"),
contents: nil
) else {
XCTFail("Failed to create second test file")
return
}
guard Query.Navigator.getProjectNavigatorRow(
fileTitle: "newFile.txt",
navigator
).waitForExistence(timeout: 2.0) else {
XCTFail("newFile.txt did not appear")
return
}
guard Query.Navigator.getProjectNavigatorRow(
fileTitle: "New Folder",
navigator
).waitForExistence(timeout: 2.0) else {
XCTFail("New Folder did not appear")
return
}
let folderRow = Query.Navigator.getProjectNavigatorRow(fileTitle: "New Folder", navigator)
folderRow.disclosureTriangles.element.click()
guard Query.Navigator.getProjectNavigatorRow(
fileTitle: "My New JS File.jsx",
navigator
).waitForExistence(timeout: 2.0) else {
XCTFail("New file inside the folder did not appear when folder was opened.")
return
}
}
func testCreateNewFiles() throws {
// Add a few files with the navigator button
for idx in 0..<5 {
let previousRowCount = Query.Navigator.getRows(navigator).count
let addButton = Query.Navigator.getAddButton(window)
XCTAssertTrue(addButton.waitForExistence(timeout: 2.0), "Add button not found")
addButton.click()
let addFileMenuItem = addButton.menuItems["Add File"]
XCTAssertTrue(addFileMenuItem.waitForExistence(timeout: 2.0), "Add File menu item not found")
addFileMenuItem.click()
let title = idx > 0 ? "untitled\(idx)" : "untitled"
XCTAssertTrue(
Query.Navigator.waitForRowCount(navigator, greaterThan: previousRowCount, timeout: 5.0),
"No new navigator row appeared after adding \(title)"
)
guard let newFileRow = Query.Navigator.waitForProjectNavigatorRow(
fileTitle: title,
navigator,
timeout: 5.0
) else {
XCTFail("\(title) did not appear in the navigator")
return
}
XCTAssertEqual(newFileRow.descendants(matching: .textField).firstMatch.value as? String, title)
let tabBar = Query.Window.getTabBar(window)
XCTAssertTrue(tabBar.waitForExistence(timeout: 2.0))
let newFileTab = Query.TabBar.getTab(labeled: title, tabBar)
XCTAssertTrue(newFileTab.waitForExistence(timeout: 2.0))
let newFileEditor = Query.Window.getFirstEditor(window)
XCTAssertTrue(newFileEditor.waitForExistence(timeout: 2.0))
XCTAssertNotNil(newFileEditor.value as? String)
}
}
}