109 lines
3.1 KiB
TypeScript
109 lines
3.1 KiB
TypeScript
import "@testing-library/jest-dom";
|
|
import { render } from "@testing-library/react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { buildHrHubVM, type HrHubHrefs } from "@hivegrid/view-models";
|
|
|
|
import { HrHubPage } from "./HrHubPage";
|
|
|
|
vi.mock("react-i18next", () => ({
|
|
useTranslation: () => ({
|
|
t: (key: string, values?: { count?: number }) =>
|
|
values?.count === undefined ? key : `${key}:${values.count}`,
|
|
}),
|
|
}));
|
|
|
|
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;
|
|
|
|
function vm(capabilities = {
|
|
canReadAll: false,
|
|
canWrite: false,
|
|
canApproveLeave: false,
|
|
canViewSurveyResults: false,
|
|
}) {
|
|
return buildHrHubVM({
|
|
moduleActive: true,
|
|
hrefs,
|
|
counts: {
|
|
ownLeave: 1,
|
|
ownSick: 0,
|
|
ownRequests: 1,
|
|
pendingLeaveApprovals: 0,
|
|
pendingRequestApprovals: 0,
|
|
visibleTeamMembers: 0,
|
|
},
|
|
capabilities,
|
|
});
|
|
}
|
|
|
|
describe("HrHubPage interim UI", () => {
|
|
it("renders priority and employee sections from the VM without admin leakage", () => {
|
|
const { container } = render(<HrHubPage vm={vm()} />);
|
|
|
|
expect(container.querySelector('[data-ui-id="ui.hr.hub.priority"]')).toBeInTheDocument();
|
|
expect(container.querySelector('[data-ui-id="ui.hr.hub.section.forMe"]')).toBeInTheDocument();
|
|
expect(container.querySelector('[data-ui-id="ui.hr.hub.section.myTeam"]')).not.toBeInTheDocument();
|
|
expect(container.querySelector('[data-ui-id="ui.hr.hub.section.administration"]')).not.toBeInTheDocument();
|
|
expect(container.querySelector('[data-ui-id="ui.hr.hub.item.sick"]')).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders the administration section only when the VM contains it", () => {
|
|
const { container } = render(
|
|
<HrHubPage
|
|
vm={vm({
|
|
canReadAll: true,
|
|
canWrite: true,
|
|
canApproveLeave: true,
|
|
canViewSurveyResults: true,
|
|
})}
|
|
/>,
|
|
);
|
|
|
|
expect(container.querySelector('[data-ui-id="ui.hr.hub.section.administration"]')).toBeInTheDocument();
|
|
expect(container.querySelector('[data-ui-id="ui.hr.hub.item.payslipAdmin"]')).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders a clear locked state for a disabled module", () => {
|
|
const locked = buildHrHubVM({
|
|
moduleActive: false,
|
|
hrefs,
|
|
counts: {
|
|
ownLeave: 0,
|
|
ownSick: 0,
|
|
ownRequests: 0,
|
|
pendingLeaveApprovals: 0,
|
|
pendingRequestApprovals: 0,
|
|
visibleTeamMembers: 0,
|
|
},
|
|
capabilities: {
|
|
canReadAll: false,
|
|
canWrite: false,
|
|
canApproveLeave: false,
|
|
canViewSurveyResults: false,
|
|
},
|
|
});
|
|
const { container } = render(<HrHubPage vm={locked} />);
|
|
|
|
expect(container.querySelector('[data-ui-id="ui.hr.hub.locked"]')).toBeInTheDocument();
|
|
});
|
|
});
|