on 2026.09.23.2009 help sign in
diagonal/test/helpers.ts
24 lines 1.3 kB history raw
1import type { Ctx, TabSnapshot } from "../src/background/engine";
2import { DEFAULT_SETTINGS, type Settings } from "../src/background/settings";
3import { emptyState, newGroupRecord, type GroupOrigin, type State } from "../src/background/state";
5export const settings = (over: Partial<Settings> = {}): Settings => ({ ...DEFAULT_SETTINGS, ...over });
6export const ctx = (now = 1_000_000, over: Partial<Settings> = {}): Ctx => ({ now, settings: settings(over) });
8export function tab(id: number, over: Partial<TabSnapshot> = {}): TabSnapshot {
9 return { id, windowId: 1, groupId: -1, index: id, url: `https://example.com/${id}`, title: `Tab ${id}`, pinned: false, status: "complete", ...over };
12export function stateWith(tabs: TabSnapshot[], groups: { id: number; origin: GroupOrigin; managed?: boolean; title?: string }[] = []): State {
13 const s = emptyState();
14 for (const t of tabs) {
15 s.tabs[t.id] = {
16 id: t.id, windowId: t.windowId, groupId: t.groupId, index: t.index, url: t.url ?? "", title: t.title ?? "",
17 pinned: t.pinned, status: t.status, createdAt: 0, lastActivatedAt: 0,
18 };
19 }
20 for (const g of groups) {
21 s.groups[g.id] = newGroupRecord(g.id, 1, g.origin, "blue", { managed: g.managed ?? g.origin !== "user", stripTitle: g.title, title: g.title });
22 }
23 return s;