38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import "@testing-library/jest-dom";
|
|
import { fireEvent, render, screen } from "@testing-library/react";
|
|
import type { ComponentProps } from "react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import CookiesList from "./CookiesList";
|
|
|
|
vi.mock("react-router", () => ({
|
|
Link: ({ children, to, ...props }: ComponentProps<"a"> & { to: string }) => (
|
|
<a href={to} {...props}>
|
|
{children}
|
|
</a>
|
|
),
|
|
}));
|
|
|
|
vi.mock("react-i18next", () => ({
|
|
useTranslation: () => ({
|
|
t: (key: string, options?: { count?: number }) => (key === "cookies.count" ? `${options?.count} localized cookies` : key),
|
|
}),
|
|
}));
|
|
|
|
describe("CookiesList", () => {
|
|
it("renders cookie category counts through i18n", () => {
|
|
render(<CookiesList editing />);
|
|
|
|
expect(screen.getAllByText(/\(\d+ localized cookies\)/).length).toBeGreaterThan(0);
|
|
expect(screen.queryByText(/\(\d+ cookies\)/)).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("renders cookie expiry values through i18n", () => {
|
|
render(<CookiesList editing />);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: /cookies\.categories\.REQUIRED\.name/i }));
|
|
|
|
expect(screen.getByText("cookies.expiry.oneMonth")).toBeInTheDocument();
|
|
expect(screen.queryByText("1 month")).not.toBeInTheDocument();
|
|
});
|
|
});
|