Skip to content

Commit 833e168

Browse files
committed
feat: add tests to test active tab functionality
1 parent 6d0925f commit 833e168

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

test/spec/Extn-Tabbar-integ-test.js

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ define(function (require, exports, module) {
8181
return $(".tab").length;
8282
}
8383

84+
/**
85+
* Helper function to check if a tab for a specific file is active
86+
* @param {string} filePath - The path of the file to check
87+
* @returns {boolean} - True if the tab is active, false otherwise
88+
*/
89+
function isTabActive(filePath) {
90+
return $(`.tab[data-path="${filePath}"].active`).length > 0;
91+
}
92+
8493
describe("Visibility", function () {
8594
it("should show tab bar when the feature is enabled", async function () {
8695
// Enable the tab bar feature
@@ -285,5 +294,128 @@ define(function (require, exports, module) {
285294
expect(getTabCount()).toBe(0);
286295
});
287296
});
297+
298+
describe("Active Tab", function () {
299+
beforeEach(async function () {
300+
// Enable the tab bar feature
301+
PreferencesManager.set("tabBar.options", { showTabBar: true, numberOfTabs: -1 });
302+
303+
// Close all files to start with a clean state
304+
await awaitsForDone(CommandManager.execute(Commands.FILE_CLOSE_ALL), "Close all files");
305+
306+
// Open all three test files
307+
await awaitsForDone(
308+
CommandManager.execute(Commands.FILE_OPEN, { fullPath: testFilePath }),
309+
"Open first test file"
310+
);
311+
await awaitsForDone(
312+
CommandManager.execute(Commands.FILE_OPEN, { fullPath: testFilePath2 }),
313+
"Open second test file"
314+
);
315+
await awaitsForDone(
316+
CommandManager.execute(Commands.FILE_OPEN, { fullPath: testFilePath3 }),
317+
"Open third test file"
318+
);
319+
320+
// Wait for all tabs to appear
321+
await awaitsFor(
322+
function () {
323+
return tabExists(testFilePath) && tabExists(testFilePath2) && tabExists(testFilePath3);
324+
},
325+
"All tabs to appear",
326+
1000
327+
);
328+
});
329+
330+
it("should change active tab when switching files in the working set", async function () {
331+
// Switch to the first file
332+
await awaitsForDone(
333+
CommandManager.execute(Commands.FILE_OPEN, { fullPath: testFilePath }),
334+
"Switch to first file"
335+
);
336+
337+
// Wait for the tab to become active
338+
await awaitsFor(
339+
function () {
340+
return isTabActive(testFilePath);
341+
},
342+
"First tab to become active",
343+
1000
344+
);
345+
346+
// Verify the first tab is active and others are not
347+
expect(isTabActive(testFilePath)).toBe(true);
348+
expect(isTabActive(testFilePath2)).toBe(false);
349+
expect(isTabActive(testFilePath3)).toBe(false);
350+
351+
// Switch to the second file
352+
await awaitsForDone(
353+
CommandManager.execute(Commands.FILE_OPEN, { fullPath: testFilePath2 }),
354+
"Switch to second file"
355+
);
356+
357+
// Wait for the tab to become active
358+
await awaitsFor(
359+
function () {
360+
return isTabActive(testFilePath2);
361+
},
362+
"Second tab to become active",
363+
1000
364+
);
365+
366+
// Verify the second tab is active and others are not
367+
expect(isTabActive(testFilePath)).toBe(false);
368+
expect(isTabActive(testFilePath2)).toBe(true);
369+
expect(isTabActive(testFilePath3)).toBe(false);
370+
371+
// Switch to the third file
372+
await awaitsForDone(
373+
CommandManager.execute(Commands.FILE_OPEN, { fullPath: testFilePath3 }),
374+
"Switch to third file"
375+
);
376+
377+
// Wait for the tab to become active
378+
await awaitsFor(
379+
function () {
380+
return isTabActive(testFilePath3);
381+
},
382+
"Third tab to become active",
383+
1000
384+
);
385+
386+
// Verify the third tab is active and others are not
387+
expect(isTabActive(testFilePath)).toBe(false);
388+
expect(isTabActive(testFilePath2)).toBe(false);
389+
expect(isTabActive(testFilePath3)).toBe(true);
390+
});
391+
392+
it("should display active tab correctly based on the active file in the working set", async function () {
393+
// Get the currently active file
394+
const activeFile = MainViewManager.getCurrentlyViewedFile();
395+
396+
// just a small timer because tab bar gets recreated
397+
await awaits(100);
398+
399+
// Verify the tab for the active file is active
400+
expect(isTabActive(activeFile.fullPath)).toBe(true);
401+
402+
// Switch to a different file
403+
await awaitsForDone(
404+
CommandManager.execute(Commands.FILE_OPEN, { fullPath: testFilePath2 }),
405+
"Switch to second file"
406+
);
407+
408+
// Get the new active file
409+
const newActiveFile = MainViewManager.getCurrentlyViewedFile();
410+
411+
await awaits(100);
412+
413+
// Verify the tab for the new active file is active
414+
expect(isTabActive(newActiveFile.fullPath)).toBe(true);
415+
416+
// Verify the tab for the previous active file is no longer active
417+
expect(isTabActive(activeFile.fullPath)).toBe(false);
418+
});
419+
});
288420
});
289421
});

0 commit comments

Comments
 (0)