From ae6b549b83a618307ad67abc6710a064142d8b5d Mon Sep 17 00:00:00 2001 From: EmmaLRussell Date: Wed, 11 Oct 2023 11:25:20 +0100 Subject: [PATCH] e2e test and lint --- app/static/src/app/localStorageManager.ts | 2 +- app/static/src/app/store/appState/actions.ts | 2 +- app/static/tests/e2e/sessions.etest.ts | 21 ++++++++++++------- .../components/sessions/sessionsPage.test.ts | 3 +-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/static/src/app/localStorageManager.ts b/app/static/src/app/localStorageManager.ts index ea635b55d..cc0a7e7ae 100644 --- a/app/static/src/app/localStorageManager.ts +++ b/app/static/src/app/localStorageManager.ts @@ -1,4 +1,4 @@ -import {UserPreferences} from "./store/appState/state"; +import { UserPreferences } from "./store/appState/state"; class LocalStorageManager { static _sessionIdsKey = (appName: string, basePath: string) => { diff --git a/app/static/src/app/store/appState/actions.ts b/app/static/src/app/store/appState/actions.ts index 8e94a0cea..94bdec93e 100644 --- a/app/static/src/app/store/appState/actions.ts +++ b/app/static/src/app/store/appState/actions.ts @@ -5,7 +5,7 @@ import { AppConfig } from "../../types/responseTypes"; import { CodeMutation } from "../code/mutations"; import { RunMutation } from "../run/mutations"; import { ModelAction } from "../model/actions"; -import {AppState, AppType, UserPreferences} from "./state"; +import { AppState, AppType, UserPreferences } from "./state"; import { AppStateMutation } from "./mutations"; import { serialiseState } from "../../serialise"; import { FitState } from "../fit/state"; diff --git a/app/static/tests/e2e/sessions.etest.ts b/app/static/tests/e2e/sessions.etest.ts index 944cd3d12..d992a32af 100644 --- a/app/static/tests/e2e/sessions.etest.ts +++ b/app/static/tests/e2e/sessions.etest.ts @@ -4,6 +4,7 @@ import { Page } from "@playwright/test"; import * as os from "os"; +import * as fs from "fs"; import { writeCode, newFitCode, @@ -29,10 +30,9 @@ test.describe("Sessions tests", () => { test("can use Sessions page", async () => { // We need to use a browser with persistent context instead of the default incognito browser so that // we can use the session ids in local storage - const userDataDir = os.tmpdir(); + const userDataDir = fs.mkdtempSync(`${os.tmpdir()}/`); const browser = await chromium.launchPersistentContext(userDataDir); const page = await browser.newPage(); - await page.goto(appUrl); // change code in this session, which we will later reload and check that we can see the code changes @@ -95,7 +95,7 @@ test.describe("Sessions tests", () => { await expect(await page.innerText(":nth-match(.session-col-header, 5)")).toBe("Delete"); await expect(await page.innerText(":nth-match(.session-col-header, 6)")).toBe("Shareable Link"); - await expect(await page.innerText(".session-label")).toBe("--no label--"); + await expect(await page.locator(".session-label")).toHaveText("--no label--"); // Can copy code and link for a session await page.click(":nth-match(.session-copy-code, 2)"); @@ -116,15 +116,22 @@ test.describe("Sessions tests", () => { await enterSessionLabel(page, "header-edit-session-label", "current session label"); await expect(await page.innerText("#sessions-menu")).toBe("Session: current session label"); + // Toggle 'Show unlabelled sessions' - all historic sessions should be filtered out + const unlabelledCount = await page.locator(".previous-session-row").count(); + await expect(unlabelledCount).toBeGreaterThan(0); + await page.click("input#show-unlabelled-check"); + await expect(await page.locator(".previous-session-row")).toHaveCount(0); + await page.click("input#show-unlabelled-check"); + await expect(await page.locator(".previous-session-row")).toHaveCount(unlabelledCount); + // Set the current session label on a previous session - await page.click(":nth-match(.session-edit-label i, 2)"); + await page.click(":nth-match(.session-edit-label i, 1)"); await enterSessionLabel(page, "page-edit-session-label", "previous session label"); - await expect(await page.locator(":nth-match(.session-label, 2)")).toHaveText( + await expect(await page.locator(":nth-match(.session-label, 1)")).toHaveText( "previous session label", { timeout } ); - // NB this will load the second load link, i.e. the older session, not the current one - await page.click(":nth-match(.session-load a, 3)"); // 3rd because there are two of these on the current + await page.click(":nth-match(.session-load a, 1)"); // Check all session values have been rehydrated: diff --git a/app/static/tests/unit/components/sessions/sessionsPage.test.ts b/app/static/tests/unit/components/sessions/sessionsPage.test.ts index 2ee3a4ce9..c5a02b614 100644 --- a/app/static/tests/unit/components/sessions/sessionsPage.test.ts +++ b/app/static/tests/unit/components/sessions/sessionsPage.test.ts @@ -33,7 +33,7 @@ describe("SessionsPage", () => { const currentSessionId = "abc"; const getWrapper = (sessionsMetadata: SessionMetadata[] | null, sessionId: string | undefined, - showUnlabelledSessions = true) => { + showUnlabelledSessions = true) => { const store = new Vuex.Store({ state: mockBasicState({ appName: "testApp", @@ -390,4 +390,3 @@ describe("SessionsPage", () => { expect((wrapper.find("input#show-unlabelled-check").element as HTMLInputElement).checked).toBe(false); }); }); -