AkurAI Build
Menu

Public repository / 7a6a24a4e46f9f1d964c5593c076f9bdf638fea0

AkurAI-Mail / src/lib/webmail/folders.test.ts

Latest change 22202d1bde69be4ace8a299dffd91f8ff24378df - Recover deployed webmail frontend (frontend parity with EC2 a6afffc) by Ólafur Búi Ólafsson

import { describe, expect, test } from "bun:test";
import { buildFolderTree, visibleFolders } from "./folders";

describe("folder tree", () => {
  const tree = buildFolderTree([
    { name: "Inbox", unread: 3, total: 10 },
    { name: "Projects/2026", unread: 1, total: 4 },
    { name: "Projects/2026/Q3", total: 2 },
  ]);

  test("builds intermediate nodes and keeps counts on the named folder", () => {
    expect(tree.map((n) => n.path)).toEqual(["Inbox", "Projects"]);
    const projects = tree[1]!;
    expect(projects).toMatchObject({ name: "Projects", depth: 0, unread: 0 });
    expect(projects.children[0]).toMatchObject({ name: "2026", path: "Projects/2026", depth: 1, unread: 1, total: 4 });
    expect(projects.children[0]!.children[0]).toMatchObject({ path: "Projects/2026/Q3", depth: 2, total: 2 });
  });

  test("lists folders expanded by default and hides children of collapsed ones", () => {
    expect(visibleFolders(tree, {}).map((n) => n.path)).toEqual(["Inbox", "Projects", "Projects/2026", "Projects/2026/Q3"]);
    expect(visibleFolders(tree, { "Projects/2026": false }).map((n) => n.path)).toEqual(["Inbox", "Projects", "Projects/2026"]);
  });
});