Closed ewgenapelsin closed 1 year ago
/**
/*
@return {Promise} */ export async function txSubmit(page, formTestId, {shouldFailPost, shouldFailModal} = {}) { await page.waitForSelector([data-test-id="${formTestId}"] [data-test-id="txSubmitButton"]:not(.is-disabled)); await wait();
[data-test-id="${formTestId}"] [data-test-id="txSubmitButton"]:not(.is-disabled)
// submit (opens modal) await page.click([data-test-id="${formTestId}"] [data-test-id="txSubmitButton"]);
[data-test-id="${formTestId}"] [data-test-id="txSubmitButton"]
const modalButtonSelector = [data-test-id="${formTestId}"] [data-test-id="txModalSubmitButton"]; if (!shouldFailModal) { // wait for modal await page.waitForSelector(modalButtonSelector); // post tx await page.click(modalButtonSelector); } else { await waitForNoSelector(page, modalButtonSelector); }
[data-test-id="${formTestId}"] [data-test-id="txModalSubmitButton"]
if (!shouldFailPost) { // wait for success modal await page.waitForSelector([data-test-id="${formTestId}"] [data-test-id="txModalSuccessClose"]); // close modal await page.click([data-test-id="${formTestId}"] [data-test-id="txModalSuccessClose"]); } else if (shouldFailPost === 'estimation') { // wait for error await page.waitForSelector([data-test-id="${formTestId}"] [data-test-id="estimationError"], {timeout: 1020000}); } else { // wait for error await page.waitForSelector([data-test-id="${formTestId}"] [data-test-id="txErrorMessage"]); } }
[data-test-id="${formTestId}"] [data-test-id="txModalSuccessClose"]
[data-test-id="${formTestId}"] [data-test-id="estimationError"]
[data-test-id="${formTestId}"] [data-test-id="txErrorMessage"]
@return {Promise} */ export function waitForNoSelector(page, selector, options) { const foundMessage = Selector ${selector} found but should not;
Selector ${selector} found but should not
return page.waitForSelector(selector, {timeout: 5000, ...options}) .then(() => { throw new Error(foundMessage); }) .catch((error) => { if (error.message === foundMessage) { throw error; } else { return 'OK'; } }); }
/**
/**
/*
@return {Promise}
*/
export async function txSubmit(page, formTestId, {shouldFailPost, shouldFailModal} = {}) {
await page.waitForSelector(
[data-test-id="${formTestId}"] [data-test-id="txSubmitButton"]:not(.is-disabled)
); await wait();// submit (opens modal) await page.click(
[data-test-id="${formTestId}"] [data-test-id="txSubmitButton"]
);const modalButtonSelector =
[data-test-id="${formTestId}"] [data-test-id="txModalSubmitButton"]
; if (!shouldFailModal) { // wait for modal await page.waitForSelector(modalButtonSelector); // post tx await page.click(modalButtonSelector); } else { await waitForNoSelector(page, modalButtonSelector); }if (!shouldFailPost) { // wait for success modal await page.waitForSelector(
[data-test-id="${formTestId}"] [data-test-id="txModalSuccessClose"]
); // close modal await page.click([data-test-id="${formTestId}"] [data-test-id="txModalSuccessClose"]
); } else if (shouldFailPost === 'estimation') { // wait for error await page.waitForSelector([data-test-id="${formTestId}"] [data-test-id="estimationError"]
, {timeout: 1020000}); } else { // wait for error await page.waitForSelector([data-test-id="${formTestId}"] [data-test-id="txErrorMessage"]
); } }/**
/*
@return {Promise} */ export function waitForNoSelector(page, selector, options) { const foundMessage =
Selector ${selector} found but should not
;return page.waitForSelector(selector, {timeout: 5000, ...options}) .then(() => { throw new Error(foundMessage); }) .catch((error) => { if (error.message === foundMessage) { throw error; } else { return 'OK'; } }); }