Skip to content

Commit

Permalink
chore: Add unit test for non-required ComboBox
Browse files Browse the repository at this point in the history
  • Loading branch information
flozia authored and Vinnl committed Feb 21, 2024
1 parent d147b85 commit f1d51a3
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import { it, expect } from "@jest/globals";
import {
getByLabelText,
getByRole,
getByText,
queryByRole,
Expand Down Expand Up @@ -2813,6 +2814,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(
DashboardUsNoPremiumUnresolvedScanUnresolvedBreaches,
Meta,
);
render(<ComposedDashboard />);

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(
DashboardUsNoPremiumUnresolvedScanUnresolvedBreaches,
Meta,
);
render(<ComposedDashboard />);

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(<ComposedDashboard />);

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(<ComposedDashboard />);

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(<ComposedDashboard />);

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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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,
Expand All @@ -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]);
});
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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]);
});
Expand All @@ -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]);
});
8 changes: 8 additions & 0 deletions src/app/components/client/ComboBox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<ComposedTextComboBox />);

const comboBoxLabel = screen.getByLabelText("ComboBox label");
expect(comboBoxLabel).toBeInTheDocument();
});

0 comments on commit f1d51a3

Please sign in to comment.