Open History to see the last commit
1import { assert, describe, it } from "vitest";
2import { buildVisibleToastLayout, shouldHideCollapsedToastContent } from "./toast.logic";
3
4describe("shouldHideCollapsedToastContent", () => {
5 it("keeps a single visible toast readable", () => {
6 assert.equal(shouldHideCollapsedToastContent(0, 1), false);
7 });
8
9 it("keeps the front-most toast readable in a visible stack", () => {
10 assert.equal(shouldHideCollapsedToastContent(0, 3), false);
11 });
12
13 it("hides non-front toasts until the stack is expanded", () => {
14 assert.equal(shouldHideCollapsedToastContent(1, 3), true);
15 });
16});
17
18describe("buildVisibleToastLayout", () => {
19 it("computes indices and offsets from the visible subset", () => {
20 const visibleToasts = [
21 { id: "a", height: 48 },
22 { id: "b", height: 72 },
23 { id: "c", height: 24 },
24 ];
25
26 const layout = buildVisibleToastLayout(visibleToasts);
27
28 assert.equal(layout.frontmostHeight, 48);
29 assert.deepEqual(
30 layout.items.map(({ toast, visibleIndex, offsetY }) => ({
31 id: toast.id,
32 visibleIndex,
33 offsetY,
34 })),
35 [
36 { id: "a", visibleIndex: 0, offsetY: 0 },
37 { id: "b", visibleIndex: 1, offsetY: 48 },
38 { id: "c", visibleIndex: 2, offsetY: 120 },
39 ],
40 );
41 });
42
43 it("treats missing heights as zero", () => {
44 const layout = buildVisibleToastLayout([
45 { id: "a" },
46 { id: "b", height: undefined },
47 { id: "c", height: 30 },
48 ]);
49
50 assert.equal(layout.frontmostHeight, 0);
51 assert.deepEqual(
52 layout.items.map(({ toast, offsetY }) => ({
53 id: toast.id,
54 offsetY,
55 })),
56 [
57 { id: "a", offsetY: 0 },
58 { id: "b", offsetY: 0 },
59 { id: "c", offsetY: 0 },
60 ],
61 );
62 });
63});