Skip to content

Commit c3480f8

Browse files
authored
fix(e2e): deal with the fact that the modal might already be closed (#6153)
* deal with the fact that the modal might already be closed * pull out the hide modal logic, use it in two places
1 parent dbedce1 commit c3480f8

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

packages/compass-e2e-tests/helpers/commands/disconnect.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ async function resetForDisconnect(
4848
closeToasts?: boolean;
4949
} = {}
5050
) {
51-
if (await browser.$(Selectors.LGModal).isDisplayed()) {
52-
// close any modals that might be in the way
53-
await browser.clickVisible(Selectors.LGModalClose);
54-
await browser.$(Selectors.LGModal).waitForDisplayed({ reverse: true });
55-
}
51+
await browser.hideVisibleModal();
5652

5753
// Collapse all the connections so that they will all hopefully fit on screen
5854
// and therefore be rendered.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { CompassBrowser } from '../compass-browser';
2+
import * as Selectors from '../selectors';
3+
4+
import Debug from 'debug';
5+
6+
const debug = Debug('compass-e2e-tests');
7+
8+
export async function hideVisibleModal(browser: CompassBrowser): Promise<void> {
9+
// If there's some race condition where something else is closing the modal at
10+
// the same time we're trying to close the modal, then make it error out
11+
// quickly so it can be ignored and we move on.
12+
13+
if (await browser.$(Selectors.LGModal).isDisplayed()) {
14+
// close any modals that might be in the way
15+
const waitOptions = { timeout: 2_000 };
16+
try {
17+
await browser.clickVisible(Selectors.LGModalClose, waitOptions);
18+
await browser.$(Selectors.LGModal).waitForDisplayed({ reverse: true });
19+
} catch (err) {
20+
// if the modal disappears by itself in the meantime, that's fine
21+
debug('ignoring', err);
22+
}
23+
}
24+
}

packages/compass-e2e-tests/helpers/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@ export * from './create-index';
5959
export * from './drop-index';
6060
export * from './hide-index';
6161
export * from './unhide-index';
62+
export * from './hide-visible-modal';
6263
export * from './hide-visible-toasts';
6364
export * from './sidebar-collection';

packages/compass-e2e-tests/helpers/commands/remove-connections.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ import type { CompassBrowser } from '../compass-browser';
33
import * as Selectors from '../selectors';
44

55
async function resetForRemove(browser: CompassBrowser) {
6-
if (await browser.$(Selectors.LGModal).isDisplayed()) {
7-
// close any modals that might be in the way
8-
await browser.clickVisible(Selectors.LGModalClose);
9-
await browser.$(Selectors.LGModal).waitForDisplayed({ reverse: true });
10-
}
6+
await browser.hideVisibleModal();
117

128
// Collapse all the connections so that they will all hopefully fit on screen
139
// and therefore be rendered.

0 commit comments

Comments
 (0)