55 lines · 1.7 KB · TypeScript
RawDownload
import { assert, describe, it } from "vitest";import { buildVisibleToastLayout, shouldHideCollapsedToastContent } from "./toast.logic"; describe("shouldHideCollapsedToastContent", () => {  it("keeps a single visible toast readable", () => {    assert.equal(shouldHideCollapsedToastContent(0, 1), false);  });   it("keeps the front-most toast readable in a visible stack", () => {    assert.equal(shouldHideCollapsedToastContent(0, 3), false);  });   it("hides non-front toasts until the stack is expanded", () => {    assert.equal(shouldHideCollapsedToastContent(1, 3), true);  });}); describe("buildVisibleToastLayout", () => {  it("computes indices and offsets from the visible subset", () => {    const visibleToasts = [{ id: "a", height: 48 }, { id: "b", height: 72 }, { id: "c", height: 24 }];     const layout = buildVisibleToastLayout(visibleToasts);     assert.equal(layout.frontmostHeight, 48);    assert.deepEqual(      layout.items.map(({ toast, visibleIndex, offsetY }) => ({        id: toast.id,        visibleIndex,        offsetY,      })),      [        { id: "a", visibleIndex: 0, offsetY: 0 },        { id: "b", visibleIndex: 1, offsetY: 48 },        { id: "c", visibleIndex: 2, offsetY: 120 },      ],    );  });   it("treats missing heights as zero", () => {    const layout = buildVisibleToastLayout([{ id: "a" }, { id: "b", height: undefined }, { id: "c", height: 30 }]);     assert.equal(layout.frontmostHeight, 0);    assert.deepEqual(      layout.items.map(({ toast, offsetY }) => ({        id: toast.id,        offsetY,      })),      [        { id: "a", offsetY: 0 },        { id: "b", offsetY: 0 },        { id: "c", offsetY: 0 },      ],    );  });});

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t