Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/prettier-3.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gpbl authored Jun 22, 2024
2 parents 007b737 + a6c0198 commit 678af32
Show file tree
Hide file tree
Showing 63 changed files with 240 additions and 1,118 deletions.
13 changes: 4 additions & 9 deletions examples/Controlled.test.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import React from "react";

import { grid } from "@/test/elements";
import { act, render, screen } from "@/test/render";
import { render, screen } from "@/test/render";
import { user } from "@/test/user";

import { Controlled } from "./Controlled";

beforeAll(() => {
jest.setSystemTime(new Date(2022, 5, 10));
});

afterAll(() => {
jest.useRealTimers();
});
beforeAll(() => jest.setSystemTime(new Date(2022, 5, 10)));
afterAll(() => jest.useRealTimers());

describe('when the "Today" button is clicked', () => {
const todayButton = () => screen.getByRole("button", { name: "Go to Today" });
beforeEach(async () => {
render(<Controlled />);
await act(() => user.click(todayButton()));
await user.click(todayButton());
});
test("the button should be disabled", async () => {
expect(todayButton()).toBeDisabled();
Expand Down
9 changes: 2 additions & 7 deletions examples/CustomDayDate.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ import { render, screen } from "@/test/render";

import { CustomDayDate } from "./CustomDayDate";

beforeAll(() => {
jest.setSystemTime(new Date(2021, 10, 25));
});

afterAll(() => {
jest.useRealTimers();
});
beforeAll(() => jest.setSystemTime(new Date(2021, 10, 25)));
afterAll(() => jest.useRealTimers());

beforeEach(() => {
render(<CustomDayDate />);
Expand Down
9 changes: 2 additions & 7 deletions examples/CustomMultiple.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ import { CustomMultiple } from "./CustomMultiple";

const today = new Date(2021, 10, 25);

beforeAll(() => {
jest.setSystemTime(today);
});

afterAll(() => {
jest.useRealTimers();
});
beforeAll(() => jest.setSystemTime(today));
afterAll(() => jest.useRealTimers());

beforeEach(() => {
render(<CustomMultiple />);
Expand Down
15 changes: 5 additions & 10 deletions examples/CustomSingle.test.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
import React from "react";

import { gridcell } from "@/test/elements";
import { act, render, screen } from "@/test/render";
import { render, screen } from "@/test/render";
import { user } from "@/test/user";

import { CustomSingle } from "./CustomSingle";

const today = new Date(2021, 10, 25);

beforeAll(() => {
jest.setSystemTime(today);
});

afterAll(() => {
jest.useRealTimers();
});
beforeAll(() => jest.setSystemTime(today));
afterAll(() => jest.useRealTimers());

beforeEach(() => {
render(<CustomSingle />);
});

describe("when a day is clicked", () => {
beforeEach(async () => {
await act(() => user.click(gridcell(today)));
await user.click(gridcell(today));
});
test("should appear as selected", () => {
expect(gridcell(today)).toHaveAttribute("aria-selected", "true");
Expand All @@ -34,7 +29,7 @@ describe("when a day is clicked", () => {
});
describe("when clicking the day again", () => {
beforeEach(async () => {
await act(() => user.click(gridcell(today)));
await user.click(gridcell(today));
});
test("should not appear as selected", () => {
expect(gridcell(today)).not.toHaveAttribute("aria-selected", "true");
Expand Down
9 changes: 2 additions & 7 deletions examples/CustomWeek.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ import { CustomWeek } from "./CustomWeek";

const today = new Date(2021, 10, 25);

beforeAll(() => {
jest.setSystemTime(today);
});

afterAll(() => {
jest.useRealTimers();
});
beforeAll(() => jest.setSystemTime(today));
afterAll(() => jest.useRealTimers());

beforeEach(() => {
render(<CustomWeek />);
Expand Down
9 changes: 2 additions & 7 deletions examples/DefaultMonth.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ import { DefaultMonth } from "./DefaultMonth";

const today = new Date(2022, 5, 10);

beforeAll(() => {
jest.setSystemTime(today);
});

afterAll(() => {
jest.useRealTimers();
});
beforeAll(() => jest.setSystemTime(today));
afterAll(() => jest.useRealTimers());

test("should display September 1979", () => {
render(<DefaultMonth />);
Expand Down
15 changes: 5 additions & 10 deletions examples/Disabled.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@ import { Disabled } from "./Disabled";
const today = new Date(2022, 5, 10);
const firstOfMonth = new Date(2022, 5, 1);

beforeAll(() => {
jest.setSystemTime(today);
});

afterAll(() => {
jest.useRealTimers();
});
beforeAll(() => jest.setSystemTime(today));
afterAll(() => jest.useRealTimers());

beforeEach(async () => {
beforeEach(() => {
render(
<div role="application">
<Disabled />
Expand All @@ -35,7 +30,7 @@ test("should not display the previous button", () => {
describe("when the first day is focused", () => {
describe("when the Arrow Left is pressed", () => {
beforeEach(async () => {
await act(() => user.type(app(), "{arrowleft}"));
await user.type(app(), "{arrowleft}");
});
test("should still display the same month", () => {
expect(grid("June 2022")).toBeInTheDocument();
Expand All @@ -45,7 +40,7 @@ describe("when the first day is focused", () => {
describe("when the last day is focused", () => {
describe("when the Arrow Right is pressed", () => {
beforeEach(async () => {
await act(() => user.type(app(), "{arrowleft}"));
await user.type(app(), "{arrowleft}");
});
test("should still display the same month", () => {
expect(grid("June 2022")).toBeInTheDocument();
Expand Down
9 changes: 2 additions & 7 deletions examples/Dropdown.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ import { Dropdown } from "./Dropdown";

const today = new Date(2015, 6, 1);

beforeAll(() => {
jest.setSystemTime(today);
});

afterAll(() => {
jest.useRealTimers();
});
beforeAll(() => jest.setSystemTime(today));
afterAll(() => jest.useRealTimers());

beforeEach(() => {
render(<Dropdown />);
Expand Down
9 changes: 2 additions & 7 deletions examples/DropdownMultipleMonths.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ import { DropdownMultipleMonths } from "./DropdownMultipleMonths";

const today = new Date(2023, 9, 16);

beforeAll(() => {
jest.setSystemTime(today);
});

afterAll(() => {
jest.useRealTimers();
});
beforeAll(() => jest.setSystemTime(today));
afterAll(() => jest.useRealTimers());

beforeEach(() => {
render(<DropdownMultipleMonths />);
Expand Down
9 changes: 2 additions & 7 deletions examples/FixedWeeks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@ import { FixedWeeks } from "./Fixedweeks";

const today = new Date(2021, 10, 25);

beforeAll(() => {
jest.setSystemTime(today);
});

afterAll(() => {
jest.useRealTimers();
});
beforeAll(() => jest.setSystemTime(today));
afterAll(() => jest.useRealTimers());

beforeEach(() => {
render(<FixedWeeks />);
Expand Down
25 changes: 10 additions & 15 deletions examples/FocusRecursive.test.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
import React from "react";

import { activeElement, gridcell } from "@/test/elements";
import { act, render } from "@/test/render";
import { render } from "@/test/render";
import { user } from "@/test/user";

import { FocusRecursive } from "./FocusRecursive";

const today = new Date(2022, 5, 10);

beforeAll(() => {
jest.setSystemTime(today);
});

afterAll(() => {
jest.useRealTimers();
});
beforeAll(() => jest.setSystemTime(today));
afterAll(() => jest.useRealTimers());

test("the first selected day should have focus", async () => {
render(<FocusRecursive />).container;
await act(() => user.tab());
await act(() => user.tab());
await act(() => user.tab());
await act(() => user.type(activeElement(), "{arrowdown}"));
await act(() => user.type(activeElement(), "{arrowdown}"));
await act(() => user.type(activeElement(), "{arrowdown}"));
await act(() => user.type(activeElement(), "{arrowdown}"));
await user.tab();
await user.tab();
await user.tab();
await user.type(activeElement(), "{arrowdown}");
await user.type(activeElement(), "{arrowdown}");
await user.type(activeElement(), "{arrowdown}");
await user.type(activeElement(), "{arrowdown}");
expect(gridcell(new Date(2022, 5, 22))).toHaveFocus();
});
9 changes: 2 additions & 7 deletions examples/Formatters.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@ import { Formatters } from "./Formatters";

const today = new Date(2021, 10, 25);

beforeAll(() => {
jest.setSystemTime(today);
});

afterAll(() => {
jest.useRealTimers();
});
beforeAll(() => jest.setSystemTime(today));
afterAll(() => jest.useRealTimers());

beforeEach(() => {
render(<Formatters />);
Expand Down
4 changes: 2 additions & 2 deletions examples/FromToMonth.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from "react";
import { differenceInMonths } from "date-fns";

import { nextButton, previousButton } from "@/test/elements";
import { act, render } from "@/test/render";
import { render } from "@/test/render";
import { user } from "@/test/user";

import { FromToMonth } from "./FromToMonth";
Expand All @@ -26,7 +26,7 @@ describe("when navigating to the last month", () => {
const nOfMonths = differenceInMonths(toDate, fromDate);
beforeEach(async () => {
for (let i = 0; i < nOfMonths; i++) {
await act(() => user.click(nextButton()));
await user.click(nextButton());
}
});

Expand Down
13 changes: 4 additions & 9 deletions examples/FromToYear.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from "react";
import { differenceInMonths } from "date-fns";

import { nextButton, previousButton } from "@/test/elements";
import { act, render } from "@/test/render";
import { render } from "@/test/render";
import { user } from "@/test/user";

import { FromToYear } from "./FromToYear";
Expand All @@ -12,13 +12,8 @@ const fromMonth = new Date(2024, 0);
const toMonth = new Date(2026, 11);
const today = new Date(2025, 10, 25);

beforeAll(() => {
jest.setSystemTime(today);
});

afterAll(() => {
jest.useRealTimers();
});
beforeAll(() => jest.setSystemTime(today));
afterAll(() => jest.useRealTimers());

beforeEach(() => {
render(<FromToYear />);
Expand All @@ -35,7 +30,7 @@ describe("when navigating to the last month", () => {
const nOfMonths = differenceInMonths(toMonth, fromMonth);
beforeEach(async () => {
for (let i = 0; i < nOfMonths; i++) {
await act(() => user.click(nextButton()));
await user.click(nextButton());
}
});
test("the previous month button should not be disabled", () => {
Expand Down
27 changes: 8 additions & 19 deletions examples/Jalali.test.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
import React from "react";

import { render, screen } from "@/test/render";
import { grid } from "@/test/elements";
import { render } from "@/test/render";

import { Jalali } from "./Jalali";

const today = new Date(2021, 10, 25);
const today = new Date(1403, 10, 25);

beforeAll(() => {
jest.setSystemTime(today);
});

afterAll(() => {
jest.useRealTimers();
});

beforeEach(() => {
render(
<div role="application">
<Jalali />
</div>
);
});
beforeAll(() => jest.setSystemTime(today));
afterAll(() => jest.useRealTimers());

test("should match the snapshot", () => {
expect(screen.getByRole("application")).toMatchSnapshot();
test("should render نوامبر 1403", () => {
render(<Jalali />);
expect(grid("نوامبر 1403")).toBeInTheDocument();
});
Loading

0 comments on commit 678af32

Please sign in to comment.