64 lines
2.6 KiB
TypeScript
64 lines
2.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { buildAdminTenantNoteListVM, type AdminTenantNoteInputRow } from "./tenant-note-list.vm.js";
|
|
|
|
function row(overrides: Partial<AdminTenantNoteInputRow>): AdminTenantNoteInputRow {
|
|
return {
|
|
id: "n1",
|
|
createdAtIso: "2026-06-20T10:00:00.000Z",
|
|
category: "general",
|
|
pinned: false,
|
|
noteText: "note body",
|
|
authorEmail: null,
|
|
authorId: null,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("authorLabelFor id fallback (tenant-note-list.ts:67)", () => {
|
|
it("uses the trimmed author id when no email is present", () => {
|
|
const vm = buildAdminTenantNoteListVM({ rows: [row({ authorEmail: null, authorId: " op_3 " })] });
|
|
expect(vm.status).toBe("ready");
|
|
expect(vm.data?.rows[0]?.authorLabel).toBe("op_3");
|
|
});
|
|
});
|
|
|
|
describe("compareNotes pinned ordering, both directions (tenant-note-list.ts:73)", () => {
|
|
it("hoists a pinned note above an unpinned one even when the pinned note is listed last", () => {
|
|
// Input order is unpinned-before-pinned, forcing the `a.pinned ? -1 : 1` -> 1 branch.
|
|
const vm = buildAdminTenantNoteListVM({
|
|
rows: [
|
|
row({ id: "unpinned", pinned: false, createdAtIso: "2026-06-22T10:00:00.000Z" }),
|
|
row({ id: "pinned", pinned: true, createdAtIso: "2026-06-10T10:00:00.000Z" }),
|
|
],
|
|
});
|
|
if (vm.status !== "ready") throw new Error("expected ready");
|
|
expect(vm.data.rows.map((r) => r.id)).toEqual(["pinned", "unpinned"]);
|
|
expect(vm.data.pinnedCount).toBe(1);
|
|
});
|
|
|
|
it("keeps a pinned note on top when it already leads the input (opposite arg order)", () => {
|
|
// Input order is pinned-before-unpinned, forcing the comparator's other
|
|
// argument order so the `a.pinned ? -1 : 1` ternary's remaining arm runs.
|
|
const vm = buildAdminTenantNoteListVM({
|
|
rows: [
|
|
row({ id: "pinned", pinned: true, createdAtIso: "2026-06-10T10:00:00.000Z" }),
|
|
row({ id: "unpinned", pinned: false, createdAtIso: "2026-06-22T10:00:00.000Z" }),
|
|
],
|
|
});
|
|
if (vm.status !== "ready") throw new Error("expected ready");
|
|
expect(vm.data.rows.map((r) => r.id)).toEqual(["pinned", "unpinned"]);
|
|
});
|
|
|
|
it("orders two pinned notes newest-first among themselves", () => {
|
|
const vm = buildAdminTenantNoteListVM({
|
|
rows: [
|
|
row({ id: "older-pinned", pinned: true, createdAtIso: "2026-06-10T10:00:00.000Z" }),
|
|
row({ id: "newer-pinned", pinned: true, createdAtIso: "2026-06-20T10:00:00.000Z" }),
|
|
],
|
|
});
|
|
if (vm.status !== "ready") throw new Error("expected ready");
|
|
expect(vm.data.rows.map((r) => r.id)).toEqual(["newer-pinned", "older-pinned"]);
|
|
expect(vm.data.pinnedCount).toBe(2);
|
|
});
|
|
});
|