test: remediate audit findings for task log viewer, report card and logger tests
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
// [DEF:frontend.src.components.__tests__.task_log_viewer:Module]
|
||||
// @TIER: STANDARD
|
||||
// @TIER: CRITICAL
|
||||
// @SEMANTICS: tests, task-log, viewer, mount, components
|
||||
// @PURPOSE: Unit tests for TaskLogViewer component by mounting it and observing the DOM.
|
||||
// @LAYER: UI (Tests)
|
||||
// @RELATION: TESTS -> frontend.src.components.TaskLogViewer
|
||||
// @RELATION: VERIFIES -> frontend/src/components/TaskLogViewer.svelte
|
||||
// @INVARIANT: Duplicate logs are never appended. Polling only active for in-progress tasks.
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
@@ -20,10 +20,12 @@ vi.mock('../../lib/i18n', () => ({
|
||||
subscribe: (fn) => {
|
||||
fn({
|
||||
tasks: {
|
||||
loading: 'Loading...'
|
||||
loading: 'Loading...',
|
||||
logs_title: 'Task Logs'
|
||||
},
|
||||
common: {
|
||||
retry: 'Retry'
|
||||
retry: 'Retry',
|
||||
close: 'Close'
|
||||
}
|
||||
});
|
||||
return () => { };
|
||||
@@ -127,5 +129,33 @@ describe('TaskLogViewer Component', () => {
|
||||
// getByText asserts there is exactly *one* match.
|
||||
expect(() => screen.getByText(/Duplicate log entry/)).not.toThrow();
|
||||
});
|
||||
|
||||
// @TEST_FIXTURE valid_viewer
|
||||
it('fetches and displays historical logs in modal mode under valid_viewer fixture', async () => {
|
||||
getTaskLogs.mockResolvedValue([
|
||||
{ timestamp: '2024-01-01T00:00:00', level: 'INFO', message: 'Modal log entry' }
|
||||
]);
|
||||
|
||||
render(TaskLogViewer, { show: true, inline: false, taskId: 'task-123' });
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText(/Modal log entry/)).toBeDefined();
|
||||
expect(screen.getByText('Task Logs')).toBeDefined();
|
||||
});
|
||||
|
||||
expect(getTaskLogs).toHaveBeenCalledWith('task-123');
|
||||
});
|
||||
|
||||
// @TEST_EDGE no_task_id
|
||||
it('does not fetch logs if taskId is null', () => {
|
||||
render(TaskLogViewer, { inline: true, taskId: null });
|
||||
expect(getTaskLogs).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// @UX_FEEDBACK
|
||||
it('passes autoScroll feedback properly down to the panel by rendering without crashing', () => {
|
||||
const { component } = render(TaskLogViewer, { inline: true, taskId: 'task-123' });
|
||||
expect(component).toBeDefined();
|
||||
});
|
||||
});
|
||||
// [/DEF:frontend.src.components.__tests__.task_log_viewer:Module]
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @vitest-environment jsdom
|
||||
*/
|
||||
// [DEF:frontend.src.lib.components.reports.__tests__.report_card.ux:Module]
|
||||
// @TIER: STANDARD
|
||||
// @TIER: CRITICAL
|
||||
// @SEMANTICS: reports, ux-tests, card, states, recovery
|
||||
// @PURPOSE: Test UX states and transitions for ReportCard component
|
||||
// @LAYER: UI
|
||||
@@ -70,6 +70,33 @@ describe('ReportCard UX Contract', () => {
|
||||
// Check fallback type (the profile itself returns 'reports.unknown_type' string which doesn't get translated by $t in the mock if it's returning the key)
|
||||
expect(screen.getByText('reports.unknown_type')).toBeDefined();
|
||||
});
|
||||
|
||||
// @TEST_FIXTURE valid_report_card
|
||||
it('should render valid_report_card correctly', () => {
|
||||
const validReportCard = {
|
||||
task_type: "migration",
|
||||
status: "success",
|
||||
summary: "Test Summary",
|
||||
updated_at: "2024-01-01"
|
||||
};
|
||||
render(ReportCard, { report: validReportCard });
|
||||
|
||||
expect(screen.getByText('Test Summary')).toBeDefined();
|
||||
expect(screen.getByText('Success')).toBeDefined();
|
||||
});
|
||||
|
||||
// @TEST_EDGE empty_report_object
|
||||
it('should handle completely empty report object gracefully', () => {
|
||||
render(ReportCard, { report: {} });
|
||||
const placeholders = screen.getAllByText('Not provided');
|
||||
expect(placeholders.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
// @TEST_EDGE random_status
|
||||
it('should render random status directly if no translation matches', () => {
|
||||
render(ReportCard, { report: { status: "unknown_status_code" } });
|
||||
expect(screen.getByText('unknown_status_code')).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
// [/DEF:frontend.src.lib.components.reports.__tests__.report_card.ux:Module]
|
||||
Reference in New Issue
Block a user