Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WickyNilliams committed Mar 25, 2024
1 parent 6263c69 commit 5e8f04e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ jobs:
node-version: "20.x"
- run: npm ci
- run: npm run build
- run: npx playwright install chrome webkit --with-deps
- run: npx playwright install --with-deps
- run: npm test
5 changes: 3 additions & 2 deletions src/calendar-date/calendar-date.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
click,
clickDay,
createSpy,
getActiveElement,
getDayButton,
getMonth,
getNextPageButton,
Expand Down Expand Up @@ -236,7 +237,7 @@ describe("CalendarDate", () => {
await sendKeys({ press: "Tab" });
await sendKeys({ press: "Enter" });

expect(getNextPageButton(calendar)).to.match(":focus-within");
expect(getActiveElement()).to.eq(getNextPageButton(calendar));
});

it("moves focus to the selected date when clicking outside of the month", async () => {
Expand All @@ -257,7 +258,7 @@ describe("CalendarDate", () => {

// get the clicked day
const button = getDayButton(month, "1 February");
expect(button).to.match(":focus-within");
expect(getActiveElement()).to.eq(button);
expect(button.tabIndex).to.eq(0);
});
});
Expand Down
12 changes: 12 additions & 0 deletions src/utils/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,15 @@ export async function clickDay(month: MonthInstance, dateLabel: string) {

await click(button);
}

export function getActiveElement(root: Document | ShadowRoot = document) {
if (
root.activeElement &&
"shadowRoot" in root.activeElement &&
root.activeElement.shadowRoot
) {
return getActiveElement(root.activeElement.shadowRoot);
}

return root.activeElement;
}

0 comments on commit 5e8f04e

Please sign in to comment.