char-slop/berry

multipurpose self-modifiable agentic harness

git clone https://git.t4t.associates/char-slop/berry

Charlotte Somfix grip styling on settings page4cce09f

main
1.7 KiB43 linesraw
1import type { HeaderContext } from "@berry/api/web.ts";
2import { assertEquals, assertStrictEquals } from "@std/assert";
3import { viewContext, withDom } from "@berry/util/dom.ts";
4import { headerWidgets } from "./header.ts";
5
6Deno.test("reloading a header widget replaces it without disturbing its neighbors or leaving stale nodes", () =>
7  withDom(() => {
8    const widgets = headerWidgets();
9    const disposed: Element[] = [];
10    const create = () => {
11      const element = document.createElement("button");
12      return {
13        element,
14        update(context: HeaderContext) {
15          element.textContent = context.tid;
16        },
17        dispose() {
18          disposed.push(element);
19        },
20      };
21    };
22    const first = { name: "first", create };
23    const second = { name: "second", create };
24    const context = (tid: string) => viewContext({ tid });
25    widgets.update([first, second], context);
26    const original = widgets.element.firstElementChild!;
27    const neighbor = widgets.element.lastElementChild!;
28
29    const reloaded = { name: "first", create: () => create() };
30    widgets.update([second, reloaded], context);
31    const replacement = widgets.element.lastElementChild!;
32    assertEquals(widgets.element.contains(original), false);
33    assertStrictEquals(widgets.element.firstElementChild, neighbor);
34    assertEquals(replacement.textContent, first.name);
35    assertEquals(disposed, [original]);
36
37    widgets.update([second], context);
38    assertEquals(widgets.element.contains(replacement), false);
39    assertStrictEquals(widgets.element.firstElementChild, neighbor);
40    assertEquals(disposed, [original, replacement]);
41    widgets.dispose();
42    assertEquals(disposed, [original, replacement, neighbor]);
43  }));