131 lines
3.9 KiB
TypeScript
131 lines
3.9 KiB
TypeScript
// @vitest-environment jsdom
|
|
import "@testing-library/jest-dom/vitest";
|
|
import { render } from "@testing-library/react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { buildHrHubVM, type HrHubHrefs } from "@hivegrid/view-models";
|
|
import { HrAdminPayslipsPage } from "./HrAdminPayslipsPage";
|
|
import { HrHubPage } from "./HrHubPage";
|
|
|
|
vi.mock("react-i18next", () => ({
|
|
useTranslation: () => ({
|
|
t: (key: string, values?: Record<string, unknown>) =>
|
|
values ? `${key}:${Object.values(values).join("/")}` : key,
|
|
i18n: { language: "de" },
|
|
}),
|
|
}));
|
|
|
|
const hubIds = [
|
|
"leave",
|
|
"sick",
|
|
"documents",
|
|
"payslips",
|
|
"announcements",
|
|
"requests",
|
|
"surveys",
|
|
"teamDirectory",
|
|
"teamLeave",
|
|
"leaveApprovals",
|
|
"requestApprovals",
|
|
"directory",
|
|
"locations",
|
|
"announcementAdmin",
|
|
"payslipAdmin",
|
|
"requestTemplates",
|
|
"uploadReminders",
|
|
"surveyAdmin",
|
|
] as const;
|
|
const hrefs = Object.fromEntries(
|
|
hubIds.map((id) => [id, `/acme/hr/${id}`]),
|
|
) as HrHubHrefs;
|
|
|
|
function hubVm(admin: boolean) {
|
|
return buildHrHubVM({
|
|
moduleActive: true,
|
|
hrefs,
|
|
counts: {
|
|
ownLeave: 1,
|
|
ownSick: 0,
|
|
ownRequests: 2,
|
|
pendingLeaveApprovals: admin ? 3 : 0,
|
|
pendingRequestApprovals: admin ? 1 : 0,
|
|
visibleTeamMembers: admin ? 8 : 0,
|
|
},
|
|
capabilities: {
|
|
canReadAll: admin,
|
|
canWrite: admin,
|
|
canApproveLeave: admin,
|
|
canViewSurveyResults: admin,
|
|
},
|
|
});
|
|
}
|
|
|
|
function stableMarkup(markup: string): string {
|
|
return markup.replace(
|
|
/<svg\b[^>]*>[\s\S]*?<\/svg>/gu,
|
|
'<svg data-visual-icon="true"></svg>',
|
|
);
|
|
}
|
|
|
|
describe("R-UX3 personnel interim visual baseline", () => {
|
|
it("captures employee and HR task hubs for desktop/mobile breakpoints", () => {
|
|
const { container } = render(
|
|
<main data-ui-id="ui.hr.personnel.visualBaseline">
|
|
<HrHubPage vm={hubVm(false)} />
|
|
<HrHubPage vm={hubVm(true)} />
|
|
</main>,
|
|
);
|
|
|
|
expect(container.querySelector("[data-ui-id='ui.hr.hub.section.forMe']")).toBeInTheDocument();
|
|
expect(container.querySelector("[data-ui-id='ui.hr.hub.section.myTeam']")).toBeInTheDocument();
|
|
expect(container.querySelector("[data-ui-id='ui.hr.hub.section.administration']")).toBeInTheDocument();
|
|
expect(container.textContent).not.toContain("password");
|
|
expect(stableMarkup(container.innerHTML)).toMatchSnapshot();
|
|
});
|
|
|
|
it("captures named payslip upload, matching, loading, empty and error states", () => {
|
|
const { container } = render(
|
|
<HrAdminPayslipsPage
|
|
rows={[
|
|
{
|
|
id: "payslip-1",
|
|
employeeLabel: "Mira Muster",
|
|
periodLabel: "2026-07",
|
|
isRead: false,
|
|
},
|
|
]}
|
|
preview={[
|
|
{
|
|
fileId: "opaque-file-id",
|
|
fileName: "2026-07-Mira-Muster.pdf",
|
|
confidence: "hard",
|
|
confidenceKey: "hr.payslips.match.confidence.hard",
|
|
confidenceTone: "success",
|
|
employeeUserId: "opaque-user-id",
|
|
employeeLabel: "Mira Muster",
|
|
},
|
|
]}
|
|
memberOptions={[
|
|
{
|
|
userId: "opaque-user-id",
|
|
displayName: "Mira Muster",
|
|
team: "Montage",
|
|
roleNames: ["Mitarbeitende"],
|
|
},
|
|
]}
|
|
period={{ year: "2026", month: "7" }}
|
|
submitting
|
|
errorKey="hr.payslips.upload.rejected"
|
|
feedbackKey="hr.payslips.upload.checked"
|
|
actions={{ onMatch: vi.fn(), onConfirm: vi.fn() }}
|
|
/>,
|
|
);
|
|
|
|
expect(container.querySelector("[data-ui-id='ui.hr.admin.payslips.files']")).toHaveAttribute("multiple");
|
|
expect(container.querySelector("[data-ui-id='ui.hr.admin.payslips.error']")).toBeInTheDocument();
|
|
expect(container.textContent).toContain("Mira Muster");
|
|
expect(container.textContent).not.toContain("opaque-user-id");
|
|
expect(container.textContent).not.toContain("opaque-file-id");
|
|
expect(stableMarkup(container.innerHTML)).toMatchSnapshot();
|
|
});
|
|
});
|