129 lines
4.9 KiB
TypeScript
129 lines
4.9 KiB
TypeScript
import "@testing-library/jest-dom";
|
|
import { fireEvent, render, screen } from "@testing-library/react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { buildHrHubVM, buildHrRequestTemplateListVM, type HrHubHrefs } from "@hivegrid/view-models";
|
|
import { expectNoAxeViolations, runAxe } from "@hivegrid/ui-app/test-setup/axe";
|
|
import { HrAdminPayslipsPage } from "./HrAdminPayslipsPage";
|
|
import { HrAdminRequestTemplatesPage } from "./HrAdminRequestTemplatesPage";
|
|
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 ids = [
|
|
"leave", "sick", "documents", "payslips", "announcements", "requests",
|
|
"surveys", "teamDirectory", "teamLeave", "leaveApprovals", "requestApprovals",
|
|
"directory", "locations", "announcementAdmin", "payslipAdmin",
|
|
"requestTemplates", "uploadReminders", "surveyAdmin",
|
|
] as const;
|
|
const hrefs = Object.fromEntries(ids.map((id) => [id, `/acme/hr/${id}`])) as HrHubHrefs;
|
|
const hubVm = buildHrHubVM({
|
|
moduleActive: true,
|
|
hrefs,
|
|
counts: {
|
|
ownLeave: 1,
|
|
ownSick: 0,
|
|
ownRequests: 1,
|
|
pendingLeaveApprovals: 2,
|
|
pendingRequestApprovals: 1,
|
|
visibleTeamMembers: 6,
|
|
},
|
|
capabilities: {
|
|
canReadAll: true,
|
|
canWrite: true,
|
|
canApproveLeave: true,
|
|
canViewSurveyResults: true,
|
|
},
|
|
});
|
|
|
|
describe("R-UX3 personnel accessibility and ID freedom", () => {
|
|
it("exposes the role-aware hub as labelled sections without critical axe violations", async () => {
|
|
const { container } = render(<HrHubPage vm={hubVm} />);
|
|
expect(screen.getByRole("heading", { name: "hr.hub.section.forMe.label" })).toBeInTheDocument();
|
|
expect(screen.getByRole("heading", { name: "hr.hub.section.myTeam.label" })).toBeInTheDocument();
|
|
expect(screen.getByRole("heading", { name: "hr.hub.section.administration.label" })).toBeInTheDocument();
|
|
expect((await runAxe(container)).violations).toEqual([]);
|
|
});
|
|
|
|
it("keeps payslip file and employee ids out of visible controls", async () => {
|
|
const { container } = render(
|
|
<HrAdminPayslipsPage
|
|
rows={[]}
|
|
preview={[{
|
|
fileId: "opaque-file-id",
|
|
fileName: "Mira-Muster-2026-07.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={false}
|
|
errorKey={null}
|
|
feedbackKey="hr.payslips.upload.checked"
|
|
actions={{ onMatch: vi.fn(), onConfirm: vi.fn() }}
|
|
/>,
|
|
);
|
|
const fileInput = screen.getByLabelText("hr.payslips.field.filesHint");
|
|
expect(fileInput).toHaveAttribute("accept", "application/pdf,.pdf");
|
|
fireEvent.change(fileInput, {
|
|
target: {
|
|
files: [
|
|
new File(["%PDF-1.7"], "mira.pdf", { type: "application/pdf" }),
|
|
new File(["%PDF-1.7"], "jo.pdf", { type: "application/pdf" }),
|
|
],
|
|
},
|
|
});
|
|
expect(screen.getByText("hr.payslips.upload.selected:2")).toBeInTheDocument();
|
|
expect(screen.getByRole("combobox", { name: "hr.payslips.field.employee" })).toBeInTheDocument();
|
|
expect(container.textContent).toContain("Mira Muster");
|
|
expect(container.textContent).not.toContain("opaque-user-id");
|
|
expect(container.textContent).not.toContain("opaque-file-id");
|
|
await expectNoAxeViolations(
|
|
<HrAdminPayslipsPage
|
|
rows={[]}
|
|
preview={[]}
|
|
memberOptions={[]}
|
|
period={{ year: "", month: "" }}
|
|
submitting={false}
|
|
errorKey={null}
|
|
feedbackKey={null}
|
|
actions={{ onMatch: vi.fn(), onConfirm: vi.fn() }}
|
|
/>,
|
|
);
|
|
});
|
|
|
|
it("uses named team context in the request-template approver picker", () => {
|
|
const { container } = render(
|
|
<HrAdminRequestTemplatesPage
|
|
vm={buildHrRequestTemplateListVM({ rows: [], createHref: "/acme/hr/admin/request-templates" })}
|
|
kinds={["expense"]}
|
|
memberOptions={[{
|
|
userId: "opaque-approver-id",
|
|
displayName: "Mira Muster",
|
|
team: "Montage",
|
|
roleNames: ["Teamleitung"],
|
|
}]}
|
|
submitting={false}
|
|
actions={{ onCreate: vi.fn(), onToggle: vi.fn(), onArchive: vi.fn() }}
|
|
/>,
|
|
);
|
|
fireEvent.click(screen.getByRole("button", { name: "hr.requests.templates.action.create" }));
|
|
fireEvent.click(screen.getByRole("combobox", { name: "hr.requests.field.approver" }));
|
|
expect(screen.getByText("Mira Muster · Montage · Teamleitung")).toBeInTheDocument();
|
|
expect(container.textContent).not.toContain("opaque-approver-id");
|
|
});
|
|
});
|