mirror of
https://github.com/gethomepage/homepage.git
synced 2026-03-30 23:02:39 -07:00
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
// @vitest-environment jsdom
|
|
|
|
import { act, screen } from "@testing-library/react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import { renderWithProviders } from "test-utils/render-with-providers";
|
|
|
|
import DateTime from "./datetime";
|
|
|
|
describe("components/widgets/datetime", () => {
|
|
it("renders formatted date/time and updates on an interval", async () => {
|
|
vi.useFakeTimers();
|
|
try {
|
|
vi.setSystemTime(new Date("2020-01-01T00:00:00.000Z"));
|
|
|
|
const format = { timeZone: "UTC", hour: "2-digit", minute: "2-digit", second: "2-digit" };
|
|
const expected0 = new Intl.DateTimeFormat("en-US", format).format(new Date());
|
|
|
|
renderWithProviders(<DateTime options={{ locale: "en-US", format }} />, { settings: { target: "_self" } });
|
|
|
|
// `render` wraps in `act`, so effects should flush synchronously.
|
|
expect(screen.getByText(expected0)).toBeInTheDocument();
|
|
|
|
act(() => {
|
|
vi.advanceTimersByTime(1000);
|
|
});
|
|
const expected1 = new Intl.DateTimeFormat("en-US", format).format(new Date());
|
|
|
|
expect(screen.getByText(expected1)).toBeInTheDocument();
|
|
} finally {
|
|
vi.useRealTimers();
|
|
}
|
|
});
|
|
});
|