diff --git a/src/components/Chip/Chip.test.tsx b/src/components/Chip/Chip.test.tsx index bdec3450..889cf39d 100644 --- a/src/components/Chip/Chip.test.tsx +++ b/src/components/Chip/Chip.test.tsx @@ -41,7 +41,7 @@ describe("Chip ", () => { ); expect( within(screen.getByTestId("chip")).getByRole("button", { - name: Label.Dismiss, + name: `${Label.Dismiss} Bob`, }), ).toBeInTheDocument(); }); @@ -59,7 +59,7 @@ describe("Chip ", () => { const dismissButton = within(screen.getByTestId("chip")).getByRole( "button", { - name: Label.Dismiss, + name: `${Label.Dismiss} Bob`, }, ); await userEvent.click(dismissButton); @@ -209,7 +209,7 @@ describe("Chip ", () => { const dismissButton = within(screen.getByTestId("chip")).getByRole( "button", { - name: Label.Dismiss, + name: `${Label.Dismiss} Bob`, }, ); await userEvent.click(dismissButton); diff --git a/src/components/Chip/Chip.tsx b/src/components/Chip/Chip.tsx index 491dca5a..c28395aa 100644 --- a/src/components/Chip/Chip.tsx +++ b/src/components/Chip/Chip.tsx @@ -150,8 +150,15 @@ const Chip = ({ return ( {chipContent} - ); diff --git a/src/components/SearchAndFilter/FilterPanelSection/FilterPanelSection.test.tsx b/src/components/SearchAndFilter/FilterPanelSection/FilterPanelSection.test.tsx index 499f9a88..f1346321 100644 --- a/src/components/SearchAndFilter/FilterPanelSection/FilterPanelSection.test.tsx +++ b/src/components/SearchAndFilter/FilterPanelSection/FilterPanelSection.test.tsx @@ -10,6 +10,11 @@ const sampleData = { chips: [{ value: "us-east1" }, { value: "us-east2" }, { value: "us-east3" }], }; +const manyChipsData = { + ...sampleData, + chips: Array.from({ length: 30 }, (_, i) => ({ value: `us-east${i + 1}` })), +}; + describe("Filter panel section", () => { it("renders", () => { render( @@ -100,25 +105,45 @@ describe("Filter panel section", () => { }); it("all chips are shown when counter is clicked", async () => { + // Jest is unaware of layout so we must mock the offsetTop and offsetHeight + // of the chips to force the overflow counter to show. + Object.defineProperty(HTMLElement.prototype, "offsetHeight", { + configurable: true, + value: 40, + }); + Object.defineProperty(HTMLElement.prototype, "offsetTop", { + configurable: true, + value: 100, + }); render( , ); + + const counter = document.querySelector( + ".p-filter-panel-section__counter", + ) as HTMLElement; + expect(counter).toBeInTheDocument(); + + await userEvent.click(counter); + expect( - document.querySelector(".p-filter-panel-section__chips"), - ).toHaveAttribute("aria-expanded", "false"); - await userEvent.click( - // Use a query selector because the element's text is split up over - // multiple elements so it can't be selected by its content. - document.querySelector(".p-filter-panel-section__counter") as HTMLElement, - ); + document.querySelector(".p-filter-panel-section__counter"), + ).not.toBeInTheDocument(); + expect( - document.querySelector(".p-filter-panel-section__chips"), - ).toHaveAttribute("aria-expanded", "true"); + screen.getByRole("button", { name: "us-east1" }), + ).toBeInTheDocument(); + expect( + screen.getByRole("button", { name: "us-east15" }), + ).toBeInTheDocument(); + expect( + screen.getByRole("button", { name: "us-east30" }), + ).toBeInTheDocument(); }); }); diff --git a/src/components/SearchAndFilter/FilterPanelSection/FilterPanelSection.tsx b/src/components/SearchAndFilter/FilterPanelSection/FilterPanelSection.tsx index 3eb94dbb..3f485351 100644 --- a/src/components/SearchAndFilter/FilterPanelSection/FilterPanelSection.tsx +++ b/src/components/SearchAndFilter/FilterPanelSection/FilterPanelSection.tsx @@ -104,11 +104,7 @@ const FilterPanelSection = ({ }} /> )} -
+
{chips?.map((chip) => { // If search term has been added to input, only matching chips // should display diff --git a/src/components/SearchAndFilter/FilterPanelSection/__snapshots__/FilterPanelSection.test.tsx.snap b/src/components/SearchAndFilter/FilterPanelSection/__snapshots__/FilterPanelSection.test.tsx.snap index fde52b93..0630b7d0 100644 --- a/src/components/SearchAndFilter/FilterPanelSection/__snapshots__/FilterPanelSection.test.tsx.snap +++ b/src/components/SearchAndFilter/FilterPanelSection/__snapshots__/FilterPanelSection.test.tsx.snap @@ -10,7 +10,6 @@ exports[`Filter panel section renders 1`] = ` Regions