@estiva-app/ui 0.104.3 → 0.106.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estiva-app/ui",
3
- "version": "0.104.3",
3
+ "version": "0.106.0",
4
4
  "description": "Estiva's design tokens (the contract) and a small set of primitives (a convenience) for every Estiva app.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -133,8 +133,8 @@
133
133
  },
134
134
  "devDependencies": {
135
135
  "@eslint/js": "^10.0.1",
136
- "@estiva-app/conversation": "^0.22.0",
137
- "@estiva-app/protocol": "^0.45.0",
136
+ "@estiva-app/conversation": "^0.33.0",
137
+ "@estiva-app/protocol": "^0.51.0",
138
138
  "@storybook/addon-a11y": "^10.6.0",
139
139
  "@storybook/addon-docs": "^10.5.10",
140
140
  "@storybook/addon-vitest": "^10.6.0",
package/registry.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "kind": "package",
5
5
  "repo": "estiva-ui",
6
6
  "package": "@estiva-app/ui",
7
- "packageVersion": "0.104.3",
7
+ "packageVersion": "0.106.0",
8
8
  "exports": 245,
9
9
  "typeExports": 254,
10
10
  "files": null
@@ -300,7 +300,7 @@
300
300
  "kind": "component",
301
301
  "importPath": "@estiva-app/ui",
302
302
  "sourceFile": "src/ArchiveDialog.tsx",
303
- "purpose": "The question asked before archiving a file or a Folder: what goes out of the lists with it, counted, and an optional resolution.",
303
+ "purpose": "The question asked before archiving a file or a team: what goes out of the lists with it, counted, and an optional resolution.",
304
304
  "purposeFrom": "page",
305
305
  "props": [
306
306
  {
@@ -638,8 +638,8 @@
638
638
  "looks": [
639
639
  "text-caption font-medium text-text-primary truncate",
640
640
  "text-small tracking-wide leading-tight truncate",
641
+ "text-small tracking-wide leading-tight line-clamp-2 text-error-default",
641
642
  "rounded-md bg-bg-active text-text-secondary overflow-hidden",
642
- "text-small tracking-wide leading-tight truncate text-error-default",
643
643
  "text-small tracking-wide leading-tight truncate text-warning-default",
644
644
  "text-small tracking-wide leading-tight truncate text-text-secondary",
645
645
  "opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 focus-visible:opacity-100",
@@ -2883,13 +2883,7 @@
2883
2883
  "name": "reactions",
2884
2884
  "takes": "ReactionRowProps",
2885
2885
  "required": false,
2886
- "note": "Its reactions: the kit's `ReactionRow`. With `onToggle`, the strip offers React too."
2887
- },
2888
- {
2889
- "name": "reactionRefused",
2890
- "takes": "text",
2891
- "required": false,
2892
- "note": "Why the last reaction was refused, in plain words: said under the reactions."
2886
+ "note": "Its reactions: the kit's `ReactionRow`. With `onToggle`, the strip offers React too; when `onToggle` answers with a refusal, \"Not reacted: <why>.\" is said under the reactions until the next reaction here, or until the card goes."
2893
2887
  },
2894
2888
  {
2895
2889
  "name": "isNew",
@@ -7155,7 +7149,7 @@
7155
7149
  "kind": "component",
7156
7150
  "importPath": "@estiva-app/ui",
7157
7151
  "sourceFile": "src/MoveDialog.tsx",
7158
- "purpose": "Move a file to another Folder, under another file there, or both: the Folder first, then what it goes under, read when the Folder is picked.",
7152
+ "purpose": "Move a file to another team, under another file there, or both: the team first, then what it goes under, read when the team is picked.",
7159
7153
  "purposeFrom": "page",
7160
7154
  "props": [
7161
7155
  {
@@ -7222,13 +7216,13 @@
7222
7216
  "name": "folderLabel",
7223
7217
  "takes": "text",
7224
7218
  "required": false,
7225
- "note": "The Folder field's label. \"Folder\" when absent."
7219
+ "note": "The team field's label. \"Team\" when absent."
7226
7220
  },
7227
7221
  {
7228
7222
  "name": "noFolder",
7229
7223
  "takes": "text",
7230
7224
  "required": false,
7231
- "note": "Said when no Folder is offered. \"There is no other folder it can be moved to.\" when absent."
7225
+ "note": "Said when no team is offered. \"There is no other team it can be moved to.\" when absent."
7232
7226
  },
7233
7227
  {
7234
7228
  "name": "check",
@@ -9443,13 +9437,7 @@
9443
9437
  "name": "reactions",
9444
9438
  "takes": "ReactionRowProps",
9445
9439
  "required": false,
9446
- "note": "Its reactions: the kit's `ReactionRow`. With `onToggle`, the strip offers React too."
9447
- },
9448
- {
9449
- "name": "reactionRefused",
9450
- "takes": "text",
9451
- "required": false,
9452
- "note": "Why the last reaction was refused, in plain words: said under the reactions."
9440
+ "note": "Its reactions: the kit's `ReactionRow`. With `onToggle`, the strip offers React too; when `onToggle` answers with a refusal, \"Not reacted: <why>.\" is said under the reactions until the next reaction here, or until the card goes."
9453
9441
  },
9454
9442
  {
9455
9443
  "name": "isNew",
@@ -5,7 +5,7 @@ import * as ArchiveDialogStories from './ArchiveDialog.stories'
5
5
 
6
6
  # ArchiveDialog
7
7
 
8
- The question asked before archiving a file or a Folder: what goes out of the
8
+ The question asked before archiving a file or a team: what goes out of the
9
9
  lists with it, counted, and an optional resolution.
10
10
 
11
11
  <Canvas of={ArchiveDialogStories.AProject} />
@@ -13,7 +13,7 @@ lists with it, counted, and an optional resolution.
13
13
  ## When
14
14
 
15
15
  - Before archiving anything whose manifest declares an archive action — a
16
- topic, a project or an issue — or a Folder. Read the counts first, with
16
+ topic, a project or an issue — or a team. Read the counts first, with
17
17
  interop's `archiveImpact`, and word them: "14 issues", "2 files also in Steer".
18
18
  - Open it at once, with `hides={null}`, when the count is still on its way: it
19
19
  says it is counting, and Archive waits for it.
@@ -3,7 +3,7 @@ import { userEvent, within } from 'storybook/test'
3
3
  import { ArchiveDialog } from './ArchiveDialog'
4
4
 
5
5
  /**
6
- * The question before archiving a file or a Folder: what goes with it,
6
+ * The question before archiving a file or a team: what goes with it,
7
7
  * counted, and an optional resolution. The apps it goes out of and the last
8
8
  * line are the caller's words; these are Peek's, and Ship's in its own story.
9
9
  */
@@ -38,15 +38,15 @@ export const ATopic: Story = {
38
38
  args: { title: 'Release notes', what: 'topic', hides: [] },
39
39
  }
40
40
 
41
- /** A Folder: what only it lists goes, and what another Folder lists stays there. */
41
+ /** A team: what only it lists goes, and what another team lists stays there. */
42
42
  export const AFolder: Story = {
43
- name: 'A folder',
44
- args: { title: 'Estiva HQ', what: 'folder', hides: ['3 projects', '6 topics'], staysVisible: ['2 files also in Steer'] },
43
+ name: 'A team',
44
+ args: { title: 'Estiva HQ', what: 'team', hides: ['3 projects', '6 topics'], staysVisible: ['2 files also in Steer'] },
45
45
  }
46
46
 
47
47
  /** Opened before the count is in: it says it is counting, and Archive waits. */
48
48
  export const Counting: Story = {
49
- args: { title: 'Estiva HQ', what: 'folder', hides: null },
49
+ args: { title: 'Estiva HQ', what: 'team', hides: null },
50
50
  }
51
51
 
52
52
  /** Another app's words: the apps in its order, and its own last line. */
@@ -94,6 +94,9 @@ const TILE_CLASSES = TYPE_TILE_CLASSES
94
94
  // @estiva-escape(no-copied-look): A6 (Katerina, 24 September: record only): a 12px medium name, the text style InputChip's label also uses, not a copy of a part
95
95
  const NAME_CLASSES = 'text-caption font-medium text-text-primary truncate'
96
96
  const NOTE_CLASSES = 'text-small tracking-wide leading-tight truncate'
97
+ // A failed file's reason is what the person acts on, its limit included ("Too large: the most is 10 MB"): up to two
98
+ // lines rather than cut at the card's width (ONE-4).
99
+ const FAILED_NOTE_CLASSES = 'text-small tracking-wide leading-tight line-clamp-2 text-error-default'
97
100
 
98
101
  function TypeIcon({ name }: { name: string }) {
99
102
  const Icon = ICON_BY_EXTENSION[extensionOf(name)] ?? IconFile
@@ -414,7 +417,7 @@ export function AttachmentCard({
414
417
  <Truncating
415
418
  text={(failed || warning ? note : state === 'uploading' ? (note ?? 'Uploading…') : (note ?? sizeText)) ?? ''}
416
419
  hint={noteHint}
417
- className={cn(NOTE_CLASSES, failed ? 'text-error-default' : warning ? 'text-warning-default' : 'text-text-secondary')}
420
+ className={failed ? FAILED_NOTE_CLASSES : cn(NOTE_CLASSES, warning ? 'text-warning-default' : 'text-text-secondary')}
418
421
  />
419
422
  </div>
420
423
  {onRemove && (
@@ -65,7 +65,9 @@ const draft = composerDraft(createDraftStore(localStorage), draftKeys.thread(roo
65
65
  ```
66
66
 
67
67
  - **It speaks the editor's document.** The text a document sends, and the document an edit or a draft opens with, are `@estiva-app/conversation`'s: `composerText`, `composerDocument`, `composerDraft`. Never write marker text here.
68
- - **`send` answers.** Resolve `{ accepted: false, reason }` and the words come back with "Not sent: *reason*". A thrown send is a refusal too.
68
+ - **`send` answers.** Resolve `{ accepted: false, reason }` and the words come back with "Not sent: *why*. Your text is back in the box." A thrown send is a refusal too. Hand `reason` over as it came — the relay's words, the error, the HTTP body, or `{ cause }` for a cause of your own — never your own sentence: the box says it in `@estiva-app/conversation`'s plain words (`refusalReason`), the same in every app. `onSave` and `edit.refused` likewise ("Not saved: *why*.", and "Your changes are still in the box." while it holds something).
69
+ - **`upload` answers the same way**: `{ accepted: false, reason }` with the reason as it came (protocol's `upload failed: <status> <body>`); the file's card says `uploadRefusal`'s line. A file over the server's limit for its type (10 MB a GIF, 50 MB another picture, 100 MB anything else) is said on its card as it is picked, and never handed to `upload`.
70
+ - **An edit holding nothing**, no words and no file, cannot be saved: Save is off. One whose words are all gone but that keeps a file is saved.
69
71
  - **`label` is required**: the editor's accessible name.
70
72
  - **`insert` is the app's Insert rows**, after the shared Format section: `commentBoxRows` and the app's own. An edit drops Urgent itself (an edit makes nobody urgent); with no `upload` there is no Upload (`commentBoxRows.file` is that row).
71
73
  - **Give the box a `key` per destination.** The editor, the rows and `code` are made once, as the box opens; a new thread is a new box.
@@ -88,7 +90,8 @@ It does these by itself. Write none of them around it.
88
90
  | `[`'s rows wear the icon of the kind each address names | an icon lookup |
89
91
  | Enter and Ctrl/Cmd+Enter send; Escape cancels an edit | key handlers |
90
92
  | Holding the words until the answer, or showing the send at once | a sending state |
91
- | A refusal: the words back, and a line under the box | a toast, or putting text back |
93
+ | A refusal: the words back, and a line under the box in the plain words every app says | a toast, putting text back, or words for the relay's reasons |
94
+ | A file over the server's limit, said on its card before anything uploads | a size check |
92
95
  | The draft, written as you type and forgotten once sent | an update listener |
93
96
  | Files: picking, pasting, dropping, uploading, failing; Send waits for an upload and holds on a failed file until its ✕ removes it | a file list |
94
97
  | The card in the box, its ✕, and a ✕ forgotten once the link is taken out; a refused send puts back what ✕ took off | a card state |
@@ -11,6 +11,7 @@ import { InlineChip } from './InlineChip'
11
11
  import { Kbd } from './Kbd'
12
12
  import { LinkCard } from './LinkCard'
13
13
  import { LinkChip } from './LinkChip'
14
+ import { RELAY_SAYS, SERVER_SAYS, type RelaySays, type ServerSays } from './conversation.examples'
14
15
  import { ITEM, ITEM_NO_SUMMARY, ready } from './linked.examples'
15
16
  import { PartCard } from './PartCard'
16
17
  import { QuotedLine } from './QuotedLine'
@@ -54,24 +55,31 @@ const INSERT = [commentBoxRows.file, commentBoxRows.mention, commentBoxRows.urge
54
55
 
55
56
  const plain = (body: JSONContent): string => (body.text ?? '') + (body.content ?? []).map(plain).join(' ')
56
57
 
57
- /** A relay that answers after a moment, and refuses whatever says "refuse". */
58
- const answering = (body: JSONContent): Promise<SendAnswer> =>
59
- new Promise((resolve) =>
60
- setTimeout(() => resolve(/refuse/i.test(plain(body)) ? { accepted: false, reason: 'rate-limited, try again in a minute' } : { accepted: true }), 900),
61
- )
58
+ /** A relay that answers after a moment, and refuses whatever says "refuse", for `refusal`. */
59
+ const answering =
60
+ (refusal: RelaySays = 'Too many at once') =>
61
+ (body: JSONContent): Promise<SendAnswer> =>
62
+ new Promise((resolve) => setTimeout(() => resolve(/refuse/i.test(plain(body)) ? { accepted: false, reason: RELAY_SAYS[refusal] } : { accepted: true }), 900))
63
+
64
+ /** A relay that refuses every save, for `refusal`. */
65
+ const refusing = (refusal: RelaySays) => (): Promise<SendAnswer> => new Promise((resolve) => setTimeout(() => resolve({ accepted: false, reason: RELAY_SAYS[refusal] }), 900))
62
66
 
63
67
  /** A relay that never answers. */
64
68
  const silent = (): Promise<SendAnswer> => new Promise(() => {})
65
69
 
70
+ /** A server that takes every file, never answers, or refuses every file for `refusal`. */
66
71
  const uploads =
67
- (answer: 'ready' | 'failed' | 'never') =>
72
+ (answer: 'ready' | 'failed' | 'never', refusal: ServerSays = 'Anything else') =>
68
73
  (file: File): Promise<UploadAnswer> =>
69
74
  answer === 'never'
70
75
  ? new Promise(() => {})
71
76
  : new Promise((resolve) =>
72
- setTimeout(() => resolve(answer === 'ready' ? { accepted: true, value: file.name } : { accepted: false, reason: 'The file is larger than 20 MB.' }), 1800),
77
+ setTimeout(() => resolve(answer === 'ready' ? { accepted: true, value: file.name } : { accepted: false, reason: SERVER_SAYS[refusal] }), 1800),
73
78
  )
74
79
 
80
+ /** What the relay said, picked in the controls. */
81
+ const relayControl = { argTypes: { refusal: { control: 'select', options: Object.keys(RELAY_SAYS) } } } as const
82
+
75
83
  const PLACEHOLDER = (
76
84
  <>
77
85
  <span>Write, or type</span>
@@ -121,7 +129,7 @@ function Live({ start, ...props }: Partial<CommentBoxProps> & { start?: JSONCont
121
129
  people={PEOPLE}
122
130
  references={references}
123
131
  insert={INSERT}
124
- send={answering}
132
+ send={answering()}
125
133
  label="Write"
126
134
  placeholder={PLACEHOLDER}
127
135
  draft={kept}
@@ -176,39 +184,63 @@ export const CommandsOpen: Story = { render: () => <Live />, play: typeInto('/')
176
184
  /** Held until the relay answers: the words stay, shut. */
177
185
  export const Sending: Story = { render: () => <Live send={silent} />, play: typeInto('On its way{Enter}') }
178
186
 
179
- /** The relay said no: the words are back in the box, and a line says why. */
180
- export const Refused: Story = { render: () => <Live />, play: typeInto('Please refuse this{Enter}') }
187
+ /**
188
+ * The relay said no: the words are back in the box, and a line says why, in the same plain words in every app. Pick
189
+ * what the relay said in the controls.
190
+ */
191
+ export const Refused: StoryObj<{ refusal: RelaySays }> = {
192
+ ...relayControl,
193
+ args: { refusal: 'Too long' },
194
+ render: ({ refusal }) => <Live send={answering(refusal)} />,
195
+ play: typeInto('Please refuse this{Enter}'),
196
+ }
181
197
 
182
198
  /** Shown at once: the box empties now, and a refusal puts the words back. Write "refuse" to see it. */
183
199
  export const ShownAtOnce: Story = { render: () => <Live showsAtOnce /> }
184
200
 
185
201
  /** Editing something sent: the chips stay chips; only the keys on the left. */
186
202
  export const Editing: Story = {
187
- render: () => <Live edit={{ body: WITH_CHIPS, onCancel: () => {}, onSave: answering }} />,
203
+ render: () => <Live edit={{ body: WITH_CHIPS, onCancel: () => {}, onSave: answering() }} />,
188
204
  }
189
205
 
190
- /** A save the relay refused: "Saving…" while it waits, then a line under the box; the changes stay. */
191
- export const EditingRefused: Story = {
192
- render: () => (
193
- <Live
194
- edit={{
195
- body: WITH_CHIPS,
196
- onCancel: () => {},
197
- onSave: () => new Promise((resolve) => setTimeout(() => resolve({ accepted: false, reason: 'rate-limited, try again in a minute' }), 900)),
198
- }}
199
- />
200
- ),
206
+ /** A save the relay refused: "Saving…" while it waits, then a line under the box; the changes stay. Pick what the relay said in the controls. */
207
+ export const EditingRefused: StoryObj<{ refusal: RelaySays }> = {
208
+ ...relayControl,
209
+ args: { refusal: 'Deleted, or no longer yours to write beside' },
210
+ render: ({ refusal }) => <Live edit={{ body: WITH_CHIPS, onCancel: () => {}, onSave: refusing(refusal) }} />,
201
211
  play: typeInto('{Enter}'),
202
212
  }
203
213
 
214
+ /** An edit with nothing left in it, no words and no file: Save is off, and nothing is said. */
215
+ export const EditingEmptied: Story = {
216
+ render: () => <Live edit={{ body: { type: 'doc', content: [{ type: 'paragraph' }] }, onCancel: () => {}, onSave: answering() }} />,
217
+ }
218
+
204
219
  /** A file attached and ready: its card under the text, and Send can send it with no words. */
205
220
  export const WithAFile: Story = { render: () => <Live />, play: pickAFile }
206
221
 
207
222
  /** A file uploading: Send waits for it. */
208
223
  export const FileUploading: Story = { render: () => <Live upload={uploads('never')} />, play: pickAFile }
209
224
 
210
- /** A file that failed: it says why, Send holds, and its ✕ removes it. */
211
- export const FileFailed: Story = { render: () => <Live upload={uploads('failed')} />, play: pickAFile }
225
+ /**
226
+ * A file the server refused: its card says why, Send holds, and its ✕ removes it. Pick what the server said in the
227
+ * controls.
228
+ */
229
+ export const FileFailed: StoryObj<{ refusal: ServerSays }> = {
230
+ args: { refusal: 'Too large' },
231
+ argTypes: { refusal: { control: 'select', options: Object.keys(SERVER_SAYS) } },
232
+ render: ({ refusal }) => <Live upload={uploads('failed', refusal)} />,
233
+ play: pickAFile,
234
+ }
235
+
236
+ /** A file over the server's limit for its type (a GIF over 10 MB): its card says so at once, and nothing uploads. */
237
+ export const FileTooLarge: Story = {
238
+ render: () => <Live />,
239
+ play: async ({ canvasElement }) => {
240
+ const input = canvasElement.querySelector('input[type=file]') as HTMLInputElement
241
+ await userEvent.upload(input, new File([new Uint8Array(15 * 1024 * 1024)], 'image.gif', { type: 'image/gif' }))
242
+ },
243
+ }
212
244
 
213
245
  /** Read-only, archived: a line in the box's place. */
214
246
  export const ReadOnlyArchived: Story = { render: () => <Live closed={{ reason: 'This is archived, so nothing new can be written here.' }} /> }
@@ -307,7 +339,7 @@ export const EditingWithACard: Story = {
307
339
  edit={{
308
340
  body: { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'As in' }] }] },
309
341
  onCancel: () => {},
310
- onSave: answering,
342
+ onSave: answering(),
311
343
  }}
312
344
  />
313
345
  ),
@@ -90,13 +90,30 @@ describe('sending, held until the relay answers', () => {
90
90
  expect(screen.queryByText('Sending…')).toBeNull()
91
91
  })
92
92
 
93
- it('a refusal keeps the words in the box and says why under it', async () => {
94
- render(<Box send={async () => ({ accepted: false, reason: 'rate-limited' })} />)
93
+ it('a refusal keeps the words in the box and says why under it in plain words, never the relay’s', async () => {
94
+ render(<Box send={async () => ({ accepted: false, reason: 'invalid: content exceeds maximum size of 262144 bytes' })} />)
95
95
  await type('Hello there')
96
96
  await press('Enter')
97
97
  await settle()
98
98
  expect(editorOf().getText()).toBe('Hello there')
99
- expect(screen.getByText('Not sent: rate-limited. Your text is back in the box.')).toBeTruthy()
99
+ expect(screen.getByText('Not sent: it is too long. Your text is back in the box.')).toBeTruthy()
100
+ expect(screen.queryByText(/262144|invalid:/)).toBeNull()
101
+ })
102
+
103
+ it('a send refused as on a deleted message says you can no longer write here, not that a message was deleted', async () => {
104
+ render(<Box send={async () => ({ accepted: false, reason: 'invalid: reply target event not found' })} />)
105
+ await type('Hello there')
106
+ await press('Enter')
107
+ await settle()
108
+ expect(screen.getByText('Not sent: you can no longer write here. Your text is back in the box.')).toBeTruthy()
109
+ })
110
+
111
+ it('a send that throws says something went wrong, not the error', async () => {
112
+ render(<Box send={async () => Promise.reject(new TypeError('Failed to fetch'))} />)
113
+ await type('Hello there')
114
+ await press('Enter')
115
+ await settle()
116
+ expect(screen.getByText('Not sent: something went wrong, try again. Your text is back in the box.')).toBeTruthy()
100
117
  expect(editorOf().isEditable).toBe(true)
101
118
  })
102
119
 
@@ -182,11 +199,11 @@ describe('sending, shown at once', () => {
182
199
  await press('Enter')
183
200
  expect(editorOf().getText()).toBe('')
184
201
  expect(onSent).toHaveBeenCalledTimes(1)
185
- answer.answer({ accepted: false, reason: 'rate-limited' })
202
+ answer.answer({ accepted: false, reason: 'restricted: not a channel member' })
186
203
  await settle()
187
204
  expect(editorOf().getText()).toBe('Hello there')
188
205
  expect(onRefused).toHaveBeenCalledTimes(1)
189
- expect(screen.getByText('Not sent: rate-limited. Your text is back in the box.')).toBeTruthy()
206
+ expect(screen.getByText('Not sent: you can no longer write here. Your text is back in the box.')).toBeTruthy()
190
207
  })
191
208
  })
192
209
 
@@ -242,14 +259,44 @@ describe('editing', () => {
242
259
  expect(onCancel).toHaveBeenCalledTimes(1)
243
260
  })
244
261
 
245
- it('a refused save keeps the words and says it was not saved', async () => {
246
- render(<Box edit={{ body, onSave: async () => ({ accepted: false, reason: 'gone' }), onCancel: () => {} }} />)
262
+ it('a refused save keeps the words and says it was not saved, and why', async () => {
263
+ render(<Box edit={{ body, onSave: async () => ({ accepted: false, reason: 'invalid: edit target not found or not editable by you' }), onCancel: () => {} }} />)
247
264
  await press('Enter')
248
265
  await settle()
249
- expect(screen.getByText('Not saved: gone. Your changes are still in the box.')).toBeTruthy()
266
+ expect(screen.getByText('Not saved: this message was deleted, or you can no longer write here. Your changes are still in the box.')).toBeTruthy()
250
267
  expect(editorOf().getText()).toBe('Said before')
251
268
  })
252
269
 
270
+ it('an edit emptied of its words and files cannot be saved, and says nothing', async () => {
271
+ const onSave = vi.fn<CommentBoxEdit['onSave']>(async () => ({ accepted: true }))
272
+ render(<Box edit={{ body, onSave, onCancel: () => {} }} />)
273
+ await act(async () => {
274
+ editorOf().commands.clearContent(true)
275
+ })
276
+ expect((screen.getByRole('button', { name: 'Save' }) as HTMLButtonElement).disabled).toBe(true)
277
+ await press('Enter')
278
+ expect(onSave).not.toHaveBeenCalled()
279
+ expect(screen.queryByText(/Not saved/)).toBeNull()
280
+ })
281
+
282
+ it('an edit emptied of its words that keeps a file is saved', async () => {
283
+ const onSave = vi.fn<CommentBoxEdit['onSave']>(async () => ({ accepted: true }))
284
+ const files = [{ id: 'old', name: 'old.png', state: 'ready' as const, value: 'old-record' }]
285
+ render(<Box edit={{ body, files, writesFiles: true, onSave, onCancel: () => {} }} />)
286
+ await act(async () => {
287
+ editorOf().commands.clearContent(true)
288
+ })
289
+ expect((screen.getByRole('button', { name: 'Save' }) as HTMLButtonElement).disabled).toBe(false)
290
+ await press('Enter')
291
+ expect(onSave).toHaveBeenCalledTimes(1)
292
+ expect(onSave.mock.calls[0][1]).toMatchObject([{ value: 'old-record' }])
293
+ })
294
+
295
+ it('a refusal reopened with nothing in the box does not say the changes are still there', () => {
296
+ render(<Box edit={{ body: { type: 'doc', content: [{ type: 'paragraph' }] }, refused: 'rate-limited: slow down', onSave: async () => ({ accepted: true }), onCancel: () => {} }} />)
297
+ expect(screen.getByText('Not saved: too many at once, try again in a moment.')).toBeTruthy()
298
+ })
299
+
253
300
  it('/ offers Upload and no Urgent in an edit whose save writes files', async () => {
254
301
  render(<Box upload={async () => ({ accepted: true, value: 1 })} edit={{ body, writesFiles: true, onSave: async () => ({ accepted: true }), onCancel: () => {} }} />)
255
302
  await type(' /')
@@ -317,8 +364,8 @@ describe('editing', () => {
317
364
  })
318
365
 
319
366
  it('an edit the app reopens after a refusal says why under it as it opens', () => {
320
- render(<Box edit={{ body, refused: 'rate-limited', onSave: async () => ({ accepted: true }), onCancel: () => {} }} />)
321
- expect(screen.getByText('Not saved: rate-limited. Your changes are still in the box.')).toBeTruthy()
367
+ render(<Box edit={{ body, refused: 'rate-limited: slow down', onSave: async () => ({ accepted: true }), onCancel: () => {} }} />)
368
+ expect(screen.getByText('Not saved: too many at once, try again in a moment. Your changes are still in the box.')).toBeTruthy()
322
369
  expect(editorOf().getText()).toBe('Said before')
323
370
  })
324
371
  })
@@ -363,13 +410,13 @@ describe('files', () => {
363
410
 
364
411
  it('a failed upload says why and holds Send and Enter until its ✕ takes it off', async () => {
365
412
  const send = vi.fn<CommentBoxProps['send']>(async () => ({ accepted: true }))
366
- render(<Box send={send} upload={async () => ({ accepted: false, reason: 'too large' })} />)
413
+ render(<Box send={send} upload={async () => ({ accepted: false, reason: 'upload failed: 413 {"error":"file too large: 11534336 bytes (max 10485760)"}' })} />)
367
414
  const input = document.querySelector('input[type=file]') as HTMLInputElement
368
415
  await act(async () => {
369
416
  fireEvent.change(input, { target: { files: [new File(['x'], 'big.mov', { type: 'video/quicktime' })] } })
370
417
  })
371
418
  await settle()
372
- expect(screen.getByText('too large')).toBeTruthy()
419
+ expect(screen.getByText('Too large: the most is 10 MB')).toBeTruthy()
373
420
  expect(screen.queryByText('Uploading… Send waits for the file.')).toBeNull()
374
421
  await type('See this')
375
422
  expect(screen.getByText('Remove the file that did not upload to send.')).toBeTruthy()
@@ -386,6 +433,19 @@ describe('files', () => {
386
433
  expect(send.mock.calls[0][1]).toEqual([])
387
434
  })
388
435
 
436
+ it('a file over the server’s limit for its type says so on its card and never uploads', async () => {
437
+ const upload = vi.fn<NonNullable<CommentBoxProps['upload']>>(async () => ({ accepted: true, value: 1 }))
438
+ render(<Box upload={upload} />)
439
+ const gif = new File(['x'], 'big.gif', { type: 'image/gif' })
440
+ Object.defineProperty(gif, 'size', { value: 15 * 1024 * 1024 })
441
+ await act(async () => {
442
+ fireEvent.change(document.querySelector('input[type=file]') as HTMLInputElement, { target: { files: [gif] } })
443
+ })
444
+ expect(screen.getByText('Too large: the most is 10 MB')).toBeTruthy()
445
+ expect(screen.getByText('Remove the file that did not upload to send.')).toBeTruthy()
446
+ expect(upload).not.toHaveBeenCalled()
447
+ })
448
+
389
449
  it('an upload that arrives after the box opened offers Upload in /', async () => {
390
450
  const { rerender } = render(<Box />)
391
451
  rerender(<Box upload={async () => ({ accepted: true, value: 1 })} />)