From 2df1b2dbe4b01b459e4e627ae252b107219f7622 Mon Sep 17 00:00:00 2001 From: Paul Fitzpatrick Date: Mon, 18 Sep 2023 13:35:01 +0100 Subject: [PATCH] make some more methods available for grist-widget tests (#677) This moves a few more gristUtils methods to gristWebDriverUtils, which is easier to use from other repositories (specifically grist-widget). --- test/nbrowser/gristUtils.ts | 48 +++------------------------- test/nbrowser/gristWebDriverUtils.ts | 43 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 43 deletions(-) diff --git a/test/nbrowser/gristUtils.ts b/test/nbrowser/gristUtils.ts index c6e337da..3cab6560 100644 --- a/test/nbrowser/gristUtils.ts +++ b/test/nbrowser/gristUtils.ts @@ -83,6 +83,11 @@ export const selectWidget = webdriverUtils.selectWidget.bind(webdriverUtils); export const dismissBehavioralPrompts = webdriverUtils.dismissBehavioralPrompts.bind(webdriverUtils); export const toggleSelectable = webdriverUtils.toggleSelectable.bind(webdriverUtils); export const waitToPass = webdriverUtils.waitToPass.bind(webdriverUtils); +export const refreshDismiss = webdriverUtils.refreshDismiss.bind(webdriverUtils); +export const acceptAlert = webdriverUtils.acceptAlert.bind(webdriverUtils); +export const isAlertShown = webdriverUtils.isAlertShown.bind(webdriverUtils); +export const waitForDocToLoad = webdriverUtils.waitForDocToLoad.bind(webdriverUtils); +export const reloadDoc = webdriverUtils.reloadDoc.bind(webdriverUtils); export const fixturesRoot: string = testUtils.fixturesRoot; @@ -776,21 +781,6 @@ export async function loadDocMenu(relPath: string, wait: boolean = true): Promis if (wait) { await waitForDocMenuToLoad(); } } -/** - * Wait for the doc to be loaded, to the point of finishing fetch for the data on the current - * page. If you navigate from a doc page, use e.g. waitForUrl() before waitForDocToLoad() to - * ensure you are checking the new page and not the old. - */ -export async function waitForDocToLoad(timeoutMs: number = 10000): Promise { - await driver.findWait('.viewsection_title', timeoutMs); - await waitForServer(); -} - -export async function reloadDoc() { - await driver.navigate().refresh(); - await waitForDocToLoad(); -} - /** * Wait for the doc list to show, to know that workspaces are fetched, and imports enabled. */ @@ -2879,34 +2869,6 @@ export async function getFilterMenuState(): Promise { })); } -/** - * Refresh browser and dismiss alert that is shown (for refreshing during edits). - */ -export async function refreshDismiss() { - await driver.navigate().refresh(); - await acceptAlert(); - await waitForDocToLoad(); -} - -/** - * Accepts an alert. - */ -export async function acceptAlert() { - await (await driver.switchTo().alert()).accept(); -} - -/** - * Returns whether an alert is shown. - */ -export async function isAlertShown() { - try { - await driver.switchTo().alert(); - return true; - } catch { - return false; - } -} - /** * Dismisses any tutorial card that might be active. */ diff --git a/test/nbrowser/gristWebDriverUtils.ts b/test/nbrowser/gristWebDriverUtils.ts index ed1b394d..2be86a6e 100644 --- a/test/nbrowser/gristWebDriverUtils.ts +++ b/test/nbrowser/gristWebDriverUtils.ts @@ -203,6 +203,49 @@ export class GristWebDriverUtils { await check(); } } + + /** + * Refresh browser and dismiss alert that is shown (for refreshing during edits). + */ + public async refreshDismiss() { + await this.driver.navigate().refresh(); + await this.acceptAlert(); + await this.waitForDocToLoad(); + } + + /** + * Accepts an alert. + */ + public async acceptAlert() { + await (await this.driver.switchTo().alert()).accept(); + } + + /** + * Returns whether an alert is shown. + */ + public async isAlertShown() { + try { + await this.driver.switchTo().alert(); + return true; + } catch { + return false; + } + } + + /** + * Wait for the doc to be loaded, to the point of finishing fetch for the data on the current + * page. If you navigate from a doc page, use e.g. waitForUrl() before waitForDocToLoad() to + * ensure you are checking the new page and not the old. + */ + public async waitForDocToLoad(timeoutMs: number = 10000): Promise { + await this.driver.findWait('.viewsection_title', timeoutMs); + await this.waitForServer(); + } + + public async reloadDoc() { + await this.driver.navigate().refresh(); + await this.waitForDocToLoad(); + } } export interface WindowDimensions {