@estiva-app/ui 0.84.0 → 0.86.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/CommentBox.d.ts +1 -1
  2. package/dist/CommentBox.d.ts.map +1 -1
  3. package/dist/{ComposeBox.d.ts → commentBoxFrame.d.ts} +32 -13
  4. package/dist/commentBoxFrame.d.ts.map +1 -0
  5. package/dist/editor.d.ts +0 -1
  6. package/dist/editor.d.ts.map +1 -1
  7. package/dist/editor.js +316 -292
  8. package/dist/editor.js.map +4 -4
  9. package/dist/eslint/index.js +594 -559
  10. package/dist/eslint/index.js.map +4 -4
  11. package/dist/eslint/no-hand-rolled-behaviour.d.ts.map +1 -1
  12. package/dist/index.d.ts +1 -0
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +150 -0
  15. package/dist/index.js.map +4 -4
  16. package/dist/linkedFrom.d.ts +83 -0
  17. package/dist/linkedFrom.d.ts.map +1 -0
  18. package/dist/looks.d.ts +1 -1
  19. package/package.json +1 -1
  20. package/registry.json +42 -128
  21. package/src/CommentBox.mdx +4 -3
  22. package/src/CommentBox.stories.tsx +3 -0
  23. package/src/CommentBox.test.tsx +15 -0
  24. package/src/CommentBox.tsx +39 -32
  25. package/src/LinkCard.mdx +1 -0
  26. package/src/{ComposeBox.tsx → commentBoxFrame.tsx} +61 -27
  27. package/src/editor.ts +1 -1
  28. package/src/eslint/no-hand-rolled-behaviour.test.ts +27 -0
  29. package/src/eslint/no-hand-rolled-behaviour.ts +44 -0
  30. package/src/index.ts +9 -0
  31. package/src/linkedFrom.test.tsx +193 -0
  32. package/src/linkedFrom.ts +286 -0
  33. package/src/looks.ts +1 -1
  34. package/src/registry/app.test.ts +3 -4
  35. package/src/registry/registry.test.ts +5 -5
  36. package/stories/Choosing.mdx +0 -1
  37. package/dist/ComposeBox.d.ts.map +0 -1
  38. package/src/ComposeBox.mdx +0 -58
  39. package/src/ComposeBox.stories.tsx +0 -81
@@ -1,3 +1,4 @@
1
+ // @estiva-escape(component-has-a-page, component-has-a-story): CommentBox's own frame, not offered to apps — CommentBox's page and stories show it (Katerina, 21 Oct: one box)
1
2
  import { useCallback, useEffect, useState, type ReactNode } from 'react'
2
3
  import { Extension } from '@tiptap/core'
3
4
  import { EditorContent, type Editor } from '@tiptap/react'
@@ -12,14 +13,15 @@ import { SelectionToolbar, type SelectionToolbarProps } from './SelectionToolbar
12
13
  import { isSuggestionActive } from './suggestionPopup'
13
14
 
14
15
  /**
15
- * The box a message, a reply or a comment is written in, from Katerina's Leaf
16
- * prototype (9 October). Peek's `ComposeBox`, its look and its keys, with
17
- * what only Peek knows left in Peek: drafts, uploads, highlights, its text
18
- * format. The app makes the editor (its extensions are its own) and adds
19
- * `ComposeKeys`; this draws the box around it and sends.
16
+ * The frame `CommentBox` writes in, from Katerina's Leaf prototype (9
17
+ * October): the text, scrolling in a `ScrollArea` past half the window, the
18
+ * bar down its left while it is marked, what is attached, and a footer. The
19
+ * send box and the edit box are this one frame with different footers, so a
20
+ * change to the box is made once (Katerina, 21 Oct: the scrollbar had to be
21
+ * fixed in two copies). It was `ComposeBox`, a part of its own until 0.85.0;
22
+ * no app used it, and two box names invited the wrong pick.
20
23
  */
21
24
 
22
- /** The editor's own classes inside the box: Peek's, rich text with no outline. Put them in `editorProps.attributes.class`. */
23
25
  /** The classes the box's editor wears: rich text with no outline. It never scrolls itself; the box does, in a `ScrollArea`. */
24
26
  export const COMPOSE_EDITOR_CLASSES = richTextClassName('default', 'outline-none w-full bg-transparent min-h-[20px] [&>p+p]:-mt-1')
25
27
 
@@ -86,8 +88,45 @@ export function isEmptyDoc(editor: Editor): boolean {
86
88
  return empty
87
89
  }
88
90
 
89
- export interface ComposeBoxProps {
90
- /** The app's editor, with `ComposeKeys` in its extensions and `COMPOSE_EDITOR_CLASSES` on it. `null` while it loads. */
91
+ export interface BoxFrameProps {
92
+ /** The box's editor, with `ComposeKeys` in its extensions and `COMPOSE_EDITOR_CLASSES` on it. `null` while it loads. */
93
+ editor: Editor | null
94
+ /** The bar down the text's left: an urgent mention or a highlight, as Peek draws it. */
95
+ marked?: boolean
96
+ /** The selection strip over the text, with these buttons. Absent, no strip (the edit box). */
97
+ selection?: Pick<SelectionToolbarProps, 'marks' | 'link' | 'actions'>
98
+ /** Said while the text is empty: words, and a `Kbd` where a key helps. */
99
+ placeholder?: ReactNode
100
+ empty?: boolean
101
+ /** What is attached, under the text: `AttachmentCard pending`s. */
102
+ attachments?: ReactNode
103
+ /** The row under it all: the tools and Send, or the keys and Cancel/Save. */
104
+ footer: ReactNode
105
+ /** On the box itself. */
106
+ className?: string
107
+ }
108
+
109
+ /** The one frame both boxes draw: the bordered box, its text in a `ScrollArea`, what is attached, the footer. */
110
+ export function BoxFrame({ editor, marked = false, selection, placeholder, empty = false, attachments, footer, className }: BoxFrameProps) {
111
+ return (
112
+ <div className={cn(WRITING_BOX_CLASSES, 'focus-within:border-border-strong transition-colors', className)}>
113
+ <div data-composer-editor data-marked={marked || undefined} className={cn('relative min-h-[20px] transition-all', marked && 'border-l-4 border-border-strong pl-2')}>
114
+ <ScrollArea className={COMPOSE_SCROLL_CLASSES.area} viewportClassName={COMPOSE_SCROLL_CLASSES.viewport} contentClassName={COMPOSE_SCROLL_CLASSES.content}>
115
+ <EditorContent editor={editor} />
116
+ </ScrollArea>
117
+ {selection && <SelectionToolbar editor={editor} {...selection} />}
118
+ {empty && placeholder != null && (
119
+ <div className="pointer-events-none absolute inset-0 flex flex-wrap items-center gap-1 text-body-2 text-text-muted">{placeholder}</div>
120
+ )}
121
+ </div>
122
+ {attachments && <div className="flex flex-wrap gap-2">{attachments}</div>}
123
+ {footer}
124
+ </div>
125
+ )
126
+ }
127
+
128
+ export interface SendBoxProps {
129
+ /** The box's editor. `null` while it loads. */
91
130
  editor: Editor | null
92
131
  /**
93
132
  * Send what is written. The box empties afterwards — unless this returns
@@ -112,11 +151,10 @@ export interface ComposeBoxProps {
112
151
  }
113
152
 
114
153
  /**
115
- * The box for writing: the text, the selection strip over it, what is
116
- * attached, the tools and Send. Enter sends (`ComposeKeys`), and so does the
117
- * button.
154
+ * The send box: the frame with the selection strip over the text, the tools
155
+ * and Send under it. Enter sends (`ComposeKeys`), and so does the button.
118
156
  */
119
- export function ComposeBox({ editor, onSend, placeholder, tools, attachments, ready = false, holding = false, marked = false, selection, className }: ComposeBoxProps) {
157
+ export function SendBox({ editor, onSend, placeholder, tools, attachments, ready = false, holding = false, marked = false, selection, className }: SendBoxProps) {
120
158
  const [empty, setEmpty] = useState(true)
121
159
  const canSend = (!empty || ready) && !holding
122
160
 
@@ -151,20 +189,15 @@ export function ComposeBox({ editor, onSend, placeholder, tools, attachments, re
151
189
 
152
190
  return (
153
191
  <div className={cn('relative', className)}>
154
- <div className={cn(WRITING_BOX_CLASSES, 'focus-within:border-border-strong transition-colors')}>
155
- <div data-composer-editor data-marked={marked || undefined} className={cn('relative min-h-[20px] transition-all', marked && 'border-l-4 border-border-strong pl-2')}>
156
- <ScrollArea className={COMPOSE_SCROLL_CLASSES.area} viewportClassName={COMPOSE_SCROLL_CLASSES.viewport} contentClassName={COMPOSE_SCROLL_CLASSES.content}>
157
- <EditorContent editor={editor} />
158
- </ScrollArea>
159
- <SelectionToolbar editor={editor} {...selection} />
160
- {empty && (
161
- <div className="pointer-events-none absolute inset-0 flex flex-wrap items-center gap-1 text-body-2 text-text-muted">{placeholder}</div>
162
- )}
163
- </div>
164
-
165
- {attachments && <div className="flex flex-wrap gap-2">{attachments}</div>}
166
-
167
- {/* The tools are one strip — one Tab stop, arrows along it; Send, the answer rather than a tool, keeps its own. */}
192
+ <BoxFrame
193
+ editor={editor}
194
+ marked={marked}
195
+ selection={selection ?? {}}
196
+ placeholder={placeholder}
197
+ empty={empty}
198
+ attachments={attachments}
199
+ footer={
200
+ // The tools are one strip — one Tab stop, arrows along it; Send, the answer rather than a tool, keeps its own.
168
201
  <div className="flex items-center justify-between">
169
202
  {tools ? (
170
203
  <Toolbar aria-label="Compose tools" surface={false} className="flex items-center gap-1">
@@ -195,7 +228,8 @@ export function ComposeBox({ editor, onSend, placeholder, tools, attachments, re
195
228
  </IconButton>
196
229
  </div>
197
230
  </div>
198
- </div>
231
+ }
232
+ />
199
233
  </div>
200
234
  )
201
235
  }
package/src/editor.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  * `Toolbar`, `MenuItem`, `SuggestionMenu` — is the main entry's own, not a copy.
9
9
  */
10
10
  export { KeptSelection, SelectionToolbar, keepSelection, releaseSelection, normalizeHref, type MarkId, type SelectionAction, type SelectionToolbarProps } from './SelectionToolbar'
11
- export { ComposeBox, ComposeKeys, COMPOSE_EDITOR_CLASSES, type ComposeBoxProps } from './ComposeBox'
11
+
12
12
  export {
13
13
  CommentBox,
14
14
  commentBoxRows,
@@ -39,6 +39,13 @@ tester.run('no-hand-rolled-behaviour', noHandRolledBehaviour, {
39
39
  name: 'a global listener kept with its reason',
40
40
  code: 'export function probe() {\n // @estiva-escape(no-hand-rolled-behaviour): the frame measures the window, which no floating part owns\n window.addEventListener("resize", () => {})\n}\n',
41
41
  },
42
+ { name: "the package's ScrollArea, its cap on the viewport", code: 'export const Probe = () => <ScrollArea viewportClassName="max-h-[50vh]" />\n' },
43
+ { name: 'a box that clips, which draws no bar', code: 'export const Probe = () => <div className="overflow-hidden" />\n' },
44
+ { name: 'the class named in a comment', code: '// a hand-made overflow-y-auto box never scrolled\nexport const Probe = () => null\n' },
45
+ {
46
+ name: 'a scroll class kept with its reason',
47
+ code: "// @estiva-escape(no-hand-rolled-behaviour): a probe that keeps the browser bar on purpose\nexport const PROBE_CLASSES = 'overflow-y-auto'\n",
48
+ },
42
49
  ],
43
50
  invalid: [
44
51
  {
@@ -66,5 +73,25 @@ tester.run('no-hand-rolled-behaviour', noHandRolledBehaviour, {
66
73
  code: 'export function probe() {\n document.addEventListener("keydown", () => {})\n}\n',
67
74
  errors: [{ messageId: 'listener', data: { event: 'keydown', target: 'document' } }],
68
75
  },
76
+ {
77
+ name: "the comment box's long draft, as the review of 0.83 found it",
78
+ code: "export const COMPOSE_EDITOR_CLASSES = 'outline-none max-h-[50vh] overflow-y-auto'\n",
79
+ errors: [{ messageId: 'scroll', data: { what: 'overflow-y-auto' } }],
80
+ },
81
+ {
82
+ name: 'a scroll class in a className, behind a variant',
83
+ code: 'export const Probe = () => <div className="[&_pre]:overflow-x-auto" />\n',
84
+ errors: [{ messageId: 'scroll', data: { what: '[&_pre]:overflow-x-auto' } }],
85
+ },
86
+ {
87
+ name: 'a scroll class in a template',
88
+ code: 'export const probe = (h: string) => `max-h-${h} overflow-auto`\n',
89
+ errors: [{ messageId: 'scroll', data: { what: 'overflow-auto' } }],
90
+ },
91
+ {
92
+ name: 'a style that scrolls',
93
+ code: "export const Probe = () => <div style={{ overflowY: 'scroll' }} />\n",
94
+ errors: [{ messageId: 'scroll', data: { what: "overflowY: 'scroll'" } }],
95
+ },
69
96
  ],
70
97
  })
@@ -1,5 +1,6 @@
1
1
  import type { Rule } from 'eslint'
2
2
  import { ESCAPE_MESSAGES, isEscaped } from './escape'
3
+ import { SCROLL_CLASS, utilityOf } from './no-rebuilt-behaviour'
3
4
 
4
5
  /**
5
6
  * Behaviour Base UI already owns, written by hand inside the package (UIG-5,
@@ -17,6 +18,12 @@ import { ESCAPE_MESSAGES, isEscaped } from './escape'
17
18
  * - **a listener on `window` or `document`** for the events a floating part
18
19
  * lives on — resize, scroll, an outside press, a key. Base UI's Positioner
19
20
  * follows the anchor and its Root closes on an outside press and on Escape.
21
+ * - **a box that scrolls with the browser's bar**: `overflow-auto`,
22
+ * `overflow-y-scroll`… in any string, or `overflow: 'auto'` in a style. The
23
+ * apps' rule (`no-rebuilt-behaviour`) refuses it and names `ScrollArea`; until
24
+ * 21 Oct nothing refused it here, and a part's own box drew the browser's bar
25
+ * in every app (the comment box's long draft, Katerina's review of 0.83).
26
+ * `ScrollArea` is Base UI's, so it needs no such class itself.
20
27
  *
21
28
  * What it deliberately does not try to read: measuring arithmetic. `Popover`
22
29
  * hands Base UI a virtual anchor with a `getBoundingClientRect`, which is the
@@ -76,11 +83,48 @@ export const noHandRolledBehaviour: Rule.RuleModule = {
76
83
  'A portal written by hand. Base UI\'s parts carry their own (Popover, Menu, Select, Tooltip, Dialog, Toast): use the part, or say why this one stays.',
77
84
  listener:
78
85
  'A `{{event}}` listener on `{{target}}`. A floating part follows its anchor and closes on an outside press and on Escape by itself (Base UI Positioner and Root): use the part, or say why this one stays.',
86
+ scroll:
87
+ '`{{what}}` scrolls with the browser\'s own bar, and some browsers draw none. Put what grows in a ScrollArea, with a `max-h-*` cap on its viewport (`viewportClassName`), or say why this one stays.',
79
88
  ...ESCAPE_MESSAGES,
80
89
  },
81
90
  },
82
91
  create(context) {
92
+ const reported = new Set<string>()
93
+ const scroll = (node: Rule.Node, what: string) => {
94
+ // The escape sits above the whole line: `export const …` puts the declaration inside the export.
95
+ let at = statement(node as unknown as CallExpression)
96
+ for (let p: Rule.Node | null = node.parent; p; p = p.parent) {
97
+ if (p.range?.[0] === at.range[0] && p.range?.[1] === at.range[1]) {
98
+ if (p.parent && /^Export/.test(p.parent.type) && p.parent.loc && p.parent.range) at = { loc: p.parent.loc, range: p.parent.range }
99
+ break
100
+ }
101
+ }
102
+ const key = `${at.range[0]}:${what}`
103
+ if (reported.has(key) || isEscaped(context, at)) return
104
+ reported.add(key)
105
+ context.report({ loc: (node as unknown as Node).loc, messageId: 'scroll', data: { what } })
106
+ }
107
+ const classTokens = (node: Rule.Node, value: string) => {
108
+ for (const token of value.split(/\s+/)) if (token && SCROLL_CLASS.test(utilityOf(token))) scroll(node, token)
109
+ }
83
110
  return {
111
+ Literal(node: Rule.Node) {
112
+ const literal = node as unknown as { value: unknown; parent?: { type: string } }
113
+ if (typeof literal.value !== 'string') return
114
+ if (literal.parent && /^(Import|Export)|^TSLiteralType$|^TSExternalModuleReference$/.test(literal.parent.type)) return
115
+ classTokens(node, literal.value)
116
+ },
117
+ TemplateElement(node: Rule.Node) {
118
+ const cooked = (node as unknown as { value: { cooked: string | null } }).value.cooked
119
+ if (cooked) classTokens(node, cooked)
120
+ },
121
+ Property(node: Rule.Node) {
122
+ const property = node as unknown as { key: { type: string; name?: string; value?: unknown }; value: { type: string; value?: unknown } }
123
+ const name = property.key.type === 'Identifier' ? property.key.name : typeof property.key.value === 'string' ? property.key.value : undefined
124
+ if (!name || !/^overflow[XY]?$/.test(name)) return
125
+ const setting = property.value.type === 'Literal' ? property.value.value : undefined
126
+ if (setting === 'auto' || setting === 'scroll') scroll(node, `${name}: '${setting}'`)
127
+ },
84
128
  ImportDeclaration(node: Rule.Node) {
85
129
  const declaration = node as unknown as ImportDeclaration
86
130
  if (declaration.source.value !== 'react-dom') return
package/src/index.ts CHANGED
@@ -103,6 +103,15 @@ export {
103
103
  type StatusColour,
104
104
  type UnavailableMemory,
105
105
  } from './linked'
106
+ export {
107
+ linkedFrom,
108
+ linkStateFrom,
109
+ type LinkedAction,
110
+ type LinkedFromOptions,
111
+ type LinkedProfile,
112
+ type LinkedSlot,
113
+ type LinkedSource,
114
+ } from './linkedFrom'
106
115
  export { CommentCount, LinkedIcon, LinkKey, LinkPickers, ProgressRing, StatusMark, type LinkPickersProps } from './LinkParts'
107
116
  export { LinkChip, type LinkChipProps } from './LinkChip'
108
117
  export { LinkRow, LinkUnavailable, type LinkRowProps, type LinkUnavailableProps } from './LinkRow'
@@ -0,0 +1,193 @@
1
+ // @vitest-environment jsdom
2
+ /**
3
+ * One file, one card, in every app (5ebf2756): what the card built from
4
+ * interop's projection shows — its key, its most recently changed items and
5
+ * how many of all of them are done, pickers for a reader who may change it,
6
+ * words for an archived file and for one whose app shares no control.
7
+ */
8
+ import { cleanup, render, screen, within } from '@testing-library/react'
9
+ import userEvent from '@testing-library/user-event'
10
+ import { afterEach, describe, expect, it, vi } from 'vitest'
11
+ import { LinkCard } from './LinkCard'
12
+ import { LinkChip } from './LinkChip'
13
+ import { linkStateFrom, type LinkedFromOptions, type LinkedSource } from './linkedFrom'
14
+
15
+ afterEach(cleanup)
16
+
17
+ const OWNER = 'a'.repeat(64)
18
+ const OTHER = 'b'.repeat(64)
19
+ const PEOPLE = { [OWNER]: { displayName: 'Person one' }, [OTHER]: { displayName: 'Person two' } }
20
+
21
+ const STATUSES = [
22
+ { value: 'todo', label: 'Todo', colour: 'neutral' },
23
+ { value: 'doing', label: 'Doing', colour: 'blue' },
24
+ { value: 'done', label: 'Done', colour: 'green' },
25
+ { value: 'dropped', label: 'Dropped', colour: 'muted' },
26
+ ]
27
+
28
+ function item(n: number, status: (typeof STATUSES)[number], changedAt: number): LinkedSource {
29
+ return {
30
+ ref: `2:${OWNER}:item-${n}`,
31
+ address: `2:${OWNER}:item-${n}`,
32
+ kind: 2,
33
+ widget: 'row',
34
+ slots: { title: { value: `Item ${n}`, field: 'title' }, status: { value: status.label, colour: status.colour, field: 'status' } },
35
+ meta: [
36
+ { value: `ABC-${n}`, field: 'ref' },
37
+ { value: OWNER, field: 'assignee', isPubkey: true, label: 'Assignee' },
38
+ ],
39
+ people: PEOPLE,
40
+ actions: [],
41
+ changedAt,
42
+ }
43
+ }
44
+
45
+ const [TODO, DOING, DONE, DROPPED] = STATUSES
46
+
47
+ /** Nine items: 3 done, 1 dropped. Items 8 and 9 changed in the same second. */
48
+ const ITEMS = [
49
+ item(1, DONE, 100),
50
+ item(2, DONE, 200),
51
+ item(3, TODO, 900),
52
+ item(4, DOING, 400),
53
+ item(5, DROPPED, 500),
54
+ item(6, TODO, 600),
55
+ item(7, DONE, 50),
56
+ item(9, TODO, 800),
57
+ item(8, DOING, 800),
58
+ ]
59
+
60
+ const GROUP: LinkedSource = {
61
+ ref: `1:${OWNER}:group`,
62
+ address: `1:${OWNER}:group`,
63
+ kind: 1,
64
+ widget: 'card',
65
+ slots: {
66
+ title: { value: 'Group one', field: 'title' },
67
+ subtitle: { value: 'What the group is for.' },
68
+ status: { value: 'Doing', colour: 'blue', field: 'status' },
69
+ },
70
+ meta: [
71
+ { value: 'ABC', field: 'key' },
72
+ { value: OWNER, field: 'lead', isPubkey: true, label: 'Lead' },
73
+ ],
74
+ children: ITEMS,
75
+ people: PEOPLE,
76
+ actions: [
77
+ { id: 'set-status', label: 'Status', control: 'select', field: 'status', current: 'doing', options: STATUSES },
78
+ { id: 'set-lead', label: 'Lead', control: 'pubkey', field: 'lead', current: OWNER },
79
+ ],
80
+ }
81
+
82
+ const options = (more: Partial<LinkedFromOptions> = {}): LinkedFromOptions => ({
83
+ hrefOf: (object, top) => `#${top ? 'top' : 'row'}-${object.address}`,
84
+ previewText: (body) => body.replace(/\*/g, ''),
85
+ directory: PEOPLE,
86
+ ...more,
87
+ })
88
+
89
+ const UNREAD = { kind: 'file' as const, noun: 'File' }
90
+
91
+ const rowTitles = () =>
92
+ screen
93
+ .getAllByRole('link')
94
+ .map((link) => link.textContent ?? '')
95
+ .filter((text) => /^ABC-\d/.test(text) || /^Item \d/.test(text))
96
+
97
+ describe('a card built from interop’s projection', () => {
98
+ it('lists the 7 most recently changed items, newest first, a tie going to the address', () => {
99
+ render(<LinkCard link={linkStateFrom(GROUP, UNREAD, options())} />)
100
+ const rows = rowTitles().map((text) => text.match(/Item \d/)?.[0])
101
+ expect(rows).toEqual(['Item 3', 'Item 8', 'Item 9', 'Item 6', 'Item 5', 'Item 4', 'Item 2'])
102
+ })
103
+
104
+ it('keeps the order it was given when nothing says when an item changed', () => {
105
+ const unknown = ITEMS.map(({ changedAt: _, ...rest }) => rest)
106
+ render(<LinkCard link={linkStateFrom({ ...GROUP, children: unknown }, UNREAD, options())} />)
107
+ const rows = rowTitles().map((text) => text.match(/Item \d/)?.[0])
108
+ expect(rows).toEqual(['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5', 'Item 6', 'Item 7'])
109
+ })
110
+
111
+ it('counts every item in its ring, listed or not, a dropped one in the total and not as done', () => {
112
+ render(<LinkCard link={linkStateFrom(GROUP, UNREAD, options())} />)
113
+ expect(screen.getByText('3/9')).toBeTruthy()
114
+ })
115
+
116
+ it('shows its key before its title, in the card and in the chip', () => {
117
+ render(<LinkCard link={linkStateFrom(GROUP, UNREAD, options())} />)
118
+ expect(screen.getByText('ABC')).toBeTruthy()
119
+ cleanup()
120
+ render(<LinkChip link={linkStateFrom(GROUP, UNREAD, options())} />)
121
+ expect(screen.getByText('ABC')).toBeTruthy()
122
+ })
123
+
124
+ it('lets a reader who may change it pick a status and a lead, through the app’s own actions', async () => {
125
+ const user = userEvent.setup()
126
+ const onAct = vi.fn()
127
+ render(<LinkCard link={linkStateFrom(GROUP, UNREAD, options({ onAct }))} />)
128
+ await user.click(screen.getByRole('combobox', { name: 'Status' }))
129
+ await user.click(await screen.findByRole('option', { name: /Done/ }))
130
+ expect(onAct).toHaveBeenCalledWith('set-status', 'done')
131
+ await user.click(screen.getByRole('combobox', { name: 'Lead' }))
132
+ await user.click(await screen.findByRole('option', { name: /Person two/ }))
133
+ expect(onAct).toHaveBeenCalledWith('set-lead', OTHER)
134
+ })
135
+
136
+ it('shows an archived file’s status and lead as words, even to a reader who could change them', () => {
137
+ render(<LinkCard link={linkStateFrom({ ...GROUP, archived: { by: OWNER, at: 1 } }, UNREAD, options({ onAct: vi.fn() }))} />)
138
+ expect(screen.queryByRole('combobox')).toBeNull()
139
+ expect(screen.getAllByText('Doing').length).toBeGreaterThan(0)
140
+ })
141
+
142
+ it('names the owner as words when the file’s app shares no control for it', () => {
143
+ const card = render(<LinkCard link={linkStateFrom({ ...GROUP, children: [], actions: [] }, UNREAD, options({ onAct: vi.fn() }))} />)
144
+ expect(screen.queryByRole('combobox')).toBeNull()
145
+ expect(within(card.container).getByText('Person one')).toBeTruthy()
146
+ })
147
+
148
+ it('opens the file and each row where the app says', () => {
149
+ render(<LinkCard link={linkStateFrom(GROUP, UNREAD, options())} />)
150
+ expect(screen.getByRole('link', { name: /Group one/ }).getAttribute('href')).toBe(`#top-${GROUP.address}`)
151
+ expect(screen.getByRole('link', { name: /Item 3/ }).getAttribute('href')).toBe(`#row-2:${OWNER}:item-3`)
152
+ })
153
+ })
154
+
155
+ describe('a file the reader cannot read', () => {
156
+ it('is not available, and opens in its app only at an https address', () => {
157
+ const stub: LinkedSource = { ...GROUP, unreachable: true, noun: 'group', appName: 'App one', openUrl: 'https://app.example/x' }
158
+ render(<LinkCard link={linkStateFrom(stub, UNREAD, options())} />)
159
+ expect(screen.getByText(/Group — not available/)).toBeTruthy()
160
+ expect(screen.getByRole('link', { name: /App one/ }).getAttribute('href')).toBe('https://app.example/x')
161
+ cleanup()
162
+ render(<LinkCard link={linkStateFrom({ ...stub, openUrl: 'javascript:alert(1)' }, UNREAD, options())} />)
163
+ expect(screen.queryByRole('link')).toBeNull()
164
+ })
165
+
166
+ it('is named by its address when its app gives it no noun', () => {
167
+ render(<LinkCard link={linkStateFrom({ ...GROUP, unreachable: true, appName: 'App one' }, { kind: 'file', noun: 'Record' }, options())} />)
168
+ expect(screen.getByText('Record — not available.')).toBeTruthy()
169
+ })
170
+
171
+ it('reads as the address says while it loads and when nothing came back', () => {
172
+ render(<LinkCard link={linkStateFrom(null, { kind: 'file', noun: 'Record' }, options())} />)
173
+ expect(screen.getByText('Record — not available.')).toBeTruthy()
174
+ })
175
+ })
176
+
177
+ describe('a message', () => {
178
+ it('is drawn as its author’s words, through the app’s preview', () => {
179
+ const message: LinkedSource = {
180
+ ref: 'e'.repeat(64),
181
+ eventId: 'e'.repeat(64),
182
+ kind: 9,
183
+ widget: ['message', 'card'],
184
+ slots: { title: { value: OTHER, isPubkey: true, field: 'pubkey' }, body: { value: 'Ship it **today**' } },
185
+ meta: [],
186
+ people: PEOPLE,
187
+ actions: [],
188
+ }
189
+ render(<LinkCard link={linkStateFrom(message, UNREAD, options())} />)
190
+ expect(screen.getByText('Person two')).toBeTruthy()
191
+ expect(screen.getByText('Ship it today')).toBeTruthy()
192
+ })
193
+ })