Skip to content

Commit

Permalink
Add test for filter panel toggling on chip dismissal
Browse files Browse the repository at this point in the history
  • Loading branch information
jmuzina committed Sep 9, 2024
1 parent ffbb42b commit eb14124
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/components/SearchAndFilter/SearchAndFilter.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, screen, waitFor } from "@testing-library/react";
import { render, screen, waitFor, within } from "@testing-library/react";
import React from "react";

import SearchAndFilter from "./SearchAndFilter";
Expand Down Expand Up @@ -413,4 +413,40 @@ describe("Search and filter", () => {
});
expect(onExpandChange).toHaveBeenCalled();
});

it("does not toggle the panel when a filter is dismissed", async () => {
const returnSearchData = jest.fn();
const onExpandChange = jest.fn();
const onPanelToggle = jest.fn();
render(
<SearchAndFilter
filterPanelData={sampleData}
returnSearchData={returnSearchData}
onExpandChange={onExpandChange}
onPanelToggle={onPanelToggle}
existingSearchData={[
{ lead: "Cloud", value: "Google" },
{ lead: "Region", value: "eu-west-1" },
]}
/>,
);

// onPanelToggle is called on initial render, so we need to clear the mock before asserting
onPanelToggle.mockClear();

// Dismiss the Cloud: Google filter chip
await waitFor(async () => {
const cloudChip: HTMLElement = screen
.getByText("CLOUD")
.closest(".p-chip");

const dismissButton = within(cloudChip).getByRole("button", {
name: "Dismiss",
});

await userEvent.click(dismissButton);
});

expect(onPanelToggle).not.toHaveBeenCalled();
});
});

0 comments on commit eb14124

Please sign in to comment.