124 lines
3.8 KiB
TypeScript
124 lines
3.8 KiB
TypeScript
import { describe, it, expect, beforeEach } from "vitest";
|
|
import { render, screen } from "@testing-library/react";
|
|
import { MemoryRouter } from "react-router-dom";
|
|
import { Sidebar } from "@/components/layout/Sidebar";
|
|
import { ReportsPage } from "@/pages/ReportsPage";
|
|
import { DataTableDemoPage } from "@/pages/DataTableDemoPage";
|
|
import { useAuthStore } from "@/hooks/useAuth";
|
|
|
|
describe("Phase 1 Frontend Smoke Tests", () => {
|
|
beforeEach(() => {
|
|
useAuthStore.setState({
|
|
user: {
|
|
id: 1,
|
|
name: "Admin",
|
|
email: "admin@poona.demo",
|
|
role: "system_admin",
|
|
department_id: null,
|
|
department_name: null,
|
|
is_active: true,
|
|
},
|
|
token: "test-token",
|
|
demoAsOfDate: null,
|
|
hydrating: false,
|
|
});
|
|
});
|
|
|
|
it("renders Sidebar with Poona Hospital logo, subtitle, and all admin navigation links", () => {
|
|
render(
|
|
<MemoryRouter>
|
|
<Sidebar />
|
|
</MemoryRouter>
|
|
);
|
|
|
|
const logo = screen.getByAltText("Poona Hospital and Research Centre") as HTMLImageElement;
|
|
expect(logo).toBeInTheDocument();
|
|
expect(logo.getAttribute("src")).toBe("/logo.jpg");
|
|
expect(screen.getByText("Asset Management & Maintenance")).toBeInTheDocument();
|
|
|
|
const labels = [
|
|
"Dashboard",
|
|
"Assets",
|
|
"Complaints",
|
|
"Preventive Maintenance",
|
|
"Calibration",
|
|
"Contracts & Warranty",
|
|
"Insurance",
|
|
"Demo Equipment",
|
|
"Department Visits",
|
|
"Reports",
|
|
"Notifications",
|
|
"Masters",
|
|
"Audit Log",
|
|
"Settings",
|
|
];
|
|
for (const label of labels) {
|
|
expect(screen.getByText(label)).toBeInTheDocument();
|
|
}
|
|
expect(screen.getByText("Poona Hospital AMS • v1.0")).toBeInTheDocument();
|
|
});
|
|
|
|
it("hides Masters, Settings, and Department Visits for department_user and coordinator", () => {
|
|
useAuthStore.setState({
|
|
user: {
|
|
id: 3,
|
|
name: "Dept User",
|
|
email: "dept@poona.demo",
|
|
role: "department_user",
|
|
department_id: 1,
|
|
department_name: "ICU",
|
|
is_active: true,
|
|
},
|
|
});
|
|
const { rerender } = render(
|
|
<MemoryRouter>
|
|
<Sidebar />
|
|
</MemoryRouter>
|
|
);
|
|
expect(screen.queryByText("Masters")).not.toBeInTheDocument();
|
|
expect(screen.queryByText("Audit Log")).not.toBeInTheDocument();
|
|
expect(screen.queryByText("Settings")).not.toBeInTheDocument();
|
|
expect(screen.queryByText("Department Visits")).not.toBeInTheDocument();
|
|
expect(screen.getByText("Assets")).toBeInTheDocument();
|
|
|
|
useAuthStore.setState({
|
|
user: {
|
|
id: 5,
|
|
name: "Coordinator",
|
|
email: "coord@poona.demo",
|
|
role: "coordinator",
|
|
department_id: null,
|
|
department_name: null,
|
|
is_active: true,
|
|
},
|
|
});
|
|
rerender(
|
|
<MemoryRouter>
|
|
<Sidebar />
|
|
</MemoryRouter>
|
|
);
|
|
expect(screen.queryByText("Masters")).not.toBeInTheDocument();
|
|
expect(screen.queryByText("Audit Log")).not.toBeInTheDocument();
|
|
expect(screen.queryByText("Settings")).not.toBeInTheDocument();
|
|
expect(screen.queryByText("Department Visits")).not.toBeInTheDocument();
|
|
expect(screen.getByText("Contracts & Warranty")).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders ReportsPage catalog cards", () => {
|
|
render(
|
|
<MemoryRouter>
|
|
<ReportsPage />
|
|
</MemoryRouter>
|
|
);
|
|
expect(screen.getByText("Reports & Exports")).toBeInTheDocument();
|
|
expect(screen.getByText("Monthly Maintenance Summary")).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders DataTableDemoPage with mock rows", () => {
|
|
render(<DataTableDemoPage />);
|
|
expect(screen.getByText("Phase 0 — DataTable Demo")).toBeInTheDocument();
|
|
expect(screen.getByText("PHRC-ICU-0001")).toBeInTheDocument();
|
|
expect(screen.getByText("CT Scanner")).toBeInTheDocument();
|
|
});
|
|
});
|