paas-inbox-panel.test.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { expect, test } from "bun:test"
  2. import { createRoot, createSignal } from "solid-js"
  3. import type { InboxItem } from "@/pages/paas/inbox"
  4. import { createInboxOpenState } from "@/pages/paas/inbox-panel-state"
  5. // Bun cannot compile Solid JSX here and the unit suite resolves the server Solid build,
  6. // where effects are inert, so the panel state is covered by the browser-condition suite.
  7. const item: InboxItem = {
  8. id: "unread:run_1",
  9. kind: "unread",
  10. title: "研究计划",
  11. detail: "科研助手",
  12. projectID: "project_1",
  13. projectName: "测试项目",
  14. chatID: "chat_1",
  15. runID: "run_1",
  16. at: 1,
  17. }
  18. test("an emptied inbox list resets open so a recreated panel stays closed", () => {
  19. const [items, setItems] = createSignal([item])
  20. const mounted = createRoot((dispose) => ({
  21. panel: createInboxOpenState(items),
  22. dispose,
  23. }))
  24. expect(mounted.panel.open()).toBe(false)
  25. mounted.panel.setOpen(true)
  26. expect(mounted.panel.open()).toBe(true)
  27. setItems([])
  28. expect(mounted.panel.open()).toBe(false)
  29. setItems([item])
  30. expect(mounted.panel.open()).toBe(false)
  31. mounted.dispose()
  32. })