Skip to content

Commit

Permalink
make some more methods available for grist-widget tests (#677)
Browse files Browse the repository at this point in the history
This moves a few more gristUtils methods to gristWebDriverUtils,
which is easier to use from other repositories (specifically
grist-widget).
  • Loading branch information
paulfitz authored Sep 18, 2023
1 parent 1737087 commit 2df1b2d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 43 deletions.
48 changes: 5 additions & 43 deletions test/nbrowser/gristUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<void> {
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.
*/
Expand Down Expand Up @@ -2879,34 +2869,6 @@ export async function getFilterMenuState(): Promise<FilterMenuValue[]> {
}));
}

/**
* 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.
*/
Expand Down
43 changes: 43 additions & 0 deletions test/nbrowser/gristWebDriverUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
await this.driver.findWait('.viewsection_title', timeoutMs);
await this.waitForServer();
}

public async reloadDoc() {
await this.driver.navigate().refresh();
await this.waitForDocToLoad();
}
}

export interface WindowDimensions {
Expand Down

0 comments on commit 2df1b2d

Please sign in to comment.