From 575016e3e71e2d1a4f8dab64226c3447da1510f9 Mon Sep 17 00:00:00 2001 From: WickyNilliams Date: Fri, 26 Apr 2024 15:45:01 +0100 Subject: [PATCH] add tests for all parts --- src/calendar-month/calendar-month.test.tsx | 37 +++++++++++++--------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/calendar-month/calendar-month.test.tsx b/src/calendar-month/calendar-month.test.tsx index d9afa28..0d1b77f 100644 --- a/src/calendar-month/calendar-month.test.tsx +++ b/src/calendar-month/calendar-month.test.tsx @@ -19,7 +19,7 @@ import { import { CalendarMonth } from "../calendar-month/calendar-month.js"; import { fixture } from "atomico/test-dom"; import { PlainDate } from "../utils/temporal.js"; -import { today } from "../utils/date.js"; +import { toDate, today } from "../utils/date.js"; type MonthContextInstance = InstanceType; @@ -105,9 +105,18 @@ describe("CalendarMonth", () => { const selected = getSelectedDays(month); expect(selected.length).to.eq(3); + expect(selected[0]).to.have.attribute("aria-label", "1 January"); + expect(selected[0]!.part.contains("selected")).to.eq(true); + expect(selected[0]!.part.contains("range-start")); + expect(selected[1]).to.have.attribute("aria-label", "2 January"); + expect(selected[1]!.part.contains("selected")).to.eq(true); + expect(selected[1]!.part.contains("range-inner")); + expect(selected[2]).to.have.attribute("aria-label", "3 January"); + expect(selected[2]!.part.contains("selected")).to.eq(true); + expect(selected[2]!.part.contains("range-end")); }); }); @@ -132,6 +141,7 @@ describe("CalendarMonth", () => { const selected = getSelectedDays(month); expect(selected.length).to.eq(1); expect(selected[0]).to.have.attribute("aria-label", "1 January"); + expect(selected[0]!.part.contains("selected")).to.eq(true); }); }); }); @@ -146,21 +156,17 @@ describe("CalendarMonth", () => { expect(title).not.to.eq(undefined); }); - it("marks selected day as pressed", async () => { - const month = await mount( - - ); - const grid = getGrid(month); + it("marks today", async () => { + const month = await mount(); - // should be single selected element - const selected = getSelectedDays(month); + const todaysDate = toDate(today()).toLocaleDateString("en-GB", { + day: "numeric", + month: "long", + }); + const button = getDayButton(month, todaysDate)!; - expect(selected.length).to.eq(1); - expect(selected[0]).to.have.trimmed.text("2"); - expect(selected[0]).to.have.attribute("aria-label", "2 January"); + expect(button.part.contains("today")).to.eq(true); + expect(button).to.have.attribute("aria-current", "date"); }); it("uses a roving tab index", async () => { @@ -198,7 +204,7 @@ describe("CalendarMonth", () => { expect(spy.last[0].detail.toString()).to.eq("2020-04-19"); }); - it("cannot select a disabled date", async () => { + it("cannot select a disallowed date", async () => { const spy = createSpy<(e: CustomEvent) => void>(); const calendar = await mount( { const day = getDayButton(calendar, "4 January")!; expect(day.part.contains("disallowed")).to.eq(true); + expect(day).to.have.attribute("aria-disabled", "true"); await click(day); expect(spy.called).to.eq(false);