35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
import { describe, it, expect, vi } from "vitest";
|
|
import { render } from "@testing-library/react";
|
|
import React from "react";
|
|
import DateCell from "./DateCell";
|
|
|
|
vi.mock("react-i18next", () => ({
|
|
useTranslation: () => ({
|
|
i18n: { language: "en" },
|
|
}),
|
|
}));
|
|
|
|
describe("DateCell", () => {
|
|
it("renders date with default displays", () => {
|
|
const date = new Date(Date.now() - 60 * 60 * 1000);
|
|
const { container } = render(<DateCell date={date} />);
|
|
expect(container.querySelector("div")).not.toBeNull();
|
|
expect(container.querySelector("div")?.getAttribute("title")).toBeTruthy();
|
|
expect(container.textContent).toMatch(/ago|vor/i);
|
|
});
|
|
|
|
it("renders date with specific displays", () => {
|
|
const date = new Date(Date.now() - 60 * 60 * 1000);
|
|
const { container } = render(<DateCell date={date} displays={["dm", "ago"]} />);
|
|
expect(container.querySelector("div")).not.toBeNull();
|
|
expect(container.querySelector("div")?.getAttribute("title")).toBeTruthy();
|
|
expect(container.textContent).toMatch(/ago|vor/i);
|
|
expect(container.textContent).not.toContain("ymd");
|
|
});
|
|
|
|
it("renders empty when date is null", () => {
|
|
const { container } = render(<DateCell date={null} />);
|
|
expect(container.querySelector("div")).toBeNull();
|
|
});
|
|
});
|