From 0f44d7e6633eface10c278b8680cc9cb57400bdf Mon Sep 17 00:00:00 2001 From: Alberto Chamorro Date: Mon, 13 Feb 2023 08:00:35 +0100 Subject: [PATCH] fix: getWeeksInMonth with properly weekStartsOn option --- .../ActivitiesCalendar/ActivitiesCalendar.tsx | 3 +-- src/shared/utils/chrono.test.ts | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/modules/binnacle/page/BinnacleDesktop/ActivitiesCalendar/ActivitiesCalendar.tsx b/src/modules/binnacle/page/BinnacleDesktop/ActivitiesCalendar/ActivitiesCalendar.tsx index fe1a9ac8a..ef9e934f4 100644 --- a/src/modules/binnacle/page/BinnacleDesktop/ActivitiesCalendar/ActivitiesCalendar.tsx +++ b/src/modules/binnacle/page/BinnacleDesktop/ActivitiesCalendar/ActivitiesCalendar.tsx @@ -7,11 +7,10 @@ import CalendarHeader from 'modules/binnacle/page/BinnacleDesktop/ActivitiesCale import { useCalendarKeysNavigation } from 'modules/binnacle/page/BinnacleDesktop/ActivitiesCalendar/useCalendarKeyboardNavigation' import { forwardRef, Fragment, useState } from 'react' import { useGlobalState } from 'shared/arch/hooks/use-global-state' -import { isSaturday, isSunday } from 'shared/utils/chrono' +import { getWeeksInMonth, isSaturday, isSunday } from 'shared/utils/chrono' import { CellHeader } from './CalendarCell/CellHeader/CellHeader' import { CellBody } from 'modules/binnacle/page/BinnacleDesktop/ActivitiesCalendar/CalendarCell/CellBody/CellBody' import type { ActivitiesPerDay } from 'modules/binnacle/data-access/interfaces/activities-per-day.interface' -import { getWeeksInMonth } from 'date-fns' export const ActivitiesCalendar = observer(() => { const { activities, holidays, selectedDate } = useGlobalState(BinnacleState) diff --git a/src/shared/utils/chrono.test.ts b/src/shared/utils/chrono.test.ts index de934239c..bad0a5543 100644 --- a/src/shared/utils/chrono.test.ts +++ b/src/shared/utils/chrono.test.ts @@ -1,4 +1,4 @@ -import chrono, { parseISO, getHumanizedDuration } from 'shared/utils/chrono' +import chrono, { parseISO, getHumanizedDuration, getWeeksInMonth } from 'shared/utils/chrono' describe('Chrono', () => { it('should format relative as expected', function () { @@ -105,4 +105,19 @@ describe('Chrono', () => { expect(humanDuration).toBe(result) } ) + + test.each` + selectedDate | result + ${'2023-01-01'} | ${6} + ${'2023-02-01'} | ${5} + ${'2023-03-01'} | ${5} + ${'2023-04-01'} | ${5} + ${'2023-05-01'} | ${5} + ${'2023-07-01'} | ${6} + ${'2023-12-01'} | ${5} + `('should get $result weeks for $selectedDate', function ({ selectedDate, result }) { + const weeksInMonth = getWeeksInMonth(parseISO(selectedDate)) + + expect(weeksInMonth).toBe(result) + }) })