tftsr-devops_investigation/tests/unit/auditLog.test.tsx
Shaun Arman 6ebe3612cd
All checks were successful
Test / frontend-tests (pull_request) Successful in 1m9s
Test / frontend-typecheck (pull_request) Successful in 1m15s
Test / rust-fmt-check (pull_request) Successful in 2m44s
Test / rust-clippy (pull_request) Successful in 24m22s
Test / rust-tests (pull_request) Successful in 25m43s
fix: lint fixes and formatting cleanup
- Fix TypeScript lint errors in setup.ts and LogUpload
- Remove unused imports and variables
- Fix duplicate Separator exports in ui/index.tsx
- Apply cargo fmt formatting to Rust code
- Update ESLint configuration
2026-04-09 20:42:40 -05:00

80 lines
2.3 KiB
TypeScript

import { describe, it, expect, beforeEach, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import Security from "@/pages/Settings/Security";
import * as tauriCommands from "@/lib/tauriCommands";
vi.mock("@/lib/tauriCommands");
const mockAuditEntries: tauriCommands.AuditEntry[] = [
{
id: "audit-1",
timestamp: "2026-04-02T10:00:00Z",
action: "generate_rca",
entity_type: "document",
entity_id: "doc-123",
user_id: "user-1",
details: JSON.stringify({
issue_id: "issue-456",
content_hash: "abc123",
data: "Sample RCA content"
}),
},
{
id: "audit-2",
timestamp: "2026-04-02T11:00:00Z",
action: "ai_chat",
entity_type: "conversation",
entity_id: "conv-789",
user_id: "user-1",
details: JSON.stringify({
message: "What caused the issue?",
response_hash: "def456"
}),
},
];
describe("Audit Log", () => {
beforeEach(() => {
vi.clearAllMocks();
vi.mocked(tauriCommands.getAuditLogCmd).mockResolvedValue(mockAuditEntries);
});
it("displays audit entries", async () => {
render(<Security />);
// Wait for audit log to load
await screen.findByText("Audit Log");
// Check that the table has rows (header + data rows)
const table = screen.getByRole("table");
expect(table).toBeInTheDocument();
const rows = screen.getAllByRole("row");
expect(rows.length).toBeGreaterThan(1); // At least header + 1 data row
});
it("provides way to view transmitted data details", async () => {
render(<Security />);
await screen.findByText("Audit Log");
// Should have View/Hide buttons for expanding details
const viewButtons = await screen.findAllByRole("button", { name: /View/i });
expect(viewButtons.length).toBeGreaterThan(0);
});
it("details column or button exists for viewing data", async () => {
render(<Security />);
await screen.findByText("Audit Log");
// The audit log should have a Details column header
const detailsHeader = screen.getByText("Details");
expect(detailsHeader).toBeInTheDocument();
// Should have view buttons
const viewButtons = await screen.findAllByRole("button", { name: /View/i });
expect(viewButtons.length).toBe(2); // One for each mock entry
});
});