Skip to content

Commit

Permalink
refactor(test): corrected test for both true and false values of shou…
Browse files Browse the repository at this point in the history
…ldCloseOnScroll
  • Loading branch information
awesome-pro committed Aug 3, 2024
1 parent 10ba017 commit 277231a
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions packages/components/popover/__tests__/popover.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ describe("Popover", () => {
expect(popover).toHaveAttribute("aria-expanded", "true");
});

it("should close popover on scroll when shouldCloseOnScroll is true", async () => {
it("should close popover on scroll", async () => {
const wrapper = render(
<Popover shouldCloseOnScroll>
<Popover>
<PopoverTrigger>
<Button data-testid="popover">Open popover</Button>
</PopoverTrigger>
Expand Down Expand Up @@ -348,3 +348,36 @@ describe("Popover", () => {
expect(popover).toHaveAttribute("aria-expanded", "false");
});
});

it("should close popover on scroll when shouldCloseOnScroll is false", async () => {
const wrapper = render(
<Popover shouldCloseOnScroll={false}>
<PopoverTrigger>
<Button data-testid="popover">Open popover</Button>
</PopoverTrigger>
<PopoverContent>
<Select data-testid="select" label="Select country">
<SelectItem key="argentina">Argentina</SelectItem>
<SelectItem key="venezuela">Venezuela</SelectItem>
<SelectItem key="brazil">Brazil</SelectItem>
</Select>
</PopoverContent>
</Popover>,
);

const popover = wrapper.getByTestId("popover");

// open popover
await act(async () => {
await userEvent.click(popover);
});

// assert that the popover is open
expect(popover).toHaveAttribute("aria-expanded", "true");

// scroll it
fireEvent.scroll(document.body);

// assert that the popover is still open
expect(popover).toHaveAttribute("aria-expanded", "true");
});

0 comments on commit 277231a

Please sign in to comment.