forked from gpbl/react-day-picker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRangeResetSelection.test.tsx
More file actions
41 lines (35 loc) · 1.56 KB
/
RangeResetSelection.test.tsx
File metadata and controls
41 lines (35 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { screen } from "@testing-library/react";
import { addDays } from "date-fns";
import React from "react";
import { dateButton } from "@/test/elements";
import { render } from "@/test/render";
import { user } from "@/test/user";
import { RangeResetSelection } from "./RangeResetSelection";
const today = new Date(2022, 8, 12);
beforeAll(() => jest.setSystemTime(today));
afterAll(() => jest.useRealTimers());
beforeEach(() => render(<RangeResetSelection />));
const getFrom = () => screen.getByTestId("from");
const getTo = () => screen.getByTestId("to");
test("select same day range", async () => {
await user.click(dateButton(today));
expect(getFrom()).toHaveTextContent("from: 2022-09-12");
expect(getTo()).toHaveTextContent("to:");
await user.click(dateButton(today));
expect(getFrom()).toHaveTextContent("from: 2022-09-12");
expect(getTo()).toHaveTextContent("to: 2022-09-12");
});
test("start range after click on day with range selected", async () => {
await user.click(dateButton(today));
expect(getFrom()).toHaveTextContent("from: 2022-09-12");
expect(getTo()).toHaveTextContent("to:");
await user.click(dateButton(addDays(today, 1)));
expect(getFrom()).toHaveTextContent("from: 2022-09-12");
expect(getTo()).toHaveTextContent("to: 2022-09-13");
await user.click(dateButton(addDays(today, 4)));
expect(getFrom()).toHaveTextContent("from: 2022-09-16");
expect(getTo()).toHaveTextContent("to:");
await user.click(dateButton(today));
expect(getFrom()).toHaveTextContent("from: 2022-09-12");
expect(getTo()).toHaveTextContent("to: 2022-09-16");
});