fix: lint, stubs, StatusBadge, uptime %, closure remarks UX

This commit is contained in:
Atharv1705
2026-11-12 17:32:14 +05:30
parent 22fad38280
commit 5027c0766e
24 changed files with 243 additions and 123 deletions
+11
View File
@@ -13,3 +13,14 @@ Items marked "to be confirmed" or left flexible in the proposal are recorded her
9. **Demo Clock (`demo_as_of_date`)**: System-wide `effective_today()` reads `demo_as_of_date` (`YYYY-MM-DD`) from Settings if non-empty; otherwise uses the real current date in `Asia/Kolkata`.
10. **Soft Deletion for Masters & Users**: Deleting departments, locations, categories, vendors, or users sets `is_active = False` rather than hard-deleting rows so historical asset/complaint/maintenance foreign keys remain intact.
11. **Password Hashing on Python 3.13**: `passlib==1.7.4` is incompatible with `bcrypt>=4.1` on Python 3.13 (`__about__` attribute removed / 72-byte wrap-check error), so `app/core/security.py` uses `bcrypt` (`bcrypt==5.0.0`) directly.
## Assumptions added post-Phase-8
12. **Permission Specifics**: `system_admin` and `biomedical` can create and edit full asset records (`coordinator` is restricted to updating `requires_calibration`, `insurance_applicable`, and `remarks`). Calibration frequency edits and plan approvals are restricted to `system_admin`, `management`, and `coordinator` (`biomedical` receives HTTP `403`). `department_user` is scoped to their assigned department (`ICU` in demo data) across assets, complaints, PM, calibration, contracts, notifications, dashboard, reports, and global search, whereas `system_admin`, `biomedical`, `management`, and `coordinator` view all departments hospital-wide. `management` and `coordinator` cannot raise complaints (enforced server-side with HTTP `403`).
13. **Critical Complaint Escalation & SLA Evaluation**: APScheduler runs `alerts.py` daily (default `06:00` in configured `TIMEZONE`) and raises `critical_complaint` notifications when open critical complaint age exceeds `escalation_open_complaint_hours` (default `24`h) or breaches `compute_sla_status` against `critical_complaint_sla_hours` (default `4`h) / `non_critical_complaint_sla_hours` (default `24`h).
14. **Insurance Drawer**: Insurance summary is surfaced via a read-only slide-over panel (`InsuranceDrawer`) from `AssetDetailPage`, `AssetPicker`, and `ComplaintDetailPage`; creating and editing policies is handled via modal dialogs on `/insurance` and the Asset Insurance tab.
15. **Demo-Only Features**: The TopBar **Demo Clock** (`demo_as_of_date`, admin-only date override for demonstrating expiry/overdue alerts and dynamic schedule transitions) and the deterministic seed loader (`python -m app.seed.seed`) exist specifically for demonstration and verification.
16. **Reopen Clears `restored_at`**: Reopening a closed breakdown complaint clears both `closed_at` and `restored_at` (`None`) on the complaint row so downtime resumes as ongoing until re-restored.
17. **Immediate Asset Return to Service**: When a breakdown complaint is restored or closed (and no other unrestored critical complaints exist on the asset), `Asset.status` transitions immediately to `in_service` rather than requiring an extra post-repair sign-off step.
18. **Code Prefixes (`complaint_no_prefix` & `asset_code_prefix`)**: Complaint numbers are auto-generated using `complaint_no_prefix` (default `CMP`, e.g. `CMP-2026-0001`; `BD-` or another prefix can be configured in Settings). Asset codes are entered manually to match physical hospital asset tags rather than auto-generated, so `asset_code_prefix` (default `PHRC`) acts as a configurable hospital label prefix shown in Settings and used for the bulk-import template sample code.
19. **Monthly Maintenance `Uptime %` Display**: The `monthly-maintenance` backend report aggregates uptime/downtime in minutes per department rather than returning per-asset `uptime_seconds`/`downtime_seconds`, so `Uptime %` (`uptime / (uptime + downtime) * 100`, 1 decimal place) is computed on the frontend in `ReportDetailPage.tsx` (falling back to `100 - downtime_pct`) and highlighted in the summary strip and table.
+9 -3
View File
@@ -83,8 +83,14 @@ export function AssetFormModal({
});
const departments = deptsQuery.data?.items ?? [];
const allLocations = locsQuery.data?.items ?? [];
const categories = catsQuery.data?.items ?? [];
const allLocations = useMemo(
() => locsQuery.data?.items ?? [],
[locsQuery.data?.items]
);
const categories = useMemo(
() => catsQuery.data?.items ?? [],
[catsQuery.data?.items]
);
const vendors = vendorsQuery.data?.items ?? [];
const defaultDeptId = editing?.department_id ?? departments[0]?.id ?? 0;
@@ -161,7 +167,7 @@ export function AssetFormModal({
remarks: "",
});
}
}, [open, editing, categories.length, defaultDeptId, defaultLocId, reset]);
}, [open, editing, categories, defaultDeptId, defaultLocId, reset]);
const watchedDeptId = Number(watch("department_id"));
const filteredLocations = useMemo(
+1 -18
View File
@@ -16,26 +16,9 @@ import {
} from "@/api/attachments";
import { ApiError } from "@/api/client";
import { formatDateTime } from "@/lib/format";
import { validateAttachmentFile } from "@/lib/validation";
import { Button } from "@/components/ui/button";
const MAX_SIZE_BYTES = 10 * 1024 * 1024; // 10 MB
const ALLOWED_EXTENSIONS = [".jpg", ".jpeg", ".png", ".pdf"];
const ALLOWED_MIME_TYPES = ["image/jpeg", "image/png", "application/pdf"];
export function validateAttachmentFile(file: File): string | null {
const nameLower = file.name.toLowerCase();
const hasAllowedExt = ALLOWED_EXTENSIONS.some((ext) => nameLower.endsWith(ext));
const hasAllowedMime = !file.type || ALLOWED_MIME_TYPES.includes(file.type);
if (!hasAllowedExt || !hasAllowedMime) {
return "Invalid file type. Only JPG, PNG, and PDF files are allowed.";
}
if (file.size > MAX_SIZE_BYTES) {
return "File is too large. Maximum allowed size is 10 MB.";
}
return null;
}
function formatBytes(bytes: number): string {
if (bytes < 1024) return `${bytes} B`;
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
@@ -12,7 +12,7 @@ import { assetsApi, type BulkImportResult } from "@/api/assets";
import { ApiError } from "@/api/client";
import { Modal } from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { toast } from "@/components/ToastProvider";
import { toast } from "@/lib/toast";
import { cn } from "@/lib/utils";
interface BulkAssetImportModalProps {
@@ -3,7 +3,7 @@ import { useQuery, useQueryClient } from "@tanstack/react-query";
import { AlertCircle, Paperclip, X } from "lucide-react";
import { Modal } from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { validateAttachmentFile } from "@/components/Attachments";
import { validateAttachmentFile } from "@/lib/validation";
import { ApiError } from "@/api/client";
import { assetsApi } from "@/api/assets";
import { vendorsApi } from "@/api/masters";
@@ -7,7 +7,7 @@ import { useAuthStore } from "@/hooks/useAuth";
import { formatDate } from "@/lib/format";
import { Modal } from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { toast } from "@/components/ToastProvider";
import { toast } from "@/lib/toast";
export function CalibrationReminderModal() {
const navigate = useNavigate();
@@ -8,7 +8,7 @@ import { AlertCircle, Clock, Paperclip, X } from "lucide-react";
import { Modal } from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { AssetPicker } from "@/components/AssetPicker";
import { validateAttachmentFile } from "@/components/Attachments";
import { validateAttachmentFile } from "@/lib/validation";
import { ApiError } from "@/api/client";
import { assetsApi, type AssetLookupItem, type AssetCriticality } from "@/api/assets";
import { complaintsApi, type ComplaintItem } from "@/api/complaints";
+1 -40
View File
@@ -1,44 +1,5 @@
import { create } from "zustand";
import { CheckCircle2, Info, AlertTriangle, AlertCircle, X } from "lucide-react";
export type ToastVariant = "success" | "info" | "warning" | "error";
export interface ToastEntry {
id: string;
title: string;
description?: string;
variant: ToastVariant;
}
interface ToastState {
toasts: ToastEntry[];
push: (t: Omit<ToastEntry, "id">) => void;
dismiss: (id: string) => void;
}
export const useToastStore = create<ToastState>((set) => ({
toasts: [],
push: (entry) => {
const id = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
set((s) => ({ toasts: [...s.toasts.slice(-4), { ...entry, id }] }));
setTimeout(() => {
set((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) }));
}, 5000);
},
dismiss: (id) =>
set((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) })),
}));
export const toast = {
success: (title: string, description?: string) =>
useToastStore.getState().push({ title, description, variant: "success" }),
info: (title: string, description?: string) =>
useToastStore.getState().push({ title, description, variant: "info" }),
warning: (title: string, description?: string) =>
useToastStore.getState().push({ title, description, variant: "warning" }),
error: (title: string, description?: string) =>
useToastStore.getState().push({ title, description, variant: "error" }),
};
import { useToastStore, type ToastVariant } from "@/lib/toast";
const VARIANT_CLS: Record<ToastVariant, string> = {
success: "bg-emerald-50 border-emerald-300 text-emerald-900",
+6 -3
View File
@@ -1,4 +1,4 @@
import { useState, useEffect, useRef } from "react";
import { useState, useEffect, useRef, useMemo } from "react";
import { useNavigate } from "react-router-dom";
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import {
@@ -28,7 +28,7 @@ import { notificationsApi, type NotificationItem } from "@/api/notifications";
import { searchApi } from "@/api/search";
import { Badge } from "@/components/ui/badge";
import { AssetStatusBadge, CallStatusBadge } from "@/components/StatusBadge";
import { toast } from "@/components/ToastProvider";
import { toast } from "@/lib/toast";
interface TopBarProps {
title?: string;
@@ -121,7 +121,10 @@ export function TopBar({ title, onMenuClick }: TopBarProps) {
refetchInterval: 60_000,
});
const bellItems = bellQuery.data?.items ?? [];
const bellItems = useMemo(
() => bellQuery.data?.items ?? [],
[bellQuery.data?.items]
);
const unreadCount = bellQuery.data?.unread_count ?? 0;
// Detect newly arrived unread notifications while app is open
+40
View File
@@ -0,0 +1,40 @@
import { create } from "zustand";
export type ToastVariant = "success" | "info" | "warning" | "error";
export interface ToastEntry {
id: string;
title: string;
description?: string;
variant: ToastVariant;
}
interface ToastState {
toasts: ToastEntry[];
push: (t: Omit<ToastEntry, "id">) => void;
dismiss: (id: string) => void;
}
export const useToastStore = create<ToastState>((set) => ({
toasts: [],
push: (entry) => {
const id = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
set((s) => ({ toasts: [...s.toasts.slice(-4), { ...entry, id }] }));
setTimeout(() => {
set((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) }));
}, 5000);
},
dismiss: (id) =>
set((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) })),
}));
export const toast = {
success: (title: string, description?: string) =>
useToastStore.getState().push({ title, description, variant: "success" }),
info: (title: string, description?: string) =>
useToastStore.getState().push({ title, description, variant: "info" }),
warning: (title: string, description?: string) =>
useToastStore.getState().push({ title, description, variant: "warning" }),
error: (title: string, description?: string) =>
useToastStore.getState().push({ title, description, variant: "error" }),
};
+17
View File
@@ -0,0 +1,17 @@
const MAX_SIZE_BYTES = 10 * 1024 * 1024; // 10 MB
const ALLOWED_EXTENSIONS = [".jpg", ".jpeg", ".png", ".pdf"];
const ALLOWED_MIME_TYPES = ["image/jpeg", "image/png", "application/pdf"];
export function validateAttachmentFile(file: File): string | null {
const nameLower = file.name.toLowerCase();
const hasAllowedExt = ALLOWED_EXTENSIONS.some((ext) => nameLower.endsWith(ext));
const hasAllowedMime = !file.type || ALLOWED_MIME_TYPES.includes(file.type);
if (!hasAllowedExt || !hasAllowedMime) {
return "Invalid file type. Only JPG, PNG, and PDF files are allowed.";
}
if (file.size > MAX_SIZE_BYTES) {
return "File is too large. Maximum allowed size is 10 MB.";
}
return null;
}
-1
View File
@@ -10,7 +10,6 @@ import {
Plus,
} from "lucide-react";
import { assetsApi } from "@/api/assets";
import type { CalibrationPlanItem } from "@/api/calibration";
import { ApiError } from "@/api/client";
import { useAuthStore } from "@/hooks/useAuth";
import { can } from "@/lib/permissions";
+58 -5
View File
@@ -22,6 +22,7 @@ import {
type TimestampField,
} from "@/api/complaints";
import { fetchUsersLookup } from "@/api/masters";
import { settingsApi } from "@/api/settings";
import { ApiError } from "@/api/client";
import { useAuthStore } from "@/hooks/useAuth";
import { can } from "@/lib/permissions";
@@ -90,6 +91,7 @@ export function ComplaintDetailPage() {
const [closeOpen, setCloseOpen] = useState(false);
const [closureRemarks, setClosureRemarks] = useState("");
const [closeError, setCloseError] = useState<string | null>(null);
const [reopenOpen, setReopenOpen] = useState(false);
const [reopenReason, setReopenReason] = useState("");
@@ -118,6 +120,21 @@ export function ComplaintDetailPage() {
enabled: Number.isFinite(complaintId) && complaintId > 0,
});
const settingsQuery = useQuery({
queryKey: ["settings"],
queryFn: () => settingsApi.getAll(),
enabled: isAdmin,
retry: false,
});
const requireClosureRemarks = (() => {
const setting = settingsQuery.data?.items?.find(
(s) => s.key === "require_closure_remarks"
);
if (setting !== undefined) return Boolean(setting.value);
return true;
})();
const eventsQuery = useQuery({
queryKey: ["complaint-events", complaintId],
queryFn: () => complaintsApi.events(complaintId),
@@ -193,11 +210,16 @@ export function ComplaintDetailPage() {
}),
onSuccess: async () => {
setActionError(null);
setCloseError(null);
setCloseOpen(false);
setClosureRemarks("");
await refreshAll();
},
onError: (err) => setActionError(err instanceof ApiError ? err.detail : "Close failed."),
onError: (err) => {
const msg = err instanceof ApiError ? err.detail : "Close failed.";
setCloseError(msg);
setActionError(msg);
},
});
const reopenMutation = useMutation({
@@ -541,7 +563,10 @@ export function ComplaintDetailPage() {
size="sm"
variant="outline"
className="border-green-600 text-green-700 hover:bg-green-50"
onClick={() => setCloseOpen(true)}
onClick={() => {
setCloseError(null);
setCloseOpen(true);
}}
>
<CheckCircle2 className="h-3.5 w-3.5 mr-1.5" />
Close Call
@@ -874,20 +899,48 @@ export function ComplaintDetailPage() {
</Modal>
{/* Close Modal */}
<Modal open={closeOpen} onOpenChange={setCloseOpen} title="Close Complaint Call">
<Modal
open={closeOpen}
onOpenChange={(next) => {
setCloseOpen(next);
if (!next) setCloseError(null);
}}
title="Close Complaint Call"
>
<form
onSubmit={(e) => {
e.preventDefault();
if (requireClosureRemarks && !closureRemarks.trim()) {
setCloseError("Closure remarks are required.");
return;
}
setCloseError(null);
closeMutation.mutate();
}}
className="space-y-4"
>
{closeError && (
<div
role="alert"
className="flex items-start gap-2 rounded-md bg-red-50 border border-red-200 px-3 py-2 text-xs text-red-700"
>
<AlertCircle className="h-4 w-4 shrink-0 mt-0.5" />
<span>{closeError}</span>
</div>
)}
<div>
<label className={labelCls}>Closure Remarks</label>
<label htmlFor="closure-remarks" className={labelCls}>
Closure Remarks {requireClosureRemarks && <span className="text-red-600">*</span>}
</label>
<textarea
id="closure-remarks"
rows={3}
required={requireClosureRemarks}
value={closureRemarks}
onChange={(e) => setClosureRemarks(e.target.value)}
onChange={(e) => {
setClosureRemarks(e.target.value);
if (closeError) setCloseError(null);
}}
placeholder="Summary of resolution and verification..."
className={inputCls}
/>
+1 -1
View File
@@ -32,7 +32,7 @@ import { ExpiryChip } from "@/components/StatusBadge";
import { AssetPicker } from "@/components/AssetPicker";
import { Attachments } from "@/components/Attachments";
import { ConfirmDialog } from "@/components/ConfirmDialog";
import { toast } from "@/components/ToastProvider";
import { toast } from "@/lib/toast";
type TabKey = "contracts" | "warranties";
+1 -1
View File
@@ -22,7 +22,7 @@ import { Modal } from "@/components/ui/dialog";
import { DemoStatusBadge } from "@/components/StatusBadge";
import { Attachments } from "@/components/Attachments";
import { ConfirmDialog } from "@/components/ConfirmDialog";
import { toast } from "@/components/ToastProvider";
import { toast } from "@/lib/toast";
type ViewTab = "active" | "returned" | "all";
+1 -1
View File
@@ -26,7 +26,7 @@ import { AssetPicker } from "@/components/AssetPicker";
import { Attachments } from "@/components/Attachments";
import { InsuranceDrawer } from "@/components/InsuranceDrawer";
import { ConfirmDialog } from "@/components/ConfirmDialog";
import { toast } from "@/components/ToastProvider";
import { toast } from "@/lib/toast";
const inputCls =
"w-full px-3 py-2 text-sm border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500";
+1 -1
View File
@@ -18,7 +18,7 @@ import {
import { formatDate, formatDateTime } from "@/lib/format";
import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
import { toast } from "@/components/ToastProvider";
import { toast } from "@/lib/toast";
const TYPE_OPTIONS: { value: NotificationType | ""; label: string }[] = [
{ value: "", label: "All Types" },
+69 -13
View File
@@ -36,7 +36,7 @@ import { useAuthStore } from "@/hooks/useAuth";
import { formatDateTime } from "@/lib/format";
import { DataTable } from "@/components/DataTable";
import { Button } from "@/components/ui/button";
import { toast } from "@/components/ToastProvider";
import { toast } from "@/lib/toast";
function currentMonthStr(): string {
const d = new Date();
@@ -94,6 +94,26 @@ function humanizeSummaryKey(key: string): string {
);
}
function computeUptimePct(record: Record<string, unknown>): string {
const upRaw = record.total_uptime_minutes ?? record.uptime_seconds;
const downRaw = record.total_downtime_minutes ?? record.downtime_seconds;
if (upRaw != null && downRaw != null) {
const up = Number(upRaw);
const down = Number(downRaw);
const total = up + down;
if (Number.isFinite(total) && total > 0) {
return `${((up / total) * 100).toFixed(1)} %`;
}
}
if (record.downtime_pct != null) {
const dtPct = Number(record.downtime_pct);
if (Number.isFinite(dtPct)) {
return `${Math.max(0, 100 - dtPct).toFixed(1)} %`;
}
}
return "—";
}
export function ReportDetailPage() {
const { reportKey } = useParams<{ reportKey: string }>();
const user = useAuthStore((s) => s.user);
@@ -215,18 +235,44 @@ export function ReportDetailPage() {
const columns: ColumnDef<Record<string, unknown>, unknown>[] = useMemo(() => {
if (!report) return [];
return report.columns.map((col) => ({
id: col.key,
accessorFn: (row) => row[col.key],
header: col.label,
cell: ({ getValue }) => {
const val = getValue();
if (val === null || val === undefined || val === "") return "—";
if (typeof val === "boolean") return val ? "Yes" : "No";
return String(val);
},
}));
}, [report]);
const baseCols: ColumnDef<Record<string, unknown>, unknown>[] = report.columns.map(
(col) => ({
id: col.key,
accessorFn: (row) => row[col.key],
header: col.label,
cell: ({ getValue }) => {
const val = getValue();
if (val === null || val === undefined || val === "") return "—";
if (typeof val === "boolean") return val ? "Yes" : "No";
return String(val);
},
})
);
if (
key === "monthly-maintenance" &&
!report.columns.some((c) => c.key === "uptime_pct")
) {
const uptimePctCol: ColumnDef<Record<string, unknown>, unknown> = {
id: "uptime_pct",
accessorFn: (row) => computeUptimePct(row),
header: "Uptime %",
cell: ({ getValue }) => (
<span className="font-semibold text-emerald-700 whitespace-nowrap">
{String(getValue() ?? "—")}
</span>
),
};
const dtPctIdx = baseCols.findIndex((c) => c.id === "downtime_pct");
if (dtPctIdx >= 0) {
baseCols.splice(dtPctIdx, 0, uptimePctCol);
} else {
baseCols.push(uptimePctCol);
}
}
return baseCols;
}, [report, key]);
async function handleExport(format: "xlsx" | "csv") {
if (!key) return;
@@ -701,6 +747,16 @@ export function ReportDetailPage() {
{/* Summary Strip */}
{report && (
<div className="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-2.5 print-break-inside-avoid">
{key === "monthly-maintenance" && (
<div className="bg-emerald-50 border border-emerald-300 rounded-lg p-3">
<div className="text-[11px] font-semibold text-emerald-800">
Uptime %
</div>
<div className="text-xl font-bold text-emerald-900 mt-0.5 truncate">
{computeUptimePct(report.summary)}
</div>
</div>
)}
{Object.entries(report.summary).map(([sKey, sVal]) => (
<div
key={sKey}
+1 -1
View File
@@ -168,7 +168,7 @@ export function SettingsPage() {
onChange={(e) => handleChange(item, e.target.checked)}
className="h-4 w-4 rounded border-gray-300 text-[#1e3a8a] focus:ring-blue-500"
/>
<span className="text-sm text-gray-700">{Boolean(val) ? "Enabled" : "Disabled"}</span>
<span className="text-sm text-gray-700">{val ? "Enabled" : "Disabled"}</span>
</label>
)}
-28
View File
@@ -1,28 +0,0 @@
// Stub pages — replaced phase by phase
interface StubProps {
title: string;
phase: number;
description?: string;
children?: React.ReactNode;
}
function StubPage({ title, phase, description, children }: StubProps) {
return (
<div className="max-w-lg mx-auto mt-16 text-center">
<div className="inline-flex items-center justify-center w-16 h-16 rounded-full bg-blue-50 mb-4">
<span className="text-2xl">🏗️</span>
</div>
<h2 className="text-xl font-semibold text-gray-800 mb-2">{title}</h2>
{description && <p className="text-gray-500 text-sm mb-4">{description}</p>}
<div className="inline-flex items-center gap-2 bg-amber-50 border border-amber-200 text-amber-700 px-4 py-2 rounded-full text-sm font-medium">
Coming in Phase {phase}
</div>
{children}
</div>
);
}
export const ReportsPage = () => (
<StubPage title="Reports & Exports" phase={7} description="8 reports with Excel export." />
);
+2 -1
View File
@@ -1,7 +1,8 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { Attachments, validateAttachmentFile } from "@/components/Attachments";
import { Attachments } from "@/components/Attachments";
import { validateAttachmentFile } from "@/lib/validation";
import { attachmentsApi } from "@/api/attachments";
function renderWithQuery(ui: React.ReactNode) {
+18 -1
View File
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { render, screen, waitFor } from "@testing-library/react";
import { render, screen, waitFor, fireEvent } from "@testing-library/react";
import { MemoryRouter, Route, Routes } from "react-router-dom";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ComplaintDetailPage } from "@/pages/ComplaintDetailPage";
@@ -145,5 +145,22 @@ describe("ComplaintDetailPage", () => {
screen.getByRole("button", { name: /Save Technical Details/i })
).toBeInTheDocument();
expect(screen.getByDisplayValue("Replaced flow sensor")).toBeInTheDocument();
const closeSpy = vi.spyOn(complaintsApi, "close").mockResolvedValue(MOCK_COMPLAINT);
fireEvent.click(screen.getByRole("button", { name: /Close Call/i }));
await waitFor(() => {
expect(screen.getByText("Close Complaint Call")).toBeInTheDocument();
});
const remarksInput = screen.getByLabelText(/Closure Remarks/i);
expect(remarksInput).toBeRequired();
const submitForm = remarksInput.closest("form")!;
fireEvent.submit(submitForm);
await waitFor(() => {
expect(screen.getByText("Closure remarks are required.")).toBeInTheDocument();
});
expect(closeSpy).not.toHaveBeenCalled();
});
});
+1
View File
@@ -151,6 +151,7 @@ describe("Phase 7 Reports", () => {
screen.getByRole("heading", { name: /Monthly Maintenance Summary/i })
).toBeInTheDocument();
expect(screen.getByText("Distinct Downtime Days")).toBeInTheDocument();
expect(screen.getAllByText("99.6 %").length).toBeGreaterThanOrEqual(2);
expect(screen.getByRole("cell", { name: "ICU" })).toBeInTheDocument();
});
+1 -1
View File
@@ -1 +1 @@
{"root":["./src/app.tsx","./src/main.tsx","./src/vite-env.d.ts","./src/api/assets.ts","./src/api/attachments.ts","./src/api/audit.ts","./src/api/auth.ts","./src/api/calibration.ts","./src/api/client.ts","./src/api/complaints.ts","./src/api/dashboard.ts","./src/api/health.ts","./src/api/masters.ts","./src/api/notifications.ts","./src/api/phase5.ts","./src/api/pm.ts","./src/api/reports.ts","./src/api/search.ts","./src/api/settings.ts","./src/components/assetformmodal.tsx","./src/components/assetpicker.tsx","./src/components/attachments.tsx","./src/components/bulkassetimportmodal.tsx","./src/components/calibrationmodals.tsx","./src/components/calibrationremindermodal.tsx","./src/components/confirmdialog.tsx","./src/components/insurancedrawer.tsx","./src/components/pmmodals.tsx","./src/components/raisecomplaintmodal.tsx","./src/components/statusbadge.tsx","./src/components/toastprovider.tsx","./src/components/datatable/datatable.test.tsx","./src/components/datatable/datatable.tsx","./src/components/datatable/index.ts","./src/components/layout/appshell.tsx","./src/components/layout/sidebar.tsx","./src/components/layout/topbar.tsx","./src/components/ui/badge.tsx","./src/components/ui/button.tsx","./src/components/ui/dialog.tsx","./src/hooks/useauth.ts","./src/lib/format.ts","./src/lib/permissions.ts","./src/lib/utils.ts","./src/pages/accessdeniedpage.tsx","./src/pages/assetdetailpage.tsx","./src/pages/assetspage.tsx","./src/pages/auditlogspage.tsx","./src/pages/calibrationpage.tsx","./src/pages/complaintdetailpage.tsx","./src/pages/complaintspage.tsx","./src/pages/contractspage.tsx","./src/pages/dashboardpage.tsx","./src/pages/datatabledemopage.tsx","./src/pages/demoequipmentpage.tsx","./src/pages/insurancepage.tsx","./src/pages/loginpage.tsx","./src/pages/masterspage.tsx","./src/pages/notificationspage.tsx","./src/pages/pmpage.tsx","./src/pages/reportdetailpage.tsx","./src/pages/reportspage.tsx","./src/pages/settingspage.tsx","./src/pages/visitspage.tsx","./src/pages/stubs.tsx","./src/test/asset-picker.test.tsx","./src/test/attachments.test.tsx","./src/test/bulk-import.test.tsx","./src/test/calibration-page.test.tsx","./src/test/complaint-detail.test.tsx","./src/test/login.test.tsx","./src/test/permissions.test.ts","./src/test/phase5-modules.test.tsx","./src/test/phase6-modules.test.tsx","./src/test/phase8-polish.test.tsx","./src/test/pm-page.test.tsx","./src/test/reports.test.tsx","./src/test/setup.ts","./src/test/smoke.test.tsx"],"version":"5.6.3"}
{"root":["./src/app.tsx","./src/main.tsx","./src/vite-env.d.ts","./src/api/assets.ts","./src/api/attachments.ts","./src/api/audit.ts","./src/api/auth.ts","./src/api/calibration.ts","./src/api/client.ts","./src/api/complaints.ts","./src/api/dashboard.ts","./src/api/health.ts","./src/api/masters.ts","./src/api/notifications.ts","./src/api/phase5.ts","./src/api/pm.ts","./src/api/reports.ts","./src/api/search.ts","./src/api/settings.ts","./src/components/assetformmodal.tsx","./src/components/assetpicker.tsx","./src/components/attachments.tsx","./src/components/bulkassetimportmodal.tsx","./src/components/calibrationmodals.tsx","./src/components/calibrationremindermodal.tsx","./src/components/confirmdialog.tsx","./src/components/insurancedrawer.tsx","./src/components/pmmodals.tsx","./src/components/raisecomplaintmodal.tsx","./src/components/statusbadge.tsx","./src/components/toastprovider.tsx","./src/components/datatable/datatable.test.tsx","./src/components/datatable/datatable.tsx","./src/components/datatable/index.ts","./src/components/layout/appshell.tsx","./src/components/layout/sidebar.tsx","./src/components/layout/topbar.tsx","./src/components/ui/badge.tsx","./src/components/ui/button.tsx","./src/components/ui/dialog.tsx","./src/hooks/useauth.ts","./src/lib/format.ts","./src/lib/permissions.ts","./src/lib/toast.ts","./src/lib/utils.ts","./src/lib/validation.ts","./src/pages/accessdeniedpage.tsx","./src/pages/assetdetailpage.tsx","./src/pages/assetspage.tsx","./src/pages/auditlogspage.tsx","./src/pages/calibrationpage.tsx","./src/pages/complaintdetailpage.tsx","./src/pages/complaintspage.tsx","./src/pages/contractspage.tsx","./src/pages/dashboardpage.tsx","./src/pages/datatabledemopage.tsx","./src/pages/demoequipmentpage.tsx","./src/pages/insurancepage.tsx","./src/pages/loginpage.tsx","./src/pages/masterspage.tsx","./src/pages/notificationspage.tsx","./src/pages/pmpage.tsx","./src/pages/reportdetailpage.tsx","./src/pages/reportspage.tsx","./src/pages/settingspage.tsx","./src/pages/visitspage.tsx","./src/test/asset-picker.test.tsx","./src/test/attachments.test.tsx","./src/test/bulk-import.test.tsx","./src/test/calibration-page.test.tsx","./src/test/complaint-detail.test.tsx","./src/test/login.test.tsx","./src/test/permissions.test.ts","./src/test/phase5-modules.test.tsx","./src/test/phase6-modules.test.tsx","./src/test/phase8-polish.test.tsx","./src/test/pm-page.test.tsx","./src/test/reports.test.tsx","./src/test/setup.ts","./src/test/smoke.test.tsx"],"version":"5.6.3"}