38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import type { DataTableModel } from "@toolctrl/view-models";
|
|
|
|
import { renderDataTableMock } from "./index.js";
|
|
|
|
const model: DataTableModel = {
|
|
captionKey: "ui.data-table.caption",
|
|
columns: [
|
|
{ key: "name", labelKey: "ui.data-table.column.name", align: "left" },
|
|
{ key: "amount", labelKey: "ui.data-table.column.amount", align: "right" },
|
|
],
|
|
rows: [
|
|
{ id: "row-1", cells: { name: "Alpha", amount: "10" } },
|
|
{ id: "row-2", cells: { name: "Beta", amount: "20" } },
|
|
],
|
|
emptyLabelKey: "ui.data-table.empty",
|
|
rowCount: 2,
|
|
};
|
|
|
|
describe("renderDataTableMock (mock impl)", () => {
|
|
test("carries the mock implementation marker and the row data", () => {
|
|
const html = renderDataTableMock(model);
|
|
expect(html).toContain('data-ui-impl="mock"');
|
|
expect(html).toContain('data-ui-id="ui.data-table"');
|
|
expect(html).toContain('data-row-id="row-1"');
|
|
expect(html).toContain('data-row-id="row-2"');
|
|
expect(html).toContain("Alpha");
|
|
expect(html).toContain("20");
|
|
});
|
|
|
|
test("renders an empty marker when there are no rows", () => {
|
|
const html = renderDataTableMock({ ...model, rows: [], rowCount: 0 });
|
|
expect(html).toContain('data-empty="true"');
|
|
expect(html).toContain('data-i18n-key="ui.data-table.empty"');
|
|
expect(html).not.toContain("data-row-id=");
|
|
});
|
|
});
|