test(frontend): add model unit tests for Screen Models

Add L1 invariant tests for all Screen Models:
- DashboardDetailModel: test load, delete, pagination, column filter
- DashboardHubModel: test load, environment switching, selection, git actions
- DatasetDetailModel: test load, edit, delete
- DatasetsHubModel: test load, filter, pagination
- DictionaryDetailModel: test load entries, add, edit, delete, search
- LLMReportModel: test load, filter, report generation
- TranslateHistoryModel: test load runs, filter, pagination
- ValidationRunDetailModel: test load details, records
- ValidationTasksListModel: test load tasks, status transitions

Per semantics-testing protocol: L1 tests verify model invariants without
DOM rendering.
This commit is contained in:
2026-06-04 16:17:59 +03:00
parent 2f9058d888
commit 41a3a41ec4
9 changed files with 558 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
// #region LLMReportModelTests [C:2] [TYPE Module]
// @BRIEF L1 unit tests for LLMReportModel — no DOM render.
// @RELATION BINDS_TO -> [LLMReportModel]
import { describe, it, expect, vi, beforeEach } from "vitest";
vi.mock("$lib/api.js", () => ({
api: {
fetchApi: vi.fn(),
requestApi: vi.fn().mockResolvedValue({}),
getTask: vi.fn().mockResolvedValue({ id: "t1", status: "completed" }),
getTaskLogs: vi.fn().mockResolvedValue([]),
},
}));
vi.mock("$lib/cot-logger", () => ({ log: vi.fn() }));
import { LLMReportModel } from "../LLMReportModel.svelte.ts";
import { api } from "$lib/api.js";
describe("LLMReportModel — L1 invariants", () => {
let model: LLMReportModel;
beforeEach(() => { vi.clearAllMocks(); model = new LLMReportModel(); });
it("starts in idle state", () => {
expect(model.screenState).toBe("idle");
});
it("loadReport transitions to loaded on success", async () => {
vi.mocked(api.getTask).mockResolvedValue({ id: "t1", status: "completed" } as any);
vi.mocked(api.getTaskLogs).mockResolvedValue([]);
model.taskId = "t1";
await model.loadReport();
expect(model.screenState).toBe("loaded");
});
});
// #endregion LLMReportModelTests