Skip to content

Commit

Permalink
chore: attempt to make tab closing less flaky (#6029)
Browse files Browse the repository at this point in the history
attempt to make tab closing less flaky
  • Loading branch information
lerouxb authored Jul 16, 2024
1 parent bd8d862 commit e7166a9
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions packages/compass-e2e-tests/helpers/commands/workspace-tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ async function closeTab(
selectorOptions: WorkspaceTabSelectorOptions,
autoConfirmTabClose: boolean
): Promise<void> {
await browser
.$(Selectors.workspaceTab(selectorOptions))
.$(Selectors.CloseWorkspaceTab)
.click();
await browser.clickVisible(
browser
.$(Selectors.workspaceTab(selectorOptions))
.$(Selectors.CloseWorkspaceTab)
);

// wait until the tab goes away and if the confirmation modal opens, maybe confirm
await browser.waitUntil(async () => {
Expand Down Expand Up @@ -48,17 +49,21 @@ export async function closeWorkspaceTabs(
return (await browser.$$(Selectors.workspaceTab())).length;
};

while ((await countTabs()) > 0) {
const currentActiveTab = await browser.$(
Selectors.workspaceTab({ active: true })
);
await currentActiveTab.click();
// Close this exact active tab rather than "the active one" because if there
// are multiple tabs then another tab will immediately become active and
// trip up the logic that checks that the tab you closed went away.
const id = await currentActiveTab.getAttribute('id');
await closeTab(browser, { id }, autoConfirmTabClose);
}
await browser.waitUntil(async () => {
if ((await countTabs()) > 0) {
const currentActiveTab = await browser.$(
Selectors.workspaceTab({ active: true })
);

// Close this exact active tab rather than "the active one" because if there
// are multiple tabs then another tab will immediately become active and
// trip up the logic that checks that the tab you closed went away.
const id = await currentActiveTab.getAttribute('id');
await closeTab(browser, { id }, autoConfirmTabClose);
}
const numTabs = await countTabs();
return numTabs === 0;
});
}

export async function closeWorkspaceTab(
Expand Down

0 comments on commit e7166a9

Please sign in to comment.