Skip to content

Commit ac2d386

Browse files
committed
fix: remove await timers from tests
1 parent 26775d2 commit ac2d386

File tree

1 file changed

+77
-10
lines changed

1 file changed

+77
-10
lines changed

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

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,13 @@ define(function (require, exports, module) {
718718
MainViewManager.setLayoutScheme(1, 1);
719719

720720
// Wait for cleanup to complete
721-
await awaits(100);
721+
await awaitsFor(
722+
function () {
723+
return MainViewManager.getPaneCount() === 1 && getTabCount() === 0;
724+
},
725+
"Cleanup to complete with single pane and no tabs",
726+
1000
727+
);
722728
});
723729

724730
it("should allow dragging and dropping a tab to the beginning of the tab bar", async function () {
@@ -923,7 +929,13 @@ define(function (require, exports, module) {
923929
MainViewManager.setLayoutScheme(1, 2);
924930

925931
// Wait for layout to settle and ensure second pane is empty
926-
await awaits(100);
932+
await awaitsFor(
933+
function () {
934+
return MainViewManager.getPaneCount() === 2;
935+
},
936+
"Layout to settle with two panes",
937+
1000
938+
);
927939

928940
// Force close any files that might be open in the second pane
929941
const secondPaneWorkingSet = MainViewManager.getWorkingSet("second-pane");
@@ -934,6 +946,17 @@ define(function (require, exports, module) {
934946
);
935947
}
936948

949+
// Wait for the second pane to actually be empty after cleanup
950+
await awaitsFor(
951+
function () {
952+
return getPaneTabCount("second-pane") === 0;
953+
},
954+
"Second pane to be cleaned up",
955+
2000
956+
);
957+
958+
expect(getPaneTabCount("second-pane")).toBe(0);
959+
937960
// Create test files for the first pane
938961
const firstPaneFiles = await createTestFiles(
939962
2,
@@ -947,6 +970,8 @@ define(function (require, exports, module) {
947970
// Wait for all tabs to appear in the first pane
948971
await waitForTabs(firstPaneFiles, "first-pane");
949972

973+
expect(getPaneTabCount("second-pane")).toBe(0);
974+
950975
// Ensure second pane is empty before proceeding
951976
await awaitsFor(
952977
function () {
@@ -1043,7 +1068,13 @@ define(function (require, exports, module) {
10431068
await testWindow.closeAllFiles();
10441069

10451070
// Wait for the tab bar to update
1046-
await awaits(300);
1071+
await awaitsFor(
1072+
function () {
1073+
return $("#phoenix-tab-bar").length > 0 && getTabCount() === 0;
1074+
},
1075+
"Tab bar to update with no tabs",
1076+
1000
1077+
);
10471078
});
10481079

10491080
it("should add tabs when files are added to the working set", async function () {
@@ -1185,8 +1216,14 @@ define(function (require, exports, module) {
11851216
// Get the currently active file
11861217
const activeFile = MainViewManager.getCurrentlyViewedFile();
11871218

1188-
// just a small timer because tab bar gets recreated
1189-
await awaits(100);
1219+
// Wait for tab bar to be recreated and reflect the active file
1220+
await awaitsFor(
1221+
function () {
1222+
return $("#phoenix-tab-bar").length > 0 && activeFile && isTabActive(activeFile.fullPath);
1223+
},
1224+
"Tab bar to be recreated and show active file",
1225+
1000
1226+
);
11901227

11911228
// Verify the tab for the active file is active
11921229
expect(isTabActive(activeFile.fullPath)).toBe(true);
@@ -1197,7 +1234,14 @@ define(function (require, exports, module) {
11971234
// Get the new active file
11981235
const newActiveFile = MainViewManager.getCurrentlyViewedFile();
11991236

1200-
await awaits(100);
1237+
// Wait for tab bar to update with the new active file
1238+
await awaitsFor(
1239+
function () {
1240+
return newActiveFile && isTabActive(newActiveFile.fullPath);
1241+
},
1242+
"Tab bar to update with new active file",
1243+
1000
1244+
);
12011245

12021246
// Verify the tab for the new active file is active
12031247
expect(isTabActive(newActiveFile.fullPath)).toBe(true);
@@ -1233,8 +1277,25 @@ define(function (require, exports, module) {
12331277
// Verify the correct file is loaded in the editor
12341278
expect(MainViewManager.getCurrentlyViewedFile().fullPath).toBe(filePath);
12351279
}
1236-
// add a small timer to make sure that the tab bar is properly loaded
1237-
await awaits(100);
1280+
// Wait for the tab bar to be properly loaded
1281+
await awaitsFor(
1282+
function () {
1283+
return $("#phoenix-tab-bar").length > 0 && getTabCount() === 3;
1284+
},
1285+
"Tab bar to be properly loaded with all tabs",
1286+
1000
1287+
);
1288+
1289+
// Wait for the third file to become active
1290+
await awaitsFor(
1291+
function () {
1292+
return isTabActive(testFilePath3) &&
1293+
MainViewManager.getCurrentlyViewedFile() &&
1294+
MainViewManager.getCurrentlyViewedFile().fullPath === testFilePath3;
1295+
},
1296+
"Third file to become active",
1297+
2000
1298+
);
12381299

12391300
// Initially, verify the third file is active (last opened)
12401301
expect(isTabActive(testFilePath3)).toBe(true);
@@ -1716,8 +1777,14 @@ define(function (require, exports, module) {
17161777
// Trigger a Git status update
17171778
testWindow.phoenixGitEvents.EventEmitter.emit("GIT_FILE_STATUS_CHANGED");
17181779

1719-
// Wait for the tabs to update
1720-
await awaits(300);
1780+
// Wait for the tabs to update with Git status
1781+
await awaitsFor(
1782+
function () {
1783+
return hasGitStatus(testFilePath) && hasGitStatus(testFilePath2);
1784+
},
1785+
"Tabs to update with Git status",
1786+
1000
1787+
);
17211788

17221789
// Verify the first file has the git-new class
17231790
const $tab1 = getTab(testFilePath);

0 commit comments

Comments
 (0)