File
Blob: tests/client/components/editor/lib/page-mention/view-state.test.ts
| 1 | import { describe, expect, it } from "vitest"; |
| 2 | import { getPageMentionViewState } from "@/client/components/editor/lib/page-mention/view-state"; |
| 3 | |
| 4 | describe("page mention view state", () => { |
| 5 | it("keeps pending mentions non-interactive with no metadata", () => { |
| 6 | expect( |
| 7 | getPageMentionViewState({ |
| 8 | status: "pending", |
| 9 | source: null, |
| 10 | accessible: false, |
| 11 | title: "Leaked title", |
| 12 | icon: "A", |
| 13 | }), |
| 14 | ).toEqual({ |
| 15 | kind: "pending", |
| 16 | interactive: false, |
| 17 | label: "Pending...", |
| 18 | ariaLabel: "Pending page mention", |
| 19 | }); |
| 20 | }); |
| 21 | |
| 22 | it("renders restricted mentions without exposing metadata", () => { |
| 23 | expect( |
| 24 | getPageMentionViewState({ |
| 25 | status: "resolved", |
| 26 | source: "server", |
| 27 | accessible: false, |
| 28 | title: "Hidden title", |
| 29 | icon: "A", |
| 30 | }), |
| 31 | ).toEqual({ |
| 32 | kind: "restricted", |
| 33 | interactive: false, |
| 34 | label: "Restricted", |
| 35 | ariaLabel: "Restricted page mention", |
| 36 | }); |
| 37 | }); |
| 38 | |
| 39 | it("renders accessible mentions from resolved metadata", () => { |
| 40 | expect( |
| 41 | getPageMentionViewState({ |
| 42 | status: "resolved", |
| 43 | source: "server", |
| 44 | accessible: true, |
| 45 | title: "Roadmap", |
| 46 | icon: "R", |
| 47 | }), |
| 48 | ).toEqual({ |
| 49 | kind: "accessible", |
| 50 | interactive: true, |
| 51 | label: "Roadmap", |
| 52 | ariaLabel: "Roadmap", |
| 53 | icon: "R", |
| 54 | showFallbackIcon: false, |
| 55 | }); |
| 56 | }); |
| 57 | |
| 58 | it("falls back to Untitled for accessible mentions without a resolved title", () => { |
| 59 | expect( |
| 60 | getPageMentionViewState({ |
| 61 | status: "resolved", |
| 62 | source: "server", |
| 63 | accessible: true, |
| 64 | title: null, |
| 65 | icon: null, |
| 66 | }), |
| 67 | ).toEqual({ |
| 68 | kind: "accessible", |
| 69 | interactive: true, |
| 70 | label: "Untitled", |
| 71 | ariaLabel: "Untitled", |
| 72 | icon: null, |
| 73 | showFallbackIcon: true, |
| 74 | }); |
| 75 | }); |
| 76 | }); |