From 170fdd36d1ecba9aef60d3f456c6915aeec013f8 Mon Sep 17 00:00:00 2001 From: Jordan Lawrence Date: Wed, 27 Nov 2024 15:08:22 +0000 Subject: [PATCH] fix: calendar filter tests using today's date --- .../__tests__/ReleasesOverview.test.tsx | 18 +++++++++++------- .../DateFilters/calendar/CalendarDay.tsx | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/sanity/src/core/releases/tool/overview/__tests__/ReleasesOverview.test.tsx b/packages/sanity/src/core/releases/tool/overview/__tests__/ReleasesOverview.test.tsx index fd621089114..55043d3cabe 100644 --- a/packages/sanity/src/core/releases/tool/overview/__tests__/ReleasesOverview.test.tsx +++ b/packages/sanity/src/core/releases/tool/overview/__tests__/ReleasesOverview.test.tsx @@ -270,13 +270,17 @@ describe('ReleasesOverview', () => { const getCalendar = () => getByDataUi(document.body, 'Calendar') it('has today in bold to signify that there is a release', () => { - const todayTile = within(getCalendar()).getByText(TODAY.getDate()) - expect(todayTile.parentNode).toHaveStyle('font-weight: 700') + const todayTile = within(getByDataUi(document.body, 'Calendar')).getByTestId( + 'day-tile-today', + ) + expect(todayTile.firstChild).toHaveStyle('font-weight: 700') }) describe('selecting a release date', () => { beforeEach(() => { - const todayTile = within(getCalendar()).getByText(TODAY.getDate()) + const todayTile = within(getByDataUi(document.body, 'Calendar')).getByTestId( + 'day-tile-today', + ) fireEvent.click(todayTile) }) @@ -354,15 +358,15 @@ describe('ReleasesOverview', () => { }) it('shows today as having no releases', () => { - const todayTile = within(getByDataUi(document.body, 'Calendar')).getByText( - TODAY.getDate(), + const todayTile = within(getByDataUi(document.body, 'Calendar')).getByTestId( + 'day-tile-today', ) expect(todayTile.parentNode).not.toHaveStyle('font-weight: 700') }) it('shows no releases when filtered by today', () => { - const todayTile = within(getByDataUi(document.body, 'Calendar')).getByText( - TODAY.getDate(), + const todayTile = within(getByDataUi(document.body, 'Calendar')).getByTestId( + 'day-tile-today', ) fireEvent.click(todayTile) diff --git a/packages/sanity/src/ui-components/inputs/DateFilters/calendar/CalendarDay.tsx b/packages/sanity/src/ui-components/inputs/DateFilters/calendar/CalendarDay.tsx index a8c9bfd8a34..7d5e820b0a7 100644 --- a/packages/sanity/src/ui-components/inputs/DateFilters/calendar/CalendarDay.tsx +++ b/packages/sanity/src/ui-components/inputs/DateFilters/calendar/CalendarDay.tsx @@ -53,6 +53,7 @@ export function CalendarDay(props: CalendarDayProps) { __unstable_focusRing data-weekday data-focused={focused ? 'true' : ''} + data-testid={isToday ? 'day-tile-today' : `day-tile-${date.getDate()}-${date.getMonth()}`} role="button" tabIndex={-1} onClick={handleClick}