Files

43 lines
1.4 KiB
TypeScript

// AK-P16b interim-UI (AD-28) — BookingPagesPage unit test. The "Neue
// Booking-Seite" CTA links to the standalone editor route; it is hidden without
// the admin permission. i18n is mocked so `t` echoes the key. Empty-rows fixture
// keeps the list free of row Links; the CTA Link needs a Router context.
import { render } from "@testing-library/react";
import "@testing-library/jest-dom/vitest";
import { MemoryRouter } from "react-router";
import { describe, expect, it, vi } from "vitest";
import { buildBookingPagesListVM } from "@hivegrid/view-models";
import { BookingPagesPage } from "./BookingPagesPage";
vi.mock("react-i18next", () => ({
useTranslation: () => ({ t: (s: string) => s, i18n: { language: "de" } }),
}));
function renderPage(canCreate = true) {
const vm = buildBookingPagesListVM({
rows: [],
canCreate,
newHref: "/acme/bookings/pages/new",
});
render(
<MemoryRouter>
<BookingPagesPage vm={vm} />
</MemoryRouter>,
);
}
describe("BookingPagesPage", () => {
it("links the create CTA to the standalone editor route", () => {
renderPage();
const cta = document.querySelector("[data-ui-id='ui.booking.pages.new']");
expect(cta).not.toBeNull();
expect(cta?.getAttribute("href")).toBe("/acme/bookings/pages/new");
});
it("hides the create CTA without the admin permission", () => {
renderPage(false);
expect(document.querySelector("[data-ui-id='ui.booking.pages.new']")).toBeNull();
});
});