From 2d2ef9ddbd626f757c765715365ee2779b574c61 Mon Sep 17 00:00:00 2001 From: Gordon Farrell Date: Tue, 7 Jan 2025 12:43:57 -0700 Subject: [PATCH 01/11] saving urlParams to session storage, testing retrieval and setting --- .../src/app/components/BaseFilter.tsx | 2 ++ .../src/app/components/EcrTableClient.tsx | 19 +++++++++++----- .../src/app/components/LibrarySearch.tsx | 5 +++++ .../ecr-viewer/src/app/components/helpers.ts | 22 +++++++++++++++++++ 4 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 containers/ecr-viewer/src/app/components/helpers.ts diff --git a/containers/ecr-viewer/src/app/components/BaseFilter.tsx b/containers/ecr-viewer/src/app/components/BaseFilter.tsx index b13ddbf97d..4540077b4b 100644 --- a/containers/ecr-viewer/src/app/components/BaseFilter.tsx +++ b/containers/ecr-viewer/src/app/components/BaseFilter.tsx @@ -9,6 +9,7 @@ import React, { import { Button } from "@trussworks/react-uswds"; import { useRouter, usePathname, useSearchParams } from "next/navigation"; import { FILTER_CLOSED, FILTER_SUBMITTED, FilterOpenContext } from "./Filters"; +import { saveToSessionStorage } from "./helpers"; /** * Custom hook to manage query parameters in the URL (set, delete, and update). Hook always resets page back to 1. @@ -61,6 +62,7 @@ export const useQueryParam = () => { // Update query params if (searchParams.get(key) !== updatedParams.get(key)) { + saveToSessionStorage("urlParams", updatedParams.toString()); router.push(pathname + "?" + updatedParams.toString()); } }; diff --git a/containers/ecr-viewer/src/app/components/EcrTableClient.tsx b/containers/ecr-viewer/src/app/components/EcrTableClient.tsx index d19d531fb5..853ec96e26 100644 --- a/containers/ecr-viewer/src/app/components/EcrTableClient.tsx +++ b/containers/ecr-viewer/src/app/components/EcrTableClient.tsx @@ -8,6 +8,7 @@ import { usePathname, useSearchParams, useRouter } from "next/navigation"; import { range } from "../view-data/utils/utils"; import classNames from "classnames"; import Link from "next/link"; +import { retrieveFromSessionStorage } from "./helpers"; type EcrTableClientProps = { data: EcrDisplay[]; @@ -106,12 +107,18 @@ export const EcrTableClient: React.FC = ({ * Updates the URL with the current sort preferences. */ useEffect(() => { - const current = new URLSearchParams(Array.from(searchParams.entries())); - current.set("columnId", sortPreferences.columnId.toString()); - current.set("direction", sortPreferences.direction.toString()); - const search = current.toString(); - const query = search ? `?${search}` : ""; - router.push(`${pathname}${query}`); + const sessionUrlParams = retrieveFromSessionStorage("urlParams"); + console.log("Retrieved session params: ", sessionUrlParams); + if (sessionUrlParams) { + router.push(`${pathname}?${sessionUrlParams}`); + } else { + const current = new URLSearchParams(Array.from(searchParams.entries())); + current.set("columnId", sortPreferences.columnId.toString()); + current.set("direction", sortPreferences.direction.toString()); + const search = current.toString(); + const query = search ? `?${search}` : ""; + router.push(`${pathname}${query}`); + } }, [sortPreferences]); /** diff --git a/containers/ecr-viewer/src/app/components/LibrarySearch.tsx b/containers/ecr-viewer/src/app/components/LibrarySearch.tsx index 4be9c7d7c6..694cca90f2 100644 --- a/containers/ecr-viewer/src/app/components/LibrarySearch.tsx +++ b/containers/ecr-viewer/src/app/components/LibrarySearch.tsx @@ -3,6 +3,7 @@ import { Search } from "@trussworks/react-uswds"; import { usePathname, useRouter, useSearchParams } from "next/navigation"; import { useCallback } from "react"; +import { saveToSessionStorage } from "./helpers"; interface LibrarySearchProps { className?: string; @@ -39,6 +40,10 @@ const LibrarySearch = ({ className, textBoxClassName }: LibrarySearchProps) => { e.currentTarget.elements.namedItem("search-field") as HTMLInputElement )?.value; if (searchParams.get("search") !== searchTerm) { + saveToSessionStorage( + "urlParams", + createQueryString("search", searchTerm), + ); router.push(pathname + "?" + createQueryString("search", searchTerm)); } }} diff --git a/containers/ecr-viewer/src/app/components/helpers.ts b/containers/ecr-viewer/src/app/components/helpers.ts new file mode 100644 index 0000000000..048bf4a918 --- /dev/null +++ b/containers/ecr-viewer/src/app/components/helpers.ts @@ -0,0 +1,22 @@ +/** + * Saves a key-value pair to session storage. + * @param key - The key under which the value will be stored. + * @param value - The value to be stored. Can be a string or any serializable object. + */ +export const saveToSessionStorage = ( + key: string, + value: string | object, +): void => { + const serializedValue = JSON.stringify(value); + sessionStorage.setItem(key, serializedValue); +}; + +/** + * Retrieves a key-value pair to session storage. + * @param key - The key under which the value was stored. + * @returns string - The stored value from session storage + */ +export const retrieveFromSessionStorage = (key: string): string | object => { + const storedValue = sessionStorage.getItem(key); + return JSON.parse(storedValue); +}; From ac01ce05a8b01f403dbfd41c8d124c6b71dc4299 Mon Sep 17 00:00:00 2001 From: Gordon Farrell Date: Wed, 8 Jan 2025 14:37:33 -0700 Subject: [PATCH 02/11] save to session storage on name click, apply to back button --- .../src/app/components/BaseFilter.tsx | 2 -- .../src/app/components/EcrTableClient.tsx | 29 +++++++++---------- .../src/app/components/LibrarySearch.tsx | 5 ---- .../app/view-data/components/BackButton.tsx | 6 +++- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/containers/ecr-viewer/src/app/components/BaseFilter.tsx b/containers/ecr-viewer/src/app/components/BaseFilter.tsx index 4540077b4b..b13ddbf97d 100644 --- a/containers/ecr-viewer/src/app/components/BaseFilter.tsx +++ b/containers/ecr-viewer/src/app/components/BaseFilter.tsx @@ -9,7 +9,6 @@ import React, { import { Button } from "@trussworks/react-uswds"; import { useRouter, usePathname, useSearchParams } from "next/navigation"; import { FILTER_CLOSED, FILTER_SUBMITTED, FilterOpenContext } from "./Filters"; -import { saveToSessionStorage } from "./helpers"; /** * Custom hook to manage query parameters in the URL (set, delete, and update). Hook always resets page back to 1. @@ -62,7 +61,6 @@ export const useQueryParam = () => { // Update query params if (searchParams.get(key) !== updatedParams.get(key)) { - saveToSessionStorage("urlParams", updatedParams.toString()); router.push(pathname + "?" + updatedParams.toString()); } }; diff --git a/containers/ecr-viewer/src/app/components/EcrTableClient.tsx b/containers/ecr-viewer/src/app/components/EcrTableClient.tsx index 853ec96e26..06fb4fc5d8 100644 --- a/containers/ecr-viewer/src/app/components/EcrTableClient.tsx +++ b/containers/ecr-viewer/src/app/components/EcrTableClient.tsx @@ -8,7 +8,7 @@ import { usePathname, useSearchParams, useRouter } from "next/navigation"; import { range } from "../view-data/utils/utils"; import classNames from "classnames"; import Link from "next/link"; -import { retrieveFromSessionStorage } from "./helpers"; +import { saveToSessionStorage } from "./helpers"; type EcrTableClientProps = { data: EcrDisplay[]; @@ -67,7 +67,7 @@ const initialHeaders = [ { id: "reportable_condition", value: "Reportable Condition", - className: "library-condition-colum", + className: "library-condition-column", dataSortable: false, sortDirection: "", }, @@ -107,18 +107,12 @@ export const EcrTableClient: React.FC = ({ * Updates the URL with the current sort preferences. */ useEffect(() => { - const sessionUrlParams = retrieveFromSessionStorage("urlParams"); - console.log("Retrieved session params: ", sessionUrlParams); - if (sessionUrlParams) { - router.push(`${pathname}?${sessionUrlParams}`); - } else { - const current = new URLSearchParams(Array.from(searchParams.entries())); - current.set("columnId", sortPreferences.columnId.toString()); - current.set("direction", sortPreferences.direction.toString()); - const search = current.toString(); - const query = search ? `?${search}` : ""; - router.push(`${pathname}${query}`); - } + const current = new URLSearchParams(Array.from(searchParams.entries())); + current.set("columnId", sortPreferences.columnId.toString()); + current.set("direction", sortPreferences.direction.toString()); + const search = current.toString(); + const query = search ? `?${search}` : ""; + router.push(`${pathname}${query}`); }, [sortPreferences]); /** @@ -290,6 +284,8 @@ const DataRow = ({ item }: { item: EcrDisplay }) => { const patientReportDate = formatDate(patientReportDateObj); const patientReportTime = formatTime(patientReportDateObj); + const searchParams = useSearchParams(); + const conditionsList = (
    {item.reportable_conditions.map((rc, index) => ( @@ -305,11 +301,14 @@ const DataRow = ({ item }: { item: EcrDisplay }) => { ))}
); + const saveUrl = () => { + saveToSessionStorage("urlParams", searchParams.toString()); + }; return ( - + {patient_first_name} {patient_last_name}
diff --git a/containers/ecr-viewer/src/app/components/LibrarySearch.tsx b/containers/ecr-viewer/src/app/components/LibrarySearch.tsx index 694cca90f2..4be9c7d7c6 100644 --- a/containers/ecr-viewer/src/app/components/LibrarySearch.tsx +++ b/containers/ecr-viewer/src/app/components/LibrarySearch.tsx @@ -3,7 +3,6 @@ import { Search } from "@trussworks/react-uswds"; import { usePathname, useRouter, useSearchParams } from "next/navigation"; import { useCallback } from "react"; -import { saveToSessionStorage } from "./helpers"; interface LibrarySearchProps { className?: string; @@ -40,10 +39,6 @@ const LibrarySearch = ({ className, textBoxClassName }: LibrarySearchProps) => { e.currentTarget.elements.namedItem("search-field") as HTMLInputElement )?.value; if (searchParams.get("search") !== searchTerm) { - saveToSessionStorage( - "urlParams", - createQueryString("search", searchTerm), - ); router.push(pathname + "?" + createQueryString("search", searchTerm)); } }} diff --git a/containers/ecr-viewer/src/app/view-data/components/BackButton.tsx b/containers/ecr-viewer/src/app/view-data/components/BackButton.tsx index 8c4cbf12e1..3cb1c3670a 100644 --- a/containers/ecr-viewer/src/app/view-data/components/BackButton.tsx +++ b/containers/ecr-viewer/src/app/view-data/components/BackButton.tsx @@ -3,6 +3,7 @@ import { Icon } from "@trussworks/react-uswds"; import Link from "next/link"; import classNames from "classnames"; import { env } from "next-runtime-env"; +import { retrieveFromSessionStorage } from "../../components/helpers"; interface BackButtonProps { className?: string; @@ -19,11 +20,14 @@ interface BackButtonProps { export const BackButton = ({ className, iconClassName }: BackButtonProps) => { const isNonIntegratedViewer = env("NEXT_PUBLIC_NON_INTEGRATED_VIEWER") === "true"; + + const savedUrlParams = retrieveFromSessionStorage("urlParams"); + return ( <> {isNonIntegratedViewer ? ( Date: Wed, 8 Jan 2025 14:47:49 -0700 Subject: [PATCH 03/11] add tests for new session storage utils --- .../src/app/components/EcrTableClient.tsx | 2 +- .../app/components/{helpers.ts => utils.ts} | 0 .../src/app/tests/components/Utils.test.tsx | 62 +++++++++++++++++++ .../__snapshots__/EcrTable.test.tsx.snap | 4 +- .../app/view-data/components/BackButton.tsx | 2 +- 5 files changed, 66 insertions(+), 4 deletions(-) rename containers/ecr-viewer/src/app/components/{helpers.ts => utils.ts} (100%) create mode 100644 containers/ecr-viewer/src/app/tests/components/Utils.test.tsx diff --git a/containers/ecr-viewer/src/app/components/EcrTableClient.tsx b/containers/ecr-viewer/src/app/components/EcrTableClient.tsx index 06fb4fc5d8..5732c0a59f 100644 --- a/containers/ecr-viewer/src/app/components/EcrTableClient.tsx +++ b/containers/ecr-viewer/src/app/components/EcrTableClient.tsx @@ -8,7 +8,7 @@ import { usePathname, useSearchParams, useRouter } from "next/navigation"; import { range } from "../view-data/utils/utils"; import classNames from "classnames"; import Link from "next/link"; -import { saveToSessionStorage } from "./helpers"; +import { saveToSessionStorage } from "./utils"; type EcrTableClientProps = { data: EcrDisplay[]; diff --git a/containers/ecr-viewer/src/app/components/helpers.ts b/containers/ecr-viewer/src/app/components/utils.ts similarity index 100% rename from containers/ecr-viewer/src/app/components/helpers.ts rename to containers/ecr-viewer/src/app/components/utils.ts diff --git a/containers/ecr-viewer/src/app/tests/components/Utils.test.tsx b/containers/ecr-viewer/src/app/tests/components/Utils.test.tsx new file mode 100644 index 0000000000..5886ea2665 --- /dev/null +++ b/containers/ecr-viewer/src/app/tests/components/Utils.test.tsx @@ -0,0 +1,62 @@ +import { + saveToSessionStorage, + retrieveFromSessionStorage, +} from "../../components/utils.ts"; + +describe("Session Storage saving utils", () => { + beforeEach(() => { + sessionStorage.clear(); + }); + + describe("saveToSessionStorage", () => { + it("should save a string value to session storage", () => { + const key = "Bread"; + const value = "Baguette"; + saveToSessionStorage(key, value); + + expect(sessionStorage.getItem(key)).toBe(JSON.stringify(value)); + }); + + it("should save an object value to session storage", () => { + const key = "testKey"; + const value = { name: "Heironymous", age: 37 }; + saveToSessionStorage(key, value); + + expect(sessionStorage.getItem(key)).toBe(JSON.stringify(value)); + }); + }); + + describe("retrieveFromSessionStorage", () => { + it("should retrieve a string value from session storage", () => { + const key = "fruit"; + const value = "Apples"; + sessionStorage.setItem(key, JSON.stringify(value)); + + const retrievedValue = retrieveFromSessionStorage(key); + expect(retrievedValue).toBe(value); + }); + + it("should retrieve an object value from session storage", () => { + const key = "patient"; + const value = { name: "Arabelle", age: 22 }; + sessionStorage.setItem(key, JSON.stringify(value)); + + const retrievedValue = retrieveFromSessionStorage(key); + expect(retrievedValue).toEqual(value); + }); + + it("should return null if the key does not exist", () => { + const key = "nonExistentKey"; + const retrievedValue = retrieveFromSessionStorage(key); + + expect(retrievedValue).toBeNull(); + }); + + it("should throw an error for invalid JSON in session storage", () => { + const key = "aKey"; + sessionStorage.setItem(key, "invalid-json"); + + expect(() => retrieveFromSessionStorage(key)).toThrow(SyntaxError); + }); + }); +}); diff --git a/containers/ecr-viewer/src/app/tests/components/__snapshots__/EcrTable.test.tsx.snap b/containers/ecr-viewer/src/app/tests/components/__snapshots__/EcrTable.test.tsx.snap index 472b0718c9..72dbb66246 100644 --- a/containers/ecr-viewer/src/app/tests/components/__snapshots__/EcrTable.test.tsx.snap +++ b/containers/ecr-viewer/src/app/tests/components/__snapshots__/EcrTable.test.tsx.snap @@ -74,7 +74,7 @@ exports[`EcrTable Snapshot test for EcrTableLoading should match snapshot 1`] = Date: Wed, 8 Jan 2025 14:55:21 -0700 Subject: [PATCH 04/11] typo fix --- containers/ecr-viewer/src/app/components/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/containers/ecr-viewer/src/app/components/utils.ts b/containers/ecr-viewer/src/app/components/utils.ts index 048bf4a918..9b3c1612be 100644 --- a/containers/ecr-viewer/src/app/components/utils.ts +++ b/containers/ecr-viewer/src/app/components/utils.ts @@ -12,7 +12,7 @@ export const saveToSessionStorage = ( }; /** - * Retrieves a key-value pair to session storage. + * Retrieves a key-value pair from session storage. * @param key - The key under which the value was stored. * @returns string - The stored value from session storage */ From de986fc403bca77677f29ed2ed583c65879f9a04 Mon Sep 17 00:00:00 2001 From: Gordon Farrell Date: Thu, 9 Jan 2025 12:13:48 -0700 Subject: [PATCH 05/11] Add playwright test, fix session storage undefined error --- containers/ecr-viewer/e2e/ecr-library.spec.ts | 26 +++++++++++++++++++ .../ecr-viewer/src/app/components/utils.ts | 15 ++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/containers/ecr-viewer/e2e/ecr-library.spec.ts b/containers/ecr-viewer/e2e/ecr-library.spec.ts index 9768fce745..3e54f7dbfd 100644 --- a/containers/ecr-viewer/e2e/ecr-library.spec.ts +++ b/containers/ecr-viewer/e2e/ecr-library.spec.ts @@ -36,6 +36,32 @@ test.describe("eCR Library Filtering", () => { ); }); + test("Filtering should persist when clicking into and returning from an eCR", async ({ + page, + }) => { + await page.goto("/ecr-viewer"); + await page.waitForURL("/ecr-viewer?columnId=date_created&direction=DESC"); + await expect(page.getByTestId("filter-tag")).toContainText( + totalNumOfConditions, + ); + + await page.getByLabel("Filter by reportable condition").click(); + // Add delay since conditions rerenders shortly after opening + await page.getByText("Deselect all").click({ delay: 200 }); + await page.getByRole("group").getByText("Anthrax (disorder)").click(); + await page.getByLabel("Apply Filter").click(); + + //Click into the first eCR + await page.$("table tr:first-child td:first-child a").click(); + //Return to the eCR Library + await page.getByText("Back to eCR Library").click({ delay: 200 }); + + await expect(page.getByText("Showing 1-16")).toBeVisible(); + expect((await page.locator("tbody > tr").allTextContents()).length).toEqual( + 16, + ); + }); + test("Search should filter results ", async ({ page }) => { await page.goto("/ecr-viewer"); await page.waitForURL("/ecr-viewer?columnId=date_created&direction=DESC"); diff --git a/containers/ecr-viewer/src/app/components/utils.ts b/containers/ecr-viewer/src/app/components/utils.ts index 9b3c1612be..0ae5c82d67 100644 --- a/containers/ecr-viewer/src/app/components/utils.ts +++ b/containers/ecr-viewer/src/app/components/utils.ts @@ -8,7 +8,12 @@ export const saveToSessionStorage = ( value: string | object, ): void => { const serializedValue = JSON.stringify(value); - sessionStorage.setItem(key, serializedValue); + + if (typeof window !== "undefined" && window.sessionStorage) { + sessionStorage.setItem(key, serializedValue); + } else { + console.warn("sessionStorage is not available"); + } }; /** @@ -17,6 +22,10 @@ export const saveToSessionStorage = ( * @returns string - The stored value from session storage */ export const retrieveFromSessionStorage = (key: string): string | object => { - const storedValue = sessionStorage.getItem(key); - return JSON.parse(storedValue); + if (typeof window !== "undefined" && window.sessionStorage) { + const storedValue = sessionStorage.getItem(key); + return JSON.parse(storedValue); + } else { + console.warn("sessionStorage is not available"); + } }; From 7bccae173ddbfe6ab7c88728f1e2928af167701e Mon Sep 17 00:00:00 2001 From: Gordon Farrell Date: Thu, 9 Jan 2025 12:20:54 -0700 Subject: [PATCH 06/11] Add undefined return type and return undefined if session storage doesnt exist to fix error --- containers/ecr-viewer/src/app/components/utils.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/containers/ecr-viewer/src/app/components/utils.ts b/containers/ecr-viewer/src/app/components/utils.ts index 0ae5c82d67..63570a6fb3 100644 --- a/containers/ecr-viewer/src/app/components/utils.ts +++ b/containers/ecr-viewer/src/app/components/utils.ts @@ -21,11 +21,14 @@ export const saveToSessionStorage = ( * @param key - The key under which the value was stored. * @returns string - The stored value from session storage */ -export const retrieveFromSessionStorage = (key: string): string | object => { +export const retrieveFromSessionStorage = ( + key: string, +): string | object | undefined => { if (typeof window !== "undefined" && window.sessionStorage) { const storedValue = sessionStorage.getItem(key); return JSON.parse(storedValue); } else { console.warn("sessionStorage is not available"); + return undefined; } }; From 03cfcfe33325d33f1f366663e01f7f4d86651111 Mon Sep 17 00:00:00 2001 From: Gordon Farrell Date: Thu, 9 Jan 2025 12:22:15 -0700 Subject: [PATCH 07/11] change undefined return to null --- containers/ecr-viewer/src/app/components/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/containers/ecr-viewer/src/app/components/utils.ts b/containers/ecr-viewer/src/app/components/utils.ts index 63570a6fb3..29163bfae0 100644 --- a/containers/ecr-viewer/src/app/components/utils.ts +++ b/containers/ecr-viewer/src/app/components/utils.ts @@ -23,12 +23,12 @@ export const saveToSessionStorage = ( */ export const retrieveFromSessionStorage = ( key: string, -): string | object | undefined => { +): string | object | null => { if (typeof window !== "undefined" && window.sessionStorage) { const storedValue = sessionStorage.getItem(key); return JSON.parse(storedValue); } else { console.warn("sessionStorage is not available"); - return undefined; + return null; } }; From ad527566b18eac3d7fa075338f19ccb3b5fc046e Mon Sep 17 00:00:00 2001 From: Gordon Farrell Date: Thu, 9 Jan 2025 12:23:08 -0700 Subject: [PATCH 08/11] update description --- containers/ecr-viewer/src/app/components/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/containers/ecr-viewer/src/app/components/utils.ts b/containers/ecr-viewer/src/app/components/utils.ts index 29163bfae0..dd51e68004 100644 --- a/containers/ecr-viewer/src/app/components/utils.ts +++ b/containers/ecr-viewer/src/app/components/utils.ts @@ -19,7 +19,7 @@ export const saveToSessionStorage = ( /** * Retrieves a key-value pair from session storage. * @param key - The key under which the value was stored. - * @returns string - The stored value from session storage + * @returns string or null - The stored value from session storage or null if it finds nothing */ export const retrieveFromSessionStorage = ( key: string, From 74301290a665fb69b7a7fdeed8213aef07f15936 Mon Sep 17 00:00:00 2001 From: Gordon Farrell Date: Thu, 9 Jan 2025 12:51:20 -0700 Subject: [PATCH 09/11] mock session storage for playwright test --- containers/ecr-viewer/e2e/ecr-library.spec.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/containers/ecr-viewer/e2e/ecr-library.spec.ts b/containers/ecr-viewer/e2e/ecr-library.spec.ts index 3e54f7dbfd..7e69801ffe 100644 --- a/containers/ecr-viewer/e2e/ecr-library.spec.ts +++ b/containers/ecr-viewer/e2e/ecr-library.spec.ts @@ -40,6 +40,29 @@ test.describe("eCR Library Filtering", () => { page, }) => { await page.goto("/ecr-viewer"); + + //Mock session storage + await page.evaluate(() => { + Object.defineProperty(window, "sessionStorage", { + value: { + storage: {}, + setItem(key, value) { + this.storage[key] = value; + }, + getItem(key) { + return this.storage[key] || null; + }, + removeItem(key) { + delete this.storage[key]; + }, + clear() { + this.storage = {}; + }, + }, + writable: true, + }); + }); + await page.waitForURL("/ecr-viewer?columnId=date_created&direction=DESC"); await expect(page.getByTestId("filter-tag")).toContainText( totalNumOfConditions, From b07ab972801fb78677bcf7c3fb6e32dc0ba58d9e Mon Sep 17 00:00:00 2001 From: Gordon Farrell Date: Thu, 9 Jan 2025 13:52:26 -0700 Subject: [PATCH 10/11] update to use locator method --- containers/ecr-viewer/e2e/ecr-library.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/containers/ecr-viewer/e2e/ecr-library.spec.ts b/containers/ecr-viewer/e2e/ecr-library.spec.ts index 7e69801ffe..f23366b60f 100644 --- a/containers/ecr-viewer/e2e/ecr-library.spec.ts +++ b/containers/ecr-viewer/e2e/ecr-library.spec.ts @@ -75,7 +75,7 @@ test.describe("eCR Library Filtering", () => { await page.getByLabel("Apply Filter").click(); //Click into the first eCR - await page.$("table tr:first-child td:first-child a").click(); + await page.locator("table tr:first-child td:first-child a").click(); //Return to the eCR Library await page.getByText("Back to eCR Library").click({ delay: 200 }); From e681e3e0039fbf9ab80ba9dd00863619b5198591 Mon Sep 17 00:00:00 2001 From: Gordon Farrell Date: Mon, 13 Jan 2025 09:27:18 -0700 Subject: [PATCH 11/11] nevermind on the e2e for sessionStorage --- containers/ecr-viewer/e2e/ecr-library.spec.ts | 49 ------------------- 1 file changed, 49 deletions(-) diff --git a/containers/ecr-viewer/e2e/ecr-library.spec.ts b/containers/ecr-viewer/e2e/ecr-library.spec.ts index f23366b60f..9768fce745 100644 --- a/containers/ecr-viewer/e2e/ecr-library.spec.ts +++ b/containers/ecr-viewer/e2e/ecr-library.spec.ts @@ -36,55 +36,6 @@ test.describe("eCR Library Filtering", () => { ); }); - test("Filtering should persist when clicking into and returning from an eCR", async ({ - page, - }) => { - await page.goto("/ecr-viewer"); - - //Mock session storage - await page.evaluate(() => { - Object.defineProperty(window, "sessionStorage", { - value: { - storage: {}, - setItem(key, value) { - this.storage[key] = value; - }, - getItem(key) { - return this.storage[key] || null; - }, - removeItem(key) { - delete this.storage[key]; - }, - clear() { - this.storage = {}; - }, - }, - writable: true, - }); - }); - - await page.waitForURL("/ecr-viewer?columnId=date_created&direction=DESC"); - await expect(page.getByTestId("filter-tag")).toContainText( - totalNumOfConditions, - ); - - await page.getByLabel("Filter by reportable condition").click(); - // Add delay since conditions rerenders shortly after opening - await page.getByText("Deselect all").click({ delay: 200 }); - await page.getByRole("group").getByText("Anthrax (disorder)").click(); - await page.getByLabel("Apply Filter").click(); - - //Click into the first eCR - await page.locator("table tr:first-child td:first-child a").click(); - //Return to the eCR Library - await page.getByText("Back to eCR Library").click({ delay: 200 }); - - await expect(page.getByText("Showing 1-16")).toBeVisible(); - expect((await page.locator("tbody > tr").allTextContents()).length).toEqual( - 16, - ); - }); - test("Search should filter results ", async ({ page }) => { await page.goto("/ecr-viewer"); await page.waitForURL("/ecr-viewer?columnId=date_created&direction=DESC");