Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+85
@@ -0,0 +1,85 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import type { FileBrowserModel } from "@hivegrid/view-models";
|
||||
|
||||
import { renderFileBrowserMock } from "./index.js";
|
||||
|
||||
const model: FileBrowserModel = {
|
||||
titleKey: "ui.files.browser.title",
|
||||
emptyHeadlineKey: "ui.files.browser.empty.headline",
|
||||
emptyBodyKey: "ui.files.browser.empty.body",
|
||||
canWrite: true,
|
||||
rows: [
|
||||
{
|
||||
id: "file-1",
|
||||
displayName: "Quartalsbericht.pdf",
|
||||
mimeType: "application/pdf",
|
||||
sizeBytes: 2048,
|
||||
detailHref: "/files/file-1",
|
||||
thumbnailUrl: null,
|
||||
},
|
||||
{
|
||||
id: "file-2",
|
||||
displayName: "logo.png",
|
||||
mimeType: "image/png",
|
||||
sizeBytes: 512,
|
||||
detailHref: "/files/file-2",
|
||||
thumbnailUrl: "/thumb/file-2",
|
||||
},
|
||||
],
|
||||
rowCount: 2,
|
||||
};
|
||||
|
||||
describe("renderFileBrowserMock (mock impl)", () => {
|
||||
test("carries the impl marker, title key and one body row per file", () => {
|
||||
const html = renderFileBrowserMock(model);
|
||||
expect(html).toContain('data-ui-impl="mock"');
|
||||
expect(html).toContain('data-ui-id="ui.files.browser"');
|
||||
expect(html).toContain('data-row-count="2"');
|
||||
// Header carries the i18n key, never a resolved label.
|
||||
expect(html).toContain('data-row="head" data-i18n-key="ui.files.browser.title"');
|
||||
// Exactly two body rows, no empty marker when rows exist.
|
||||
expect(html.match(/data-row="body"/g)).toHaveLength(2);
|
||||
expect(html).not.toContain('data-empty="true"');
|
||||
});
|
||||
|
||||
test("emits mime type and raw byte size as data-attributes per row", () => {
|
||||
const html = renderFileBrowserMock(model);
|
||||
expect(html).toContain('data-row-id="file-1"');
|
||||
expect(html).toContain('data-mime="application/pdf"');
|
||||
expect(html).toContain('data-size="2048"');
|
||||
expect(html).toContain("Quartalsbericht.pdf");
|
||||
expect(html).toContain('data-row-id="file-2"');
|
||||
expect(html).toContain('data-mime="image/png"');
|
||||
expect(html).toContain('data-size="512"');
|
||||
});
|
||||
|
||||
test("renders the empty headline marker when there are no rows", () => {
|
||||
const html = renderFileBrowserMock({ ...model, rows: [], rowCount: 0 });
|
||||
expect(html).toContain('data-row-count="0"');
|
||||
expect(html).toContain('data-empty="true"');
|
||||
expect(html).toContain('data-i18n-key="ui.files.browser.empty.headline"');
|
||||
expect(html).not.toContain('data-row="body"');
|
||||
});
|
||||
|
||||
test("escapes HTML metacharacters in display name and mime type", () => {
|
||||
const html = renderFileBrowserMock({
|
||||
...model,
|
||||
rows: [
|
||||
{
|
||||
id: "x&y",
|
||||
displayName: '<script>"alert"</script>',
|
||||
mimeType: 'text/x-"weird"',
|
||||
sizeBytes: 1,
|
||||
detailHref: "/files/x",
|
||||
thumbnailUrl: null,
|
||||
},
|
||||
],
|
||||
rowCount: 1,
|
||||
});
|
||||
// No raw angle brackets or quotes from user data leak into the markup.
|
||||
expect(html).toContain("<script>"alert"</script>");
|
||||
expect(html).toContain('data-row-id="x&y"');
|
||||
expect(html).toContain('data-mime="text/x-"weird""');
|
||||
expect(html).not.toContain("<script>");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user