diff options
| author | Tobias Järvelöv <tobias.jarvelov@mullvad.net> | 2025-02-27 13:19:14 +0100 |
|---|---|---|
| committer | Tobias Järvelöv <tobias.jarvelov@mullvad.net> | 2025-04-28 12:53:03 +0200 |
| commit | 3555ce59e137ad771850b9f2d40086f52723c175 (patch) | |
| tree | 02ca3ba6729013109d10daad674715bb5f09f0d5 | |
| parent | fd8d54d8e70317eaba56be4205902d5144a5660f (diff) | |
| download | mullvadvpn-3555ce59e137ad771850b9f2d40086f52723c175.tar.xz mullvadvpn-3555ce59e137ad771850b9f2d40086f52723c175.zip | |
Refactor waitForNextRoute into a factory
| -rw-r--r-- | desktop/packages/mullvad-vpn/test/e2e/utils.ts | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/desktop/packages/mullvad-vpn/test/e2e/utils.ts b/desktop/packages/mullvad-vpn/test/e2e/utils.ts index 2df6d9bf27..06e22ab52b 100644 --- a/desktop/packages/mullvad-vpn/test/e2e/utils.ts +++ b/desktop/packages/mullvad-vpn/test/e2e/utils.ts @@ -64,11 +64,12 @@ const currentRouteFactory = (app: ElectronApplication) => { }; const waitForNavigationFactory = (app: ElectronApplication, page: Page) => { + const waitForNextRoute = waitForNextRouteFactory(app); // Wait for navigation animation to finish. A function can be provided that initiates the // navigation, e.g. clicks a button. return async (initiateNavigation?: () => Promise<void> | void) => { // Wait for route to change after optionally initiating the navigation. - const [route] = await Promise.all([waitForNextRoute(app), initiateNavigation?.()]); + const [route] = await Promise.all([waitForNextRoute(), initiateNavigation?.()]); // Wait for view corresponding to new route to appear await page.getByTestId(route).isVisible(); @@ -111,15 +112,16 @@ const waitForRouteFactory = (app: ElectronApplication) => { }; // Returns the route when it changes -const waitForNextRoute = (app: ElectronApplication): Promise<string> => { - return app.evaluate( - ({ ipcMain }) => - new Promise((resolve) => { - ipcMain.once('navigation-setHistory', (_event, history: History) => { - resolve(history.entries[history.index].pathname); - }); - }), - ); +const waitForNextRouteFactory = (app: ElectronApplication) => { + return async () => + app.evaluate<string>( + ({ ipcMain }) => + new Promise((resolve) => { + ipcMain.once('navigation-setHistory', (_event, history: History) => { + resolve(history.entries[history.index].pathname); + }); + }), + ); }; const getStyleProperty = (locator: Locator, property: string) => { |
