Skip to content

Commit 4805576

Browse files
committed
Fix LineChartCard test
1 parent 7314506 commit 4805576

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

test/visits/charts/LineChartCard.test.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { fireEvent, screen } from '@testing-library/react';
22
import { fromPartial } from '@total-typescript/shoehorn';
3-
import { formatISO, isBefore, subDays, subMonths, subYears } from 'date-fns';
3+
import { formatISO, subDays, subMonths, subYears } from 'date-fns';
4+
import { isBeforeOrEqual } from '../../../src/utils/dates/helpers/date';
45
import type { StrictDateRange } from '../../../src/utils/dates/helpers/dateIntervals';
56
import { ChartDimensionsProvider } from '../../../src/visits/charts/ChartDimensionsContext';
67
import type { VisitsList } from '../../../src/visits/charts/LineChartCard';
@@ -120,8 +121,12 @@ describe('<LineChartCard />', () => {
120121
{ selectionStart: 100, selectionEnd: 300 },
121122
// Right to left
122123
{ selectionStart: 300, selectionEnd: 100 },
123-
])('allows date range to be selected via drag and drop', ({ selectionStart, selectionEnd }) => {
124-
const { chart } = setUpChartWithData();
124+
])('allows date range to be selected via drag and drop', async ({ selectionStart, selectionEnd }) => {
125+
const { chart, user } = setUpChartWithData();
126+
127+
// An initial click is needed for subsequent events to receive the proper state from recharts
128+
// See https://github.com/recharts/recharts/discussions/6178#discussioncomment-14029671
129+
await user.click(chart);
125130

126131
fireEvent.mouseDown(chart, { clientX: selectionStart, clientY: 200, button: 0 });
127132
fireEvent.mouseMove(chart, { clientX: selectionEnd, clientY: 200 });
@@ -131,7 +136,7 @@ describe('<LineChartCard />', () => {
131136

132137
// Regardless of the selection direction, the oldest date will always be used as start date
133138
const [{ startDate, endDate }] = onDateRangeChange.mock.lastCall as [StrictDateRange];
134-
expect(isBefore(startDate, endDate)).toBe(true);
139+
expect(isBeforeOrEqual(startDate, endDate)).toBe(true);
135140
});
136141

137142
it.each([

0 commit comments

Comments
 (0)