File tree Expand file tree Collapse file tree 5 files changed +72
-0
lines changed
packages/compass-e2e-tests/helpers/commands Expand file tree Collapse file tree 5 files changed +72
-0
lines changed Original file line number Diff line number Diff line change 1+ import { Selectors } from '../compass' ;
2+ import type { CompassBrowser } from '../compass-browser' ;
3+
4+ // TODO: Wait for any animation to settle before resolving?
5+ export function getOpenModals (
6+ browser : CompassBrowser ,
7+ selector : Parameters < CompassBrowser [ '$$' ] > [ 0 ] = Selectors . LGModal
8+ ) : Promise < WebdriverIO . Element [ ] > {
9+ return browser . $$ ( selector ) . filter ( async ( element ) => {
10+ const tagName = await element . getTagName ( ) ;
11+ if ( tagName !== 'dialog' ) {
12+ throw new Error (
13+ `Expected selector to match dialogs, matched '${ tagName } '`
14+ ) ;
15+ }
16+ const open = await element . getAttribute ( 'open' ) ;
17+ return open === 'true' ;
18+ } ) ;
19+ }
Original file line number Diff line number Diff line change @@ -66,3 +66,7 @@ export * from './read-first-document-content';
6666export * from './read-stage-operators' ;
6767export * from './click-confirmation-action' ;
6868export * from './get-input-by-label' ;
69+ export * from './get-open-modals' ;
70+ export * from './is-modal-open' ;
71+ export * from './is-modal-eventually-open' ;
72+ export * from './wait-for-open-modal' ;
Original file line number Diff line number Diff line change 1+ import { Selectors } from '../compass' ;
2+ import type { CompassBrowser } from '../compass-browser' ;
3+
4+ export async function isModalEventuallyOpen (
5+ browser : CompassBrowser ,
6+ selector : Parameters < CompassBrowser [ '$$' ] > [ 0 ] = Selectors . LGModal ,
7+ timeout ?: number
8+ ) : Promise < boolean > {
9+ try {
10+ await browser . waitForOpenModal ( selector , { timeout } ) ;
11+ // return true if it opens before the timeout expires
12+ return true ;
13+ } catch {
14+ return false ;
15+ }
16+ }
Original file line number Diff line number Diff line change 1+ import { Selectors } from '../compass' ;
2+ import type { CompassBrowser } from '../compass-browser' ;
3+
4+ export async function isModalOpen (
5+ browser : CompassBrowser ,
6+ selector : Parameters < CompassBrowser [ '$$' ] > [ 0 ] = Selectors . LGModal
7+ ) : Promise < boolean > {
8+ const modals = await browser . getOpenModals ( selector ) ;
9+ return modals . length > 0 ;
10+ }
Original file line number Diff line number Diff line change 1+ import { inspect } from 'node:util' ;
2+ import type { WaitForOptions } from 'webdriverio' ;
3+ import type { CompassBrowser } from '../compass-browser' ;
4+
5+ export async function waitForOpenModal (
6+ browser : CompassBrowser ,
7+ selector : Parameters < CompassBrowser [ '$$' ] > [ 0 ] ,
8+ { reverse = false , ...options } : WaitForOptions = { }
9+ ) : Promise < void > {
10+ await browser . waitUntil (
11+ async ( ) => {
12+ const open = await browser . isModalOpen ( selector ) ;
13+ return reverse ? ! open : open ;
14+ } ,
15+ {
16+ timeout : 2_000 ,
17+ timeoutMsg : `Timeout waiting for modal '${ inspect ( selector ) } ' to ${
18+ reverse ? 'close' : 'open'
19+ } `,
20+ ...options ,
21+ }
22+ ) ;
23+ }
You can’t perform that action at this time.
0 commit comments