2021-05-19 11:49:48 +00:00
|
|
|
import { Application } from 'spectron';
|
2021-07-22 23:04:56 +00:00
|
|
|
|
2020-11-25 02:26:00 +00:00
|
|
|
import findAsync from './find-async';
|
|
|
|
|
2021-09-01 14:50:26 +00:00
|
|
|
interface WaitUntilOpenedOptions {modalName?: string; title?: string}
|
2021-05-19 11:49:48 +00:00
|
|
|
export const waitUntilOpened = async (app, { modalName, title }: WaitUntilOpenedOptions) => {
|
2020-11-25 02:26:00 +00:00
|
|
|
if (modalName) {
|
|
|
|
const modal = await app.client.react$(modalName);
|
|
|
|
await modal.waitForDisplayed();
|
|
|
|
} else {
|
|
|
|
await app.client.waitUntilTextExists('div.modal__header__children', title);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-19 11:49:48 +00:00
|
|
|
export const close = async (app: Application, modalName?: string) => {
|
2020-11-25 02:26:00 +00:00
|
|
|
let modal;
|
|
|
|
if (modalName) {
|
|
|
|
modal = await app.client.react$(modalName);
|
|
|
|
} else {
|
|
|
|
const modals = await app.client.react$$('Modal');
|
|
|
|
modal = await findAsync(modals, m => m.isDisplayed());
|
|
|
|
}
|
|
|
|
|
|
|
|
await modal.$('button.modal__close-btn').then(e => e.click());
|
|
|
|
};
|
2020-12-04 21:47:04 +00:00
|
|
|
|
2021-03-03 20:00:56 +00:00
|
|
|
export const clickModalFooterByText = async (app, text) => {
|
|
|
|
const btn = await app.client
|
|
|
|
.$('.modal[aria-hidden=false] .modal__footer')
|
|
|
|
.then(e => e.$(`button*=${text}`));
|
2020-12-04 21:47:04 +00:00
|
|
|
await btn.waitForClickable();
|
|
|
|
await btn.click();
|
|
|
|
};
|
2021-03-03 20:00:56 +00:00
|
|
|
|
|
|
|
export const typeIntoModalInput = async (app, text) => {
|
|
|
|
const input = await app.client.$('.modal input');
|
|
|
|
await input.waitUntil(() => input.isFocused());
|
|
|
|
await input.keys(text);
|
|
|
|
};
|