@@ -25,39 +25,62 @@ define(function (require, exports, module) {
2525
2626 describe ( "integration:TabBar" , function ( ) {
2727 let testWindow , PreferencesManager , $ , FileSystem , MainViewManager , CommandManager , Commands , testFilePath ;
28+ let testFilePath2 , testFilePath3 ;
2829
2930 beforeAll ( async function ( ) {
3031 // Create the test window
3132 testWindow = await SpecRunnerUtils . createTestWindowAndRun ( ) ;
32- // Get reference to useful modules
33+ // Get reference to all the required modules
3334 $ = testWindow . $ ;
3435 PreferencesManager = testWindow . brackets . test . PreferencesManager ;
3536 FileSystem = testWindow . brackets . test . FileSystem ;
3637 MainViewManager = testWindow . brackets . test . MainViewManager ;
3738 CommandManager = testWindow . brackets . test . CommandManager ;
3839 Commands = testWindow . brackets . test . Commands ;
3940
40- // Create a test file
41+ // Create test files
4142 testFilePath = SpecRunnerUtils . getTempDirectory ( ) + "/tabbar-test.js" ;
43+ testFilePath2 = SpecRunnerUtils . getTempDirectory ( ) + "/tabbar-test2.js" ;
44+ testFilePath3 = SpecRunnerUtils . getTempDirectory ( ) + "/tabbar-test3.js" ;
45+
4246 await SpecRunnerUtils . createTempDirectory ( ) ;
43- await jsPromise ( SpecRunnerUtils . createTextFile ( testFilePath , "// Test file for TabBar" , FileSystem ) ) ;
47+ await jsPromise ( SpecRunnerUtils . createTextFile ( testFilePath , "// Test file 1 for TabBar" , FileSystem ) ) ;
48+ await jsPromise ( SpecRunnerUtils . createTextFile ( testFilePath2 , "// Test file 2 for TabBar" , FileSystem ) ) ;
49+ await jsPromise ( SpecRunnerUtils . createTextFile ( testFilePath3 , "// Test file 3 for TabBar" , FileSystem ) ) ;
4450
45- // Open the test file
51+ // Open the first test file
4652 await awaitsForDone (
4753 CommandManager . execute ( Commands . FILE_OPEN , { fullPath : testFilePath } ) ,
4854 "Open test file"
4955 ) ;
5056 } , 30000 ) ;
5157
5258 afterAll ( async function ( ) {
53- // Close the test file
59+ // Close all files
5460 await awaitsForDone ( CommandManager . execute ( Commands . FILE_CLOSE_ALL ) , "Close all files" ) ;
5561
5662 testWindow = null ;
5763 await SpecRunnerUtils . closeTestWindow ( ) ;
5864 await SpecRunnerUtils . removeTempDirectory ( ) ;
5965 } , 30000 ) ;
6066
67+ /**
68+ * Helper function to check if a tab for a specific file exists in the tab bar
69+ * @param {string } filePath - The path of the file to check
70+ * @returns {boolean } - True if the tab exists, false otherwise
71+ */
72+ function tabExists ( filePath ) {
73+ return $ ( `.tab[data-path="${ filePath } "]` ) . length > 0 ;
74+ }
75+
76+ /**
77+ * Helper function to count the number of tabs in the tab bar
78+ * @returns {number } - The number of tabs
79+ */
80+ function getTabCount ( ) {
81+ return $ ( ".tab" ) . length ;
82+ }
83+
6184 describe ( "Visibility" , function ( ) {
6285 it ( "should show tab bar when the feature is enabled" , async function ( ) {
6386 // Enable the tab bar feature
@@ -93,5 +116,174 @@ define(function (require, exports, module) {
93116 expect ( $ ( "#phoenix-tab-bar" ) . is ( ":visible" ) ) . toBe ( false ) ;
94117 } ) ;
95118 } ) ;
119+
120+ describe ( "Working Set" , function ( ) {
121+ beforeEach ( async function ( ) {
122+ // Enable the tab bar feature
123+ PreferencesManager . set ( "tabBar.options" , { showTabBar : true , numberOfTabs : - 1 } ) ;
124+
125+ // Close all files to start with a clean state
126+ await awaitsForDone ( CommandManager . execute ( Commands . FILE_CLOSE_ALL ) , "Close all files" ) ;
127+
128+ // Wait for the tab bar to update
129+ await awaits ( 300 ) ;
130+ } ) ;
131+
132+ it ( "should add tabs when files are added to the working set" , async function ( ) {
133+ // Open the first test file
134+ await awaitsForDone (
135+ CommandManager . execute ( Commands . FILE_OPEN , { fullPath : testFilePath } ) ,
136+ "Open first test file"
137+ ) ;
138+
139+ // Wait for the tab bar to update
140+ await awaitsFor (
141+ function ( ) {
142+ return tabExists ( testFilePath ) ;
143+ } ,
144+ "Tab for first file to appear" ,
145+ 1000
146+ ) ;
147+
148+ // Verify the tab exists
149+ expect ( tabExists ( testFilePath ) ) . toBe ( true ) ;
150+ expect ( getTabCount ( ) ) . toBe ( 1 ) ;
151+
152+ // Open the second test file
153+ await awaitsForDone (
154+ CommandManager . execute ( Commands . FILE_OPEN , { fullPath : testFilePath2 } ) ,
155+ "Open second test file"
156+ ) ;
157+
158+ // Wait for the tab bar to update
159+ await awaitsFor (
160+ function ( ) {
161+ return tabExists ( testFilePath2 ) ;
162+ } ,
163+ "Tab for second file to appear" ,
164+ 1000
165+ ) ;
166+
167+ // Verify both tabs exist
168+ expect ( tabExists ( testFilePath ) ) . toBe ( true ) ;
169+ expect ( tabExists ( testFilePath2 ) ) . toBe ( true ) ;
170+ expect ( getTabCount ( ) ) . toBe ( 2 ) ;
171+
172+ // Open the third test file
173+ await awaitsForDone (
174+ CommandManager . execute ( Commands . FILE_OPEN , { fullPath : testFilePath3 } ) ,
175+ "Open third test file"
176+ ) ;
177+
178+ // Wait for the tab bar to update
179+ await awaitsFor (
180+ function ( ) {
181+ return tabExists ( testFilePath3 ) ;
182+ } ,
183+ "Tab for third file to appear" ,
184+ 1000
185+ ) ;
186+
187+ // Verify all three tabs exist
188+ expect ( tabExists ( testFilePath ) ) . toBe ( true ) ;
189+ expect ( tabExists ( testFilePath2 ) ) . toBe ( true ) ;
190+ expect ( tabExists ( testFilePath3 ) ) . toBe ( true ) ;
191+ expect ( getTabCount ( ) ) . toBe ( 3 ) ;
192+ } ) ;
193+
194+ it ( "should remove tabs when files are removed from the working set" , async function ( ) {
195+ // Open all three test files like in previous test
196+ await awaitsForDone (
197+ CommandManager . execute ( Commands . FILE_OPEN , { fullPath : testFilePath } ) ,
198+ "Open first test file"
199+ ) ;
200+ await awaitsForDone (
201+ CommandManager . execute ( Commands . FILE_OPEN , { fullPath : testFilePath2 } ) ,
202+ "Open second test file"
203+ ) ;
204+ await awaitsForDone (
205+ CommandManager . execute ( Commands . FILE_OPEN , { fullPath : testFilePath3 } ) ,
206+ "Open third test file"
207+ ) ;
208+
209+ // Wait for all tabs to appear
210+ await awaitsFor (
211+ function ( ) {
212+ return tabExists ( testFilePath ) && tabExists ( testFilePath2 ) && tabExists ( testFilePath3 ) ;
213+ } ,
214+ "All tabs to appear" ,
215+ 1000
216+ ) ;
217+
218+ // Verify all three tabs exist
219+ expect ( getTabCount ( ) ) . toBe ( 3 ) ;
220+
221+ // Close the second test file
222+ const fileToClose2 = FileSystem . getFileForPath ( testFilePath2 ) ;
223+ await awaitsForDone (
224+ CommandManager . execute ( Commands . FILE_CLOSE , { file : fileToClose2 } ) ,
225+ "Close second test file"
226+ ) ;
227+
228+ // Wait for the tab to disappear
229+ await awaitsFor (
230+ function ( ) {
231+ return ! tabExists ( testFilePath2 ) ;
232+ } ,
233+ "Tab for second file to disappear" ,
234+ 1000
235+ ) ;
236+
237+ // Verify the second tab is removed
238+ expect ( tabExists ( testFilePath ) ) . toBe ( true ) ;
239+ expect ( tabExists ( testFilePath2 ) ) . toBe ( false ) ;
240+ expect ( tabExists ( testFilePath3 ) ) . toBe ( true ) ;
241+ expect ( getTabCount ( ) ) . toBe ( 2 ) ;
242+
243+ // Close the first test file
244+ const fileToClose1 = FileSystem . getFileForPath ( testFilePath ) ;
245+ await awaitsForDone (
246+ CommandManager . execute ( Commands . FILE_CLOSE , { file : fileToClose1 } ) ,
247+ "Close first test file"
248+ ) ;
249+
250+ // Wait for the tab to disappear
251+ await awaitsFor (
252+ function ( ) {
253+ return ! tabExists ( testFilePath ) ;
254+ } ,
255+ "Tab for first file to disappear" ,
256+ 1000
257+ ) ;
258+
259+ // Verify the first tab is removed
260+ expect ( tabExists ( testFilePath ) ) . toBe ( false ) ;
261+ expect ( tabExists ( testFilePath2 ) ) . toBe ( false ) ;
262+ expect ( tabExists ( testFilePath3 ) ) . toBe ( true ) ;
263+ expect ( getTabCount ( ) ) . toBe ( 1 ) ;
264+
265+ // Close the third test file
266+ const fileToClose3 = FileSystem . getFileForPath ( testFilePath3 ) ;
267+ await awaitsForDone (
268+ CommandManager . execute ( Commands . FILE_CLOSE , { file : fileToClose3 } ) ,
269+ "Close third test file"
270+ ) ;
271+
272+ // Wait for the tab to disappear
273+ await awaitsFor (
274+ function ( ) {
275+ return ! tabExists ( testFilePath3 ) ;
276+ } ,
277+ "Tab for third file to disappear" ,
278+ 1000
279+ ) ;
280+
281+ // Verify all tabs are removed
282+ expect ( tabExists ( testFilePath ) ) . toBe ( false ) ;
283+ expect ( tabExists ( testFilePath2 ) ) . toBe ( false ) ;
284+ expect ( tabExists ( testFilePath3 ) ) . toBe ( false ) ;
285+ expect ( getTabCount ( ) ) . toBe ( 0 ) ;
286+ } ) ;
287+ } ) ;
96288 } ) ;
97289} ) ;
0 commit comments