From 5d7e17b82f063281f1a0cc5252f559d9a1d29157 Mon Sep 17 00:00:00 2001 From: Florian Zia Date: Wed, 21 Feb 2024 13:29:22 +0100 Subject: [PATCH 1/3] fix: c8 coverage --- package.json | 2 +- src/app/(proper_react)/(redesign)/GaScript.tsx | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 3666a08c0a3..3c6a8a5509f 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "start": "next start", "lint": "stylelint '**/*.scss' && prettier --check './src' && next lint --max-warnings=0", "fix": "prettier --write './src' && next lint --fix && stylelint --fix '**/*.scss'", - "test": "jest", + "test": "jest --no-cache", "e2e": "playwright test src/e2e/", "e2e:debug": "playwright test src/e2e/ --ui", "e2e:smoke": "playwright test src/e2e/ --grep @smoke", diff --git a/src/app/(proper_react)/(redesign)/GaScript.tsx b/src/app/(proper_react)/(redesign)/GaScript.tsx index 83519fed893..a0fa2881874 100644 --- a/src/app/(proper_react)/(redesign)/GaScript.tsx +++ b/src/app/(proper_react)/(redesign)/GaScript.tsx @@ -21,6 +21,7 @@ export const GaScript = ({ nonce }: Props) => { nonce={nonce} /> ) : ( + /* c8 ignore next */ <> ); }; From 94fc9f19ea4abab9c880bd15d3c081c465bf491f Mon Sep 17 00:00:00 2001 From: Florian Zia Date: Wed, 21 Feb 2024 14:55:39 +0100 Subject: [PATCH 2/3] chore: Add unit test for non-required ComboBox --- .../(dashboard)/dashboard/Dashboard.test.tsx | 166 ++++++++++++++++++ .../dashboard/filterExposures.test.ts | 7 - src/app/components/client/ComboBox.test.tsx | 8 + 3 files changed, 174 insertions(+), 7 deletions(-) diff --git a/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/dashboard/Dashboard.test.tsx b/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/dashboard/Dashboard.test.tsx index 4e5e2700a35..015bdcc4802 100644 --- a/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/dashboard/Dashboard.test.tsx +++ b/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/dashboard/Dashboard.test.tsx @@ -4,6 +4,7 @@ import { it, expect } from "@jest/globals"; import { + getByLabelText, getByRole, getByText, queryByRole, @@ -2644,6 +2645,171 @@ it("allows Plus-eligible users to filter by exposure type", async () => { expect(exposureTypeRadioGroup).toBeInTheDocument(); }); +it("allows Plus users to filter by info for sale", async () => { + const user = userEvent.setup(); + const ComposedDashboard = composeStory( + DashboardUsPremiumUnresolvedScanUnresolvedBreaches, + Meta, + ); + render(); + + expect( + screen.queryAllByText("Data breach", { + selector: "dd", + }).length, + ).toBeGreaterThan(0); + expect( + screen.queryAllByText("Info for sale", { + selector: "dd", + }).length, + ).toBeGreaterThan(0); + + const filterMenuButton = screen.getByRole("button", { + name: "Select filters", + }); + await user.click(filterMenuButton); + + const filterDialog = screen.getByRole("dialog"); + const exposureTypeInput = getByLabelText(filterDialog, "Your info for sale"); + await user.click(exposureTypeInput); + + const showResultsButton = getByRole(filterDialog, "button", { + name: "Show results", + }); + await user.click(showResultsButton); + + expect( + screen.queryAllByText("Data breach", { + selector: "dd", + }).length, + ).toBe(0); + expect( + screen.queryAllByText("Info for sale", { + selector: "dd", + }).length, + ).toBeGreaterThan(0); +}); + +it("allows Plus users to filter by data breach", async () => { + const user = userEvent.setup(); + const ComposedDashboard = composeStory( + DashboardUsPremiumUnresolvedScanUnresolvedBreaches, + Meta, + ); + render(); + + expect( + screen.queryAllByText("Data breach", { + selector: "dd", + }).length, + ).toBeGreaterThan(0); + expect( + screen.queryAllByText("Info for sale", { + selector: "dd", + }).length, + ).toBeGreaterThan(0); + + const filterMenuButton = screen.getByRole("button", { + name: "Select filters", + }); + await user.click(filterMenuButton); + + const filterDialog = screen.getByRole("dialog"); + const exposureTypeInput = getByLabelText(filterDialog, "Data breach"); + await user.click(exposureTypeInput); + + const showResultsButton = getByRole(filterDialog, "button", { + name: "Show results", + }); + await user.click(showResultsButton); + + expect( + screen.queryAllByText("Data breach", { + selector: "dd", + }).length, + ).toBeGreaterThan(0); + expect( + screen.queryAllByText("Info for sale", { + selector: "dd", + }).length, + ).toBe(0); +}); + +it("allows users to filter for results in the last 7 days", async () => { + const user = userEvent.setup(); + const ComposedDashboard = composeStory( + DashboardUsPremiumUnresolvedScanUnresolvedBreaches, + Meta, + ); + render(); + + const filterMenuButton = screen.getByRole("button", { + name: "Select filters", + }); + await user.click(filterMenuButton); + + const filterDialog = screen.getByRole("dialog"); + const exposureTypeInput = getByLabelText(filterDialog, "Last 7 days"); + await user.click(exposureTypeInput); + + const showResultsButton = getByRole(filterDialog, "button", { + name: "Show results", + }); + await user.click(showResultsButton); + + expect(showResultsButton).not.toBeInTheDocument(); +}); + +it("allows users to filter for results in the last 30 days", async () => { + const user = userEvent.setup(); + const ComposedDashboard = composeStory( + DashboardUsPremiumUnresolvedScanUnresolvedBreaches, + Meta, + ); + render(); + + const filterMenuButton = screen.getByRole("button", { + name: "Select filters", + }); + await user.click(filterMenuButton); + + const filterDialog = screen.getByRole("dialog"); + const exposureTypeInput = getByLabelText(filterDialog, "Last 30 days"); + await user.click(exposureTypeInput); + + const showResultsButton = getByRole(filterDialog, "button", { + name: "Show results", + }); + await user.click(showResultsButton); + + expect(showResultsButton).not.toBeInTheDocument(); +}); + +it("allows users to filter for results in the last year", async () => { + const user = userEvent.setup(); + const ComposedDashboard = composeStory( + DashboardUsPremiumUnresolvedScanUnresolvedBreaches, + Meta, + ); + render(); + + const filterMenuButton = screen.getByRole("button", { + name: "Select filters", + }); + await user.click(filterMenuButton); + + const filterDialog = screen.getByRole("dialog"); + const exposureTypeInput = getByLabelText(filterDialog, "Last year"); + await user.click(exposureTypeInput); + + const showResultsButton = getByRole(filterDialog, "button", { + name: "Show results", + }); + await user.click(showResultsButton); + + expect(showResultsButton).not.toBeInTheDocument(); +}); + it("send Telemetry when users click on free scans when all exposures are fixed", async () => { const user = userEvent.setup(); const ComposedDashboard = composeStory( diff --git a/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/dashboard/filterExposures.test.ts b/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/dashboard/filterExposures.test.ts index 9ae50030e28..2878ef1813b 100644 --- a/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/dashboard/filterExposures.test.ts +++ b/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/dashboard/filterExposures.test.ts @@ -63,7 +63,6 @@ it("doesn't filter out anything by default", () => { filterExposures(exposures, { dateFound: "show-all-date-found", exposureType: "show-all-exposure-type", - status: "show-all-status", }), ).toStrictEqual(exposures); }); @@ -84,7 +83,6 @@ it("can filter out breaches", () => { filterExposures(exposures, { dateFound: "show-all-date-found", exposureType: "data-broker", - status: "show-all-status", }), ).toStrictEqual([ scanResultThisWeek, @@ -110,7 +108,6 @@ it("can filter out data brokers", () => { filterExposures(exposures, { dateFound: "show-all-date-found", exposureType: "data-breach", - status: "show-all-status", }), ).toStrictEqual([breachThisWeek, breachThisMonth, breachThisYear, breachOld]); }); @@ -131,7 +128,6 @@ it("can filter out exposures older than a year", () => { filterExposures(exposures, { dateFound: "last-year", exposureType: "show-all-exposure-type", - status: "show-all-status", }), ).toStrictEqual([ breachThisWeek, @@ -159,7 +155,6 @@ it("can filter out exposures older than a month", () => { filterExposures(exposures, { dateFound: "thirty-days", exposureType: "show-all-exposure-type", - status: "show-all-status", }), ).toStrictEqual([ breachThisWeek, @@ -185,7 +180,6 @@ it("can filter out exposures older than a week", () => { filterExposures(exposures, { dateFound: "seven-days", exposureType: "show-all-exposure-type", - status: "show-all-status", }), ).toStrictEqual([breachThisWeek, scanResultThisWeek]); }); @@ -206,7 +200,6 @@ it("filters out anything that doesn't match *all* filters", () => { filterExposures(exposures, { dateFound: "last-year", exposureType: "data-breach", - status: "show-all-status", }), ).toStrictEqual([breachThisWeek, breachThisMonth, breachThisYear]); }); diff --git a/src/app/components/client/ComboBox.test.tsx b/src/app/components/client/ComboBox.test.tsx index a2dd4f50ddf..4506e5cc6f7 100644 --- a/src/app/components/client/ComboBox.test.tsx +++ b/src/app/components/client/ComboBox.test.tsx @@ -56,3 +56,11 @@ it("shows error messages", () => { const errorMessage = screen.getByText("Input invalid"); expect(errorMessage).toBeInTheDocument(); }); + +it("shows combobox as not required", () => { + const ComposedTextComboBox = composeStory(TextComboBoxEmpty, Meta); + render(); + + const comboBoxLabel = screen.getByLabelText("ComboBox label"); + expect(comboBoxLabel).toBeInTheDocument(); +}); From 434a19079fd34837f8b895cb8cc64d98f99f61ef Mon Sep 17 00:00:00 2001 From: Florian Zia Date: Wed, 21 Feb 2024 15:28:55 +0100 Subject: [PATCH 3/3] chore: Remove jest --no-cache --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3c6a8a5509f..3666a08c0a3 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "start": "next start", "lint": "stylelint '**/*.scss' && prettier --check './src' && next lint --max-warnings=0", "fix": "prettier --write './src' && next lint --fix && stylelint --fix '**/*.scss'", - "test": "jest --no-cache", + "test": "jest", "e2e": "playwright test src/e2e/", "e2e:debug": "playwright test src/e2e/ --ui", "e2e:smoke": "playwright test src/e2e/ --grep @smoke",