Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/routes/[_]dev.customer-portal-preview.settings.test.tsx
T

80 lines
4.1 KiB
TypeScript

// @vitest-environment jsdom
import "@testing-library/jest-dom/vitest";
import { fireEvent, render, screen, within } from "@testing-library/react";
import { MemoryRouter } from "react-router";
import { beforeAll, describe, expect, it, vi } from "vitest";
import CustomerPortalSettingsPreviewRoute from "./[_]dev.customer-portal-preview.settings";
vi.mock("react-i18next", () => ({
useTranslation: () => ({
t: (key: string, values?: Record<string, unknown>) => (values ? `${key}:${Object.values(values).join("/")}` : key),
}),
}));
beforeAll(() => {
Object.defineProperty(window, "matchMedia", {
configurable: true,
value: vi.fn((query: string) => ({
matches: false,
media: query,
onchange: null,
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
addListener: vi.fn(),
removeListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});
});
describe("local customer portal preview", () => {
it("follows the reduced portal flow from overview into project work and settings", () => {
render(
<MemoryRouter initialEntries={["/_dev/customer-portal-preview/settings"]}>
<CustomerPortalSettingsPreviewRoute />
</MemoryRouter>
);
// Without a tenant logo the portal shows the tenant's own name, not our brand.
expect(screen.queryByRole("img", { name: "HiveGrid" })).not.toBeInTheDocument();
const sidebar = document.querySelector('[data-ui-id="ui.customerPortal.sidebar"]') as HTMLElement;
expect(within(sidebar).getByText("Demo Pro CRM Kundenportal")).toBeVisible();
expect(document.querySelector('[data-ui-id="ui.customerPortal.sidebar.settings"]')).toHaveClass("mt-auto");
expect(screen.getByRole("heading", { name: "customerPortal.lifecycle.title" })).toBeVisible();
expect(screen.queryByRole("button", { name: "customerPortal.navigation.upload" })).not.toBeInTheDocument();
expect(screen.getByRole("tab", { name: "customerPortal.lifecycle.tabs.account" })).toHaveAttribute("aria-selected", "true");
expect(screen.queryByText("customerPortal.lifecycle.deletion.title")).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("tab", { name: "customerPortal.lifecycle.tabs.privacy" }));
expect(screen.getByText("customerPortal.lifecycle.deletion.title")).toBeVisible();
fireEvent.click(screen.getByRole("button", { name: "customerPortal.navigation.dashboard" }));
expect(screen.getByRole("heading", { name: "customerPortal.dashboard.title" })).toBeVisible();
fireEvent.click(screen.getByRole("button", { name: "customerPortal.navigation.projects" }));
expect(screen.getByRole("heading", { name: "customerPortal.projects.title" })).toBeVisible();
fireEvent.click(screen.getByRole("button", { name: "customerPortal.projects.open" }));
expect(screen.getByRole("heading", { name: previewProjectName })).toBeVisible();
expect(screen.getByRole("button", { name: "customerPortal.projects.back" })).toHaveClass("self-start");
expect(screen.getByRole("tablist", { name: "customerPortal.projects.tabs.label" })).toHaveClass("self-start");
expect(screen.getByRole("tab", { name: "customerPortal.projects.tabs.overview" })).toHaveAttribute("aria-selected", "true");
expect(screen.getByRole("progressbar", { name: "customerPortal.projects.progressValue:67" })).toHaveClass("w-full", "gap-0");
expect(screen.queryByText("customerPortal.complaint.description")).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("tab", { name: "customerPortal.projects.tabs.files" }));
expect(screen.getByText("Montagefreigabe.pdf")).toBeVisible();
expect(screen.getByText("customerPortal.upload.title")).toBeVisible();
fireEvent.click(screen.getByRole("tab", { name: "customerPortal.projects.tabs.requests" }));
expect(screen.getByText("customerPortal.complaint.description")).toBeVisible();
fireEvent.click(screen.getByRole("button", { name: "customerPortal.navigation.settings" }));
expect(screen.getByRole("heading", { name: "customerPortal.lifecycle.title" })).toBeVisible();
});
});
const previewProjectName = "Modernisierung Heizungsanlage";