AkurAI Build
Menu

Public repository / c3ef99b092caa55fb6a3eed9d3e776734cc99e97

AkurAI-Mail / src/lib/webmail/filters.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 { filterParams, isPlainView, mailboxCacheKey } from "./filters";

describe("filters", () => {
  test("smart mailboxes and chips both set query flags", () => {
    expect(filterParams("today", new Set(["unread", "contacts"]))).toEqual({
      unread: "true", flagged: "false", attachment: "false", today: "true", vip: "false", contacts: "true", priority: "false",
    });
    expect(filterParams("flagged", new Set()).flagged).toBe("true");
  });

  test("only unfiltered first pages are cached", () => {
    expect(isPlainView("", "", "", new Set())).toBe(true);
    expect(isPlainView("q", "", "", new Set())).toBe(false);
    expect(isPlainView("", "c", "", new Set())).toBe(false);
    expect(isPlainView("", "", "vip", new Set())).toBe(false);
    expect(isPlainView("", "", "", new Set(["unread"]))).toBe(false);
  });

  test("cache key is per mailbox and folder", () => {
    expect(mailboxCacheKey("a@x.is", "Inbox")).toBe("akurai-webmail-cache:a@x.is:Inbox");
    expect(mailboxCacheKey("", "Sent")).toBe("akurai-webmail-cache:default:Sent");
  });
});