Skip to content

Commit

Permalink
fix(e2e): deal with the fact that the modal might already be closed (#…
Browse files Browse the repository at this point in the history
…6153)

* deal with the fact that the modal might already be closed

* pull out the hide modal logic, use it in two places
  • Loading branch information
lerouxb authored Aug 26, 2024
1 parent dbedce1 commit c3480f8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
6 changes: 1 addition & 5 deletions packages/compass-e2e-tests/helpers/commands/disconnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ async function resetForDisconnect(
closeToasts?: boolean;
} = {}
) {
if (await browser.$(Selectors.LGModal).isDisplayed()) {
// close any modals that might be in the way
await browser.clickVisible(Selectors.LGModalClose);
await browser.$(Selectors.LGModal).waitForDisplayed({ reverse: true });
}
await browser.hideVisibleModal();

// Collapse all the connections so that they will all hopefully fit on screen
// and therefore be rendered.
Expand Down
24 changes: 24 additions & 0 deletions packages/compass-e2e-tests/helpers/commands/hide-visible-modal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { CompassBrowser } from '../compass-browser';
import * as Selectors from '../selectors';

import Debug from 'debug';

const debug = Debug('compass-e2e-tests');

export async function hideVisibleModal(browser: CompassBrowser): Promise<void> {
// If there's some race condition where something else is closing the modal at
// the same time we're trying to close the modal, then make it error out
// quickly so it can be ignored and we move on.

if (await browser.$(Selectors.LGModal).isDisplayed()) {
// close any modals that might be in the way
const waitOptions = { timeout: 2_000 };
try {
await browser.clickVisible(Selectors.LGModalClose, waitOptions);
await browser.$(Selectors.LGModal).waitForDisplayed({ reverse: true });
} catch (err) {
// if the modal disappears by itself in the meantime, that's fine
debug('ignoring', err);
}
}
}
1 change: 1 addition & 0 deletions packages/compass-e2e-tests/helpers/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ export * from './create-index';
export * from './drop-index';
export * from './hide-index';
export * from './unhide-index';
export * from './hide-visible-modal';
export * from './hide-visible-toasts';
export * from './sidebar-collection';
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import type { CompassBrowser } from '../compass-browser';
import * as Selectors from '../selectors';

async function resetForRemove(browser: CompassBrowser) {
if (await browser.$(Selectors.LGModal).isDisplayed()) {
// close any modals that might be in the way
await browser.clickVisible(Selectors.LGModalClose);
await browser.$(Selectors.LGModal).waitForDisplayed({ reverse: true });
}
await browser.hideVisibleModal();

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

0 comments on commit c3480f8

Please sign in to comment.