-
-
Notifications
You must be signed in to change notification settings - Fork 193
Expand file tree
/
Copy pathExtn-CollapseFolders-integ-test.js
More file actions
241 lines (208 loc) · 10.3 KB
/
Extn-CollapseFolders-integ-test.js
File metadata and controls
241 lines (208 loc) · 10.3 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
* GNU AGPL-3.0 License
*
* Copyright (c) 2021 - present core.ai . All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
* for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
*
*/
/*global describe, it, expect, beforeAll, afterAll, beforeEach, afterEach, awaitsFor, awaitsForDone, awaits, jsPromise */
define(function (require, exports, module) {
const SpecRunnerUtils = require("spec/SpecRunnerUtils");
describe("integration:Collapse Folders", function () {
let testWindow, ProjectManager, FileSystem, $, testProjectPath, testProjectFolder;
beforeAll(async function () {
// Create the test window
testWindow = await SpecRunnerUtils.createTestWindowAndRun();
// Get reference to useful modules
$ = testWindow.$;
ProjectManager = testWindow.brackets.test.ProjectManager;
FileSystem = testWindow.brackets.test.FileSystem;
// Setup a test project folder with nested directories
testProjectPath = SpecRunnerUtils.getTempDirectory() + "/collapse-folders-test";
testProjectFolder = FileSystem.getDirectoryForPath(testProjectPath);
// Ensure the test directory exists
await SpecRunnerUtils.createTempDirectory();
// Create test project structure
await SpecRunnerUtils.ensureExistsDirAsync(testProjectPath);
await SpecRunnerUtils.ensureExistsDirAsync(testProjectPath + "/folder1");
await SpecRunnerUtils.ensureExistsDirAsync(testProjectPath + "/folder1/subfolder1");
await SpecRunnerUtils.ensureExistsDirAsync(testProjectPath + "/folder2");
await SpecRunnerUtils.ensureExistsDirAsync(testProjectPath + "/folder2/subfolder2");
// Create some test files
await jsPromise(SpecRunnerUtils.createTextFile(testProjectPath + "/file.js", "// Test file", FileSystem));
await jsPromise(
SpecRunnerUtils.createTextFile(testProjectPath + "/folder1/file1.js", "// Test file 1", FileSystem)
);
await jsPromise(
SpecRunnerUtils.createTextFile(
testProjectPath + "/folder1/subfolder1/subfile1.js",
"// Test subfile 1",
FileSystem
)
);
await jsPromise(
SpecRunnerUtils.createTextFile(testProjectPath + "/folder2/file2.js", "// Test file 2", FileSystem)
);
await jsPromise(
SpecRunnerUtils.createTextFile(
testProjectPath + "/folder2/subfolder2/subfile2.js",
"// Test subfile 2",
FileSystem
)
);
// Load the test project
await SpecRunnerUtils.loadProjectInTestWindow(testProjectPath);
}, 30000);
afterAll(async function () {
testWindow = null;
await SpecRunnerUtils.closeTestWindow();
await SpecRunnerUtils.removeTempDirectory();
}, 30000);
/**
* Helper function to open a folder in the project tree
* @param {string} folderPath - The path of the folder to open
*/
async function openFolder(folderPath) {
const folderEntry = FileSystem.getDirectoryForPath(folderPath);
// Call setDirectoryOpen without awaitsForDone since it doesn't return a promise
ProjectManager._actionCreator.setDirectoryOpen(folderEntry.fullPath, true);
// Wait for the folder to be opened in the UI
await awaitsFor(
function () {
const $folderNode = findDirectoryNode(folderPath);
return $folderNode && $folderNode.hasClass("jstree-open");
},
"Folder to be opened: " + folderPath,
1000
);
}
/**
* Helper function to find a directory node in the project tree
* @param {string} path - The path of the directory to find
* @returns {jQuery|null} - The jQuery object for the directory node, or null if not found
*/
function findDirectoryNode(path) {
const dirName = path.split("/").pop();
const $treeItems = $("#project-files-container li");
let $result = null;
$treeItems.each(function () {
const $treeNode = $(this);
if ($treeNode.children("a").text().trim() === dirName) {
$result = $treeNode;
return false; // Break the loop
}
});
return $result;
}
/**
* Helper function to check if a folder is open in the project tree
* @param {string} folderPath - The path of the folder to check
* @returns {boolean} - True if the folder is open, false otherwise
*/
function isFolderOpen(folderPath) {
const $folderNode = findDirectoryNode(folderPath);
// If the folder node can't be found, it's definitely not open
if (!$folderNode) {
return false;
}
return $folderNode.hasClass("jstree-open");
}
describe("UI", function () {
it("should have a collapse button in the project files header", async function () {
// Check if the collapse button exists
const $collapseBtn = $("#collapse-folders");
expect($collapseBtn.length).toBe(1);
// Check if the button has the collapse icons
expect($collapseBtn.find(".collapse-icon").length).toBe(2);
});
it("should collapse all open folders when the collapse button is clicked", async function () {
// Open some folders first
await openFolder(testProjectPath + "/folder1");
await openFolder(testProjectPath + "/folder2");
// Verify folders are open
expect(isFolderOpen(testProjectPath + "/folder1")).toBe(true);
expect(isFolderOpen(testProjectPath + "/folder2")).toBe(true);
// Click the collapse button
$("#collapse-folders").click();
// Wait for folders to be collapsed
await awaitsFor(
function () {
return (
!isFolderOpen(testProjectPath + "/folder1") && !isFolderOpen(testProjectPath + "/folder2")
);
},
"Folders to be collapsed",
1000
);
// Verify folders are closed
expect(isFolderOpen(testProjectPath + "/folder1")).toBe(false);
expect(isFolderOpen(testProjectPath + "/folder2")).toBe(false);
});
it("should collapse nested folders when the collapse button is clicked", async function () {
// Open folders with nested structure
await openFolder(testProjectPath + "/folder1");
await openFolder(testProjectPath + "/folder1/subfolder1");
await openFolder(testProjectPath + "/folder2");
await openFolder(testProjectPath + "/folder2/subfolder2");
// Verify folders are open
expect(isFolderOpen(testProjectPath + "/folder1")).toBe(true);
expect(isFolderOpen(testProjectPath + "/folder1/subfolder1")).toBe(true);
expect(isFolderOpen(testProjectPath + "/folder2")).toBe(true);
expect(isFolderOpen(testProjectPath + "/folder2/subfolder2")).toBe(true);
// Click the collapse button
$("#collapse-folders").click();
// Wait for all folders to be collapsed
await awaitsFor(
function () {
return (
!isFolderOpen(testProjectPath + "/folder1") &&
!isFolderOpen(testProjectPath + "/folder1/subfolder1") &&
!isFolderOpen(testProjectPath + "/folder2") &&
!isFolderOpen(testProjectPath + "/folder2/subfolder2")
);
},
"All folders to be collapsed",
1000
);
// Verify all folders are closed
expect(isFolderOpen(testProjectPath + "/folder1")).toBe(false);
expect(isFolderOpen(testProjectPath + "/folder1/subfolder1")).toBe(false);
expect(isFolderOpen(testProjectPath + "/folder2")).toBe(false);
expect(isFolderOpen(testProjectPath + "/folder2/subfolder2")).toBe(false);
});
it("should do nothing when no folders are open", async function () {
// Make sure all folders are closed
$("#collapse-folders").click();
await awaitsFor(
function () {
return (
!isFolderOpen(testProjectPath + "/folder1") && !isFolderOpen(testProjectPath + "/folder2")
);
},
"Folders to be collapsed",
1000
);
// Get the current state of the project tree
const initialState = $("#project-files-container").html();
// Click the collapse button again
$("#collapse-folders").click();
// Wait a bit to ensure any potential changes would have happened
await awaits(300);
// Verify the project tree hasn't changed
expect($("#project-files-container").html()).toBe(initialState);
});
});
});
});