31 lines
1.4 KiB
TypeScript
31 lines
1.4 KiB
TypeScript
function assert(condition: unknown, message = "assertion failed"): void {
|
|
if (!condition) throw new Error(message);
|
|
}
|
|
|
|
function assertEqual<T>(actual: T, expected: T, message = "values should be equal"): void {
|
|
if (actual !== expected) throw new Error(`${message}: expected ${String(expected)}, got ${String(actual)}`);
|
|
}
|
|
|
|
function assertDeepEqual(actual: unknown, expected: unknown, message = "values should be deeply equal"): void {
|
|
const actualJson = JSON.stringify(actual);
|
|
const expectedJson = JSON.stringify(expected);
|
|
if (actualJson !== expectedJson) throw new Error(`${message}: expected ${expectedJson}, got ${actualJson}`);
|
|
}
|
|
|
|
import { buildMailboxFolderTree, findFolderNodeId, folderAncestorIds, folderParts } from "../src/features/mail/mailboxFolders";
|
|
|
|
assertDeepEqual(folderParts("INBOX.Sent.Archive"), ["INBOX", "Sent", "Archive"]);
|
|
assertDeepEqual(folderParts("Projects/2026/Inbox"), ["Projects", "2026", "Inbox"]);
|
|
|
|
const tree = buildMailboxFolderTree([
|
|
{ name: "Archive/2026", flags: [] },
|
|
{ name: "INBOX", flags: [] },
|
|
{ name: "INBOX.Sent", flags: ["\\Sent"] },
|
|
{ name: "Projects/2026/Inbox", flags: [] }
|
|
]);
|
|
|
|
assertEqual(tree[0].id, "INBOX", "INBOX sorts first");
|
|
assertEqual(findFolderNodeId(tree, "INBOX.Sent"), "INBOX/Sent");
|
|
assertDeepEqual(folderAncestorIds(tree, "Projects/2026/Inbox"), ["Projects", "Projects/2026", "Projects/2026/Inbox"]);
|
|
assertEqual(tree.find((node) => node.id === "INBOX")?.children[0]?.folderName, "INBOX.Sent");
|