78 lines
2.5 KiB
TypeScript
78 lines
2.5 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import type { FileBrowserData } from "@toolctrl/view-models";
|
|
import { renderFileBrowserMock } from "@toolctrl/ui-mock";
|
|
|
|
import { fileBrowserAdapter } from "./fileBrowser.js";
|
|
|
|
const vm: FileBrowserData = {
|
|
viewMode: "table",
|
|
rows: [
|
|
{
|
|
id: "file-1",
|
|
displayName: "invoice.pdf",
|
|
mimeType: "application/pdf",
|
|
sizeBytes: 1024,
|
|
createdAtIso: "2026-06-20T00:00:00.000Z",
|
|
tags: [],
|
|
source: "manual_upload",
|
|
previewStatus: "ready",
|
|
scanStatus: "clean",
|
|
thumbnailUrl: "/acme/media/file-1/thumb",
|
|
detailHref: "/acme/files/file-1",
|
|
linkedEntityLabelKey: null,
|
|
},
|
|
{
|
|
id: "file-2",
|
|
displayName: "photo.heic",
|
|
mimeType: "image/heic",
|
|
sizeBytes: 2048,
|
|
createdAtIso: "2026-06-20T00:00:00.000Z",
|
|
tags: ["site"],
|
|
source: "manual_upload",
|
|
previewStatus: "pending",
|
|
scanStatus: "pending",
|
|
thumbnailUrl: null,
|
|
detailHref: "/acme/files/file-2",
|
|
linkedEntityLabelKey: null,
|
|
},
|
|
],
|
|
filter: { entityType: null, mimeGroup: null, tags: [], assignedToUserId: null, includeArchived: false },
|
|
canWrite: true,
|
|
canDelete: false,
|
|
nextCursor: null,
|
|
emptyHeadlineKey: "files.browser.empty.headline",
|
|
emptyBodyKey: "files.browser.empty.body",
|
|
};
|
|
|
|
describe("fileBrowserAdapter hot-swap (M017)", () => {
|
|
test("normalizes the VM once via toProps", () => {
|
|
const model = fileBrowserAdapter.toProps(vm);
|
|
expect(model.rowCount).toBe(2);
|
|
expect(model.titleKey).toBe("files.browser.title");
|
|
expect(model.rows.map((row) => row.id)).toEqual(["file-1", "file-2"]);
|
|
});
|
|
|
|
test("swaps the render implementation without changing the data", () => {
|
|
const defaultHtml = fileBrowserAdapter.render(vm);
|
|
const mockHtml = fileBrowserAdapter.render(vm, renderFileBrowserMock);
|
|
|
|
expect(defaultHtml).toContain('data-ui-impl="subframe"');
|
|
expect(defaultHtml).not.toContain('data-ui-impl="mock"');
|
|
expect(mockHtml).toContain('data-ui-impl="mock"');
|
|
expect(mockHtml).not.toContain('data-ui-impl="subframe"');
|
|
expect(defaultHtml).not.toBe(mockHtml);
|
|
|
|
for (const html of [defaultHtml, mockHtml]) {
|
|
for (const row of vm.rows) {
|
|
expect(html).toContain(`data-row-id="${row.id}"`);
|
|
expect(html).toContain(row.displayName);
|
|
}
|
|
}
|
|
});
|
|
|
|
test("the default renderer is the real subframe implementation", () => {
|
|
expect(fileBrowserAdapter.name).toBe("fileBrowser");
|
|
expect(fileBrowserAdapter.render(vm)).toContain('data-ui-id="ui.files.browser"');
|
|
});
|
|
});
|