Skip to content

Commit

Permalink
updating Overlay tests to account for header changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhazledine committed Sep 19, 2024
1 parent cccf4b9 commit ba95ab9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
11 changes: 7 additions & 4 deletions packages/core/src/__tests__/__e2e__/overlay/Overlay.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ describe("GIVEN an Overlay", () => {
cy.realPress("Enter");
cy.findByRole("dialog").should("be.visible");
//focus into overlay
cy.findByRole("button", { name: /Close Overlay/i }).should("be.focused");
cy.findAllByRole("button", { name: "Close overlay" }).should(
"be.focused",
);
cy.realPress("Tab");
});

Expand All @@ -45,11 +47,11 @@ describe("GIVEN an Overlay", () => {

cy.findByRole("button", { name: /Show Overlay/i }).realClick();
cy.findByRole("dialog").should("be.visible");
cy.findByRole("button", { name: /Close Overlay/i }).should("be.focused");
cy.findByRole("button", { name: /Close overlay/i }).should("be.focused");
cy.realPress("Tab");
cy.findByRole("button", { name: /Hover me/i }).should("be.focused");
cy.realPress("Tab");
cy.findByRole("button", { name: /Close Overlay/i }).should("be.focused");
cy.findByRole("button", { name: /Close overlay/i }).should("be.focused");
});
});

Expand Down Expand Up @@ -119,7 +121,8 @@ describe("GIVEN an Overlay", () => {
cy.findByRole("dialog").should("be.visible");
cy.get("@onOpenChangeSpy").should("have.callCount", 1);

cy.findByRole("button", { name: /Close Overlay/i }).realClick();
cy.findByRole("button", { name: /Close overlay/i }).realClick();

cy.findByRole("dialog").should("not.exist");

cy.findByRole("button", { name: /Show Overlay/i }).realClick();
Expand Down
24 changes: 13 additions & 11 deletions packages/core/stories/overlay/overlay.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Right.args = {
};

export const Header = ({ onOpenChange }: OverlayProps) => {
const [open, setOpen] = useState(true);
const [open, setOpen] = useState(false);
const id = useId();

const onChange = (newOpen: boolean) => {
Expand Down Expand Up @@ -103,7 +103,7 @@ export const Header = ({ onOpenChange }: OverlayProps) => {
};

export const HeaderWithCloseButton = ({ onOpenChange }: OverlayProps) => {
const [open, setOpen] = useState(true);
const [open, setOpen] = useState(false);
const id = useId();

const onChange = (newOpen: boolean) => {
Expand All @@ -113,6 +113,16 @@ export const HeaderWithCloseButton = ({ onOpenChange }: OverlayProps) => {

const handleClose = () => setOpen(false);

const CloseButton = () => (
<Button
aria-label="Close overlay"
variant="secondary"
onClick={handleClose}
>
<CloseIcon aria-hidden />
</Button>
);

return (
<Overlay open={open} onOpenChange={onChange}>
<OverlayTrigger>
Expand All @@ -127,15 +137,7 @@ export const HeaderWithCloseButton = ({ onOpenChange }: OverlayProps) => {
<OverlayHeader
id={id}
header="Header block"
endAdornment={
<Button
aria-label="Close dialog"
variant="secondary"
onClick={handleClose}
>
<CloseIcon aria-hidden />
</Button>
}
endAdornment={<CloseButton />}
/>
<OverlayPanelContent>
<StackLayout gap={1}>
Expand Down

0 comments on commit ba95ab9

Please sign in to comment.