@lemonriver/core 1.1.0 → 1.3.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 (98) hide show
  1. package/dist/{build-Dm7gVRhb.js → build-CSkdswfd.js} +1 -1
  2. package/dist/cli/bin.js +5 -5
  3. package/dist/{config-CubOIzrs.js → config-C5-myPY6.js} +129 -2
  4. package/dist/{dev-DgLeXPqp.js → dev-DHtYH8sw.js} +2 -2
  5. package/dist/{mcp-CjYDzcJa.js → mcp-B2UeO1un.js} +1 -1
  6. package/dist/{preview-CxXQpPk5.js → preview-C1B6-umF.js} +1 -1
  7. package/dist/{update-b1dSg_FW.js → update-DzL8fpcI.js} +1 -1
  8. package/dist/vite/index.js +1 -1
  9. package/package.json +5 -2
  10. package/release-notes.json +33 -0
  11. package/src/app/components/player.tsx +6 -1
  12. package/src/app/lemonriver/chrome/app-chrome.tsx +52 -0
  13. package/src/app/lemonriver/chrome/sidebar-extras.tsx +8 -1
  14. package/src/app/lemonriver/feedback/dialog.tsx +222 -0
  15. package/src/app/lemonriver/feedback/export.ts +21 -2
  16. package/src/app/lemonriver/feedback/first-success.ts +30 -0
  17. package/src/app/lemonriver/feedback/install.ts +18 -0
  18. package/src/app/lemonriver/feedback/model.ts +88 -0
  19. package/src/app/lemonriver/help/help-page.tsx +16 -1
  20. package/src/app/lemonriver/links.ts +16 -0
  21. package/src/app/lemonriver/present/dual-screen.ts +154 -0
  22. package/src/app/lemonriver/present/presenter-blocked-hint.tsx +28 -0
  23. package/src/app/lemonriver/present/wake-lock.ts +74 -0
  24. package/src/app/lemonriver/settings/backup-section.tsx +13 -0
  25. package/src/app/lemonriver/settings/settings-page.tsx +20 -0
  26. package/src/app/lemonriver/share/editor-share.tsx +6 -3
  27. package/src/app/lemonriver/share/share-dialog.tsx +2 -0
  28. package/src/app/lemonriver/text/en.ts +48 -0
  29. package/src/app/lemonriver/text/es.ts +45 -0
  30. package/src/app/lemonriver/text/ja.ts +44 -0
  31. package/src/app/lemonriver/text/types.ts +48 -0
  32. package/src/app/lemonriver/text/zh-cn.ts +48 -0
  33. package/src/app/lemonriver/text/zh-tw.ts +48 -0
  34. package/src/app/lemonriver/theme/pages.ts +4 -0
  35. package/src/app/lemonriver/update/release-notes.ts +22 -0
  36. package/src/app/lemonriver/update/update-prompt.tsx +28 -4
  37. package/src/app/routes/presenter.tsx +2 -0
  38. package/src/app/routes/slide.tsx +14 -1
  39. package/src/app/components/note-markdown.test.tsx +0 -42
  40. package/src/app/components/thumbnail-rail-scroll.test.ts +0 -60
  41. package/src/app/lemonriver/agent-prefs/prefs.test.ts +0 -173
  42. package/src/app/lemonriver/backup/guide.test.ts +0 -45
  43. package/src/app/lemonriver/backup/model.test.ts +0 -108
  44. package/src/app/lemonriver/backup/places.test.ts +0 -154
  45. package/src/app/lemonriver/board/blocks/classify.test.ts +0 -209
  46. package/src/app/lemonriver/board/layout.test.ts +0 -245
  47. package/src/app/lemonriver/board/model/agent-tasks.test.ts +0 -200
  48. package/src/app/lemonriver/board/model/apply-prompt.test.ts +0 -121
  49. package/src/app/lemonriver/board/model/cards.test.ts +0 -332
  50. package/src/app/lemonriver/board/model/changes.test.ts +0 -244
  51. package/src/app/lemonriver/board/model/filter.test.ts +0 -50
  52. package/src/app/lemonriver/board/model/history.test.ts +0 -71
  53. package/src/app/lemonriver/board/model/restructure.test.ts +0 -205
  54. package/src/app/lemonriver/board/model/self-check.test.ts +0 -329
  55. package/src/app/lemonriver/board/model/structure.test.ts +0 -350
  56. package/src/app/lemonriver/board/model/timing.test.ts +0 -113
  57. package/src/app/lemonriver/features.test.ts +0 -49
  58. package/src/app/lemonriver/feedback/pending-toast.test.ts +0 -44
  59. package/src/app/lemonriver/feedback/upload.test.ts +0 -26
  60. package/src/app/lemonriver/help/model.test.ts +0 -179
  61. package/src/app/lemonriver/home/brief.test.ts +0 -38
  62. package/src/app/lemonriver/home/drafts.test.ts +0 -23
  63. package/src/app/lemonriver/home/sorting.test.ts +0 -24
  64. package/src/app/lemonriver/home/time.test.ts +0 -33
  65. package/src/app/lemonriver/outline/files.test.ts +0 -90
  66. package/src/app/lemonriver/outline/model.test.ts +0 -751
  67. package/src/app/lemonriver/public-links.test.ts +0 -32
  68. package/src/app/lemonriver/routes.test.tsx +0 -54
  69. package/src/app/lemonriver/share/codes.test.ts +0 -49
  70. package/src/app/lemonriver/share/compare.test.ts +0 -199
  71. package/src/app/lemonriver/share/folder.test.ts +0 -42
  72. package/src/app/lemonriver/share/guide.test.ts +0 -78
  73. package/src/app/lemonriver/share/naming.test.ts +0 -70
  74. package/src/app/lemonriver/share/paths.test.ts +0 -116
  75. package/src/app/lemonriver/share/pdf.test.ts +0 -79
  76. package/src/app/lemonriver/templates/knobs.test.ts +0 -62
  77. package/src/app/lemonriver/templates/model.test.ts +0 -175
  78. package/src/app/lemonriver/templates/preview-content.test.ts +0 -117
  79. package/src/app/lemonriver/templates/recommend.test.ts +0 -71
  80. package/src/app/lemonriver/text/text.test.ts +0 -90
  81. package/src/app/lemonriver/theme/pages.test.ts +0 -74
  82. package/src/app/lemonriver/theme/themes.test.ts +0 -18
  83. package/src/app/lemonriver/trash/api.test.ts +0 -19
  84. package/src/app/lemonriver/update/prompt.test.ts +0 -84
  85. package/src/app/lemonriver/update/version.test.ts +0 -14
  86. package/src/app/lib/asset-filter.test.ts +0 -176
  87. package/src/app/lib/inspector/fiber.test.ts +0 -154
  88. package/src/app/lib/inspector/geometry.test.ts +0 -324
  89. package/src/app/lib/inspector/text-edit-timeline.test.ts +0 -121
  90. package/src/app/lib/note-markdown.test.ts +0 -147
  91. package/src/app/lib/pptx/css.test.ts +0 -205
  92. package/src/app/lib/pptx/ooxml.test.ts +0 -199
  93. package/src/app/lib/pptx/text-lines.test.ts +0 -82
  94. package/src/app/lib/print-ready.test.ts +0 -32
  95. package/src/app/lib/sdk.test.ts +0 -13
  96. package/src/app/lib/transition.test.ts +0 -31
  97. package/src/app/lib/use-document-title.test.ts +0 -14
  98. package/src/app/lib/utils.test.ts +0 -49
@@ -1,350 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import {
3
- addColumnAfter,
4
- type BoardColumn,
5
- chapterProgress,
6
- columnOfPosition,
7
- columnsAfterApply,
8
- columnsAfterInsert,
9
- columnsAfterMove,
10
- columnsAfterMoveMany,
11
- columnsAfterRemove,
12
- deleteColumnAt,
13
- insertPageColumn,
14
- moveColumnBlock,
15
- orderAfterColumnMove,
16
- reconcileColumns,
17
- sanitizeStructure,
18
- } from './structure.ts';
19
-
20
- const deck = (): BoardColumn[] => [
21
- { title: 'Cover', size: 2 },
22
- { title: 'Chapter 1', size: 6 },
23
- { title: 'Chapter 2', size: 8 },
24
- ];
25
-
26
- describe('columnOfPosition', () => {
27
- it('maps a deck position to the column holding it', () => {
28
- const columns = deck();
29
- expect([0, 1, 2, 7, 8, 15].map((p) => columnOfPosition(columns, p))).toEqual([
30
- 0, 0, 1, 1, 2, 2,
31
- ]);
32
- });
33
-
34
- it('skips empty columns instead of claiming a position for them', () => {
35
- const columns = [
36
- { title: 'A', size: 1 },
37
- { title: 'B', size: 0 },
38
- { title: 'C', size: 1 },
39
- ];
40
- expect(columnOfPosition(columns, 1)).toBe(2);
41
- });
42
- });
43
-
44
- describe('columnsAfterMove', () => {
45
- it('hands exactly one page over when a card crosses a boundary', () => {
46
- expect(columnsAfterMove(deck(), 2, 10).map((c) => c.size)).toEqual([2, 5, 9]);
47
- });
48
-
49
- it('leaves the structure alone when a card moves inside its own column', () => {
50
- const columns = deck();
51
- expect(columnsAfterMove(columns, 3, 6)).toBe(columns);
52
- });
53
-
54
- it('keeps a chapter together when the page that heads it moves away', () => {
55
- // The reported defect: dragging a chapter page into another chapter used to
56
- // re-group the deck, so the five pages it headed jumped column with it. The
57
- // structure is the board's own now, so only the dragged page changes column.
58
- const after = columnsAfterMove(deck(), 2, 12);
59
- expect(after.map((c) => c.size)).toEqual([2, 5, 9]);
60
- expect(after.map((c) => c.title)).toEqual(['Cover', 'Chapter 1', 'Chapter 2']);
61
- });
62
- });
63
-
64
- describe('reconcileColumns', () => {
65
- it('leaves a structure that already matches the deck', () => {
66
- expect(reconcileColumns(deck(), 16).map((c) => c.size)).toEqual([2, 6, 8]);
67
- });
68
-
69
- it('gives pages added outside the board to the last column', () => {
70
- expect(reconcileColumns(deck(), 18).map((c) => c.size)).toEqual([2, 6, 10]);
71
- });
72
-
73
- it('takes pages deleted outside the board off the end', () => {
74
- expect(reconcileColumns(deck(), 12).map((c) => c.size)).toEqual([2, 6, 4]);
75
- });
76
-
77
- it('drops trailing columns a deletion emptied rather than leaving dead labels', () => {
78
- expect(reconcileColumns(deck(), 8).map((c) => c.title)).toEqual(['Cover', 'Chapter 1']);
79
- });
80
-
81
- it('always leaves one column for a deck that still has pages', () => {
82
- expect(reconcileColumns([], 4)).toEqual([{ title: '', size: 4 }]);
83
- expect(reconcileColumns(deck(), 1).map((c) => c.size)).toEqual([1]);
84
- });
85
-
86
- it('reports no columns for an empty deck', () => {
87
- expect(reconcileColumns(deck(), 0)).toEqual([]);
88
- });
89
- });
90
-
91
- describe('sanitizeStructure', () => {
92
- it('accepts a stored structure', () => {
93
- expect(sanitizeStructure({ columns: [{ title: 'A', size: 2 }] })).toEqual({
94
- columns: [{ title: 'A', size: 2 }],
95
- });
96
- });
97
-
98
- it('refuses anything that is not a column list', () => {
99
- expect(sanitizeStructure(null)).toBeNull();
100
- expect(sanitizeStructure({})).toBeNull();
101
- expect(sanitizeStructure({ columns: 'nope' })).toBeNull();
102
- expect(sanitizeStructure({ columns: [{ title: 'A', size: -1 }] })).toBeNull();
103
- expect(sanitizeStructure({ columns: [{ title: 'A', size: 1.5 }] })).toBeNull();
104
- });
105
-
106
- it('fills in a missing title rather than dropping the column', () => {
107
- expect(sanitizeStructure({ columns: [{ size: 3 }] })).toEqual({
108
- columns: [{ title: '', size: 3 }],
109
- });
110
- });
111
- });
112
-
113
- describe('addColumnAfter', () => {
114
- it('puts an empty chapter right after the one it was asked for', () => {
115
- const next = addColumnAfter(deck(), 0, 'New');
116
- expect(next.map((c) => c.title)).toEqual(['Cover', 'New', 'Chapter 1', 'Chapter 2']);
117
- expect(next[1].size).toBe(0);
118
- });
119
-
120
- it('leaves the page count alone', () => {
121
- const before = deck();
122
- const next = addColumnAfter(before, 2, 'New');
123
- expect(next.reduce((sum, c) => sum + c.size, 0)).toBe(16);
124
- expect(before).toHaveLength(3);
125
- });
126
- });
127
-
128
- describe('deleteColumnAt', () => {
129
- it('folds the pages of a removed chapter into the one before it', () => {
130
- expect(deleteColumnAt(deck(), 1)?.map((c) => c.size)).toEqual([8, 8]);
131
- });
132
-
133
- it('folds its pages into the next chapter when it is the first one', () => {
134
- const next = deleteColumnAt(deck(), 0);
135
- expect(next?.map((c) => c.size)).toEqual([8, 8]);
136
- expect(next?.[0].title).toBe('Chapter 1');
137
- });
138
-
139
- it('refuses to remove the only chapter left', () => {
140
- expect(deleteColumnAt([{ title: 'All', size: 4 }], 0)).toBeNull();
141
- expect(deleteColumnAt(deck(), 9)).toBeNull();
142
- });
143
- });
144
-
145
- describe('moving a whole chapter', () => {
146
- it('carries its pages with it and renumbers the deck', () => {
147
- const columns = [
148
- { title: 'A', size: 2 },
149
- { title: 'B', size: 3 },
150
- { title: 'C', size: 2 },
151
- ];
152
- expect(moveColumnBlock(columns, 0, 2)?.map((c) => c.title)).toEqual(['B', 'C', 'A']);
153
- expect(orderAfterColumnMove(columns, 0, 2)).toEqual([2, 3, 4, 5, 6, 0, 1]);
154
- expect(orderAfterColumnMove(columns, 2, 0)).toEqual([5, 6, 0, 1, 2, 3, 4]);
155
- });
156
-
157
- it('is a permutation of every page, losing none', () => {
158
- const order = orderAfterColumnMove(deck(), 1, 0);
159
- expect([...order].sort((a, b) => a - b)).toEqual([...Array(16).keys()]);
160
- });
161
-
162
- it('does nothing when the chapter stays where it is', () => {
163
- expect(moveColumnBlock(deck(), 1, 1)).toBeNull();
164
- expect(orderAfterColumnMove(deck(), 1, 1)).toEqual([...Array(16).keys()]);
165
- });
166
- });
167
-
168
- describe('columnsAfterMoveMany', () => {
169
- it('moves several pages across one boundary at once', () => {
170
- const columns = [
171
- { title: 'A', size: 3 },
172
- { title: 'B', size: 3 },
173
- ];
174
- expect(columnsAfterMoveMany(columns, [0, 1], 4).map((c) => c.size)).toEqual([1, 5]);
175
- });
176
-
177
- it('leaves a column unchanged when it both gives and takes a page', () => {
178
- const columns = [
179
- { title: 'A', size: 3 },
180
- { title: 'B', size: 3 },
181
- ];
182
- expect(columnsAfterMoveMany(columns, [1], 4).map((c) => c.size)).toEqual([2, 4]);
183
- expect(columnsAfterMoveMany(columns, [2], 4).map((c) => c.size)).toEqual([2, 4]);
184
- });
185
-
186
- it('takes pages from two chapters into a third', () => {
187
- const columns = [
188
- { title: 'A', size: 2 },
189
- { title: 'B', size: 2 },
190
- { title: 'C', size: 2 },
191
- ];
192
- expect(columnsAfterMoveMany(columns, [0, 3], 5).map((c) => c.size)).toEqual([1, 1, 4]);
193
- });
194
- });
195
-
196
- describe('insertPageColumn', () => {
197
- it('drops a card into a chapter of its own between two chapters', () => {
198
- const columns = [
199
- { title: 'A', size: 2 },
200
- { title: 'B', size: 3 },
201
- ];
202
- const result = insertPageColumn(columns, 3, 1, 'New');
203
- expect(result?.columns.map((c) => [c.title, c.size])).toEqual([
204
- ['A', 2],
205
- ['New', 1],
206
- ['B', 2],
207
- ]);
208
- expect(result?.order).toEqual([0, 1, 3, 2, 4]);
209
- });
210
-
211
- it('removes the chapter its only card came from', () => {
212
- const columns = [
213
- { title: 'A', size: 1 },
214
- { title: 'B', size: 2 },
215
- ];
216
- const result = insertPageColumn(columns, 0, 1, 'New');
217
- expect(result?.columns.map((c) => [c.title, c.size])).toEqual([
218
- ['New', 1],
219
- ['B', 2],
220
- ]);
221
- expect(result?.order).toEqual([0, 1, 2]);
222
- });
223
-
224
- it('moves a card backwards through the deck as well as forwards', () => {
225
- const columns = [
226
- { title: 'A', size: 2 },
227
- { title: 'B', size: 2 },
228
- { title: 'C', size: 2 },
229
- ];
230
- const result = insertPageColumn(columns, 5, 1, 'New');
231
- expect(result?.columns.map((c) => [c.title, c.size])).toEqual([
232
- ['A', 2],
233
- ['New', 1],
234
- ['B', 2],
235
- ['C', 1],
236
- ]);
237
- expect(result?.order).toEqual([0, 1, 5, 2, 3, 4]);
238
- });
239
-
240
- it('refuses a boundary that is not between two chapters', () => {
241
- const columns = [
242
- { title: 'A', size: 2 },
243
- { title: 'B', size: 2 },
244
- ];
245
- expect(insertPageColumn(columns, 0, 0, 'New')).toBeNull();
246
- expect(insertPageColumn(columns, 0, 2, 'New')).toBeNull();
247
- expect(insertPageColumn(columns, 99, 1, 'New')).toBeNull();
248
- });
249
- });
250
-
251
- describe('column bookkeeping for batch edits', () => {
252
- const columns = [
253
- { title: 'A', size: 2 },
254
- { title: 'B', size: 3 },
255
- { title: 'C', size: 2 },
256
- ];
257
-
258
- it('takes one page off the chapter that held each removed page', () => {
259
- expect(columnsAfterRemove(columns, [0, 4, 5]).map((c) => c.size)).toEqual([1, 2, 1]);
260
- });
261
-
262
- it('empties a chapter whose pages all went, rather than borrowing a neighbour', () => {
263
- expect(columnsAfterRemove(columns, [0, 1]).map((c) => c.size)).toEqual([0, 3, 2]);
264
- });
265
-
266
- it('adds each new page to the chapter it was added beside', () => {
267
- expect(columnsAfterInsert(columns, [0, 6]).map((c) => c.size)).toEqual([3, 3, 3]);
268
- });
269
-
270
- it('cannot put an emptied chapter back from positions alone, which is why undo replays the saved list', () => {
271
- const removed = columnsAfterRemove(columns, [0, 1]);
272
- expect(columnsAfterInsert(removed, [0, 1])).not.toEqual(columns);
273
- });
274
- });
275
-
276
- describe('columnsAfterApply', () => {
277
- const before = [
278
- { title: 'Opening', keys: ['a', 'b'] },
279
- { title: 'Middle', keys: ['c'] },
280
- { title: 'End', keys: ['d'] },
281
- ];
282
-
283
- it('keeps a page the apply created right after another page in that page’s chapter', () => {
284
- expect(columnsAfterApply(before, ['a', 'a2', 'b', 'c', 'd'])).toEqual([
285
- { title: 'Opening', size: 3 },
286
- { title: 'Middle', size: 1 },
287
- { title: 'End', size: 1 },
288
- ]);
289
- });
290
-
291
- it('takes a merged page out of the chapter that held it', () => {
292
- expect(columnsAfterApply(before, ['a', 'c', 'd'])).toEqual([
293
- { title: 'Opening', size: 1 },
294
- { title: 'Middle', size: 1 },
295
- { title: 'End', size: 1 },
296
- ]);
297
- });
298
-
299
- it('gives a page added at the very front the chapter of the page behind it', () => {
300
- expect(columnsAfterApply(before, ['new', 'a', 'b', 'c', 'd']).map((c) => c.size)).toEqual([
301
- 3, 1, 1,
302
- ]);
303
- });
304
-
305
- it('keeps a chapter that lost every page, with its title', () => {
306
- expect(columnsAfterApply(before, ['a', 'b', 'd'])).toEqual([
307
- { title: 'Opening', size: 2 },
308
- { title: 'Middle', size: 0 },
309
- { title: 'End', size: 1 },
310
- ]);
311
- });
312
-
313
- it('sends every new page to the chapter named, even one that is still empty', () => {
314
- const columns = [...before.slice(0, 2), { title: 'End', keys: [] }];
315
- expect(columnsAfterApply(columns, ['a', 'b', 'c', 'n1', 'n2'], 2)).toEqual([
316
- { title: 'Opening', size: 2 },
317
- { title: 'Middle', size: 1 },
318
- { title: 'End', size: 2 },
319
- ]);
320
- });
321
-
322
- it('falls back to the deck’s new length when no page can be matched', () => {
323
- expect(columnsAfterApply(before, ['x', 'y'])).toEqual([{ title: 'Opening', size: 2 }]);
324
- });
325
- });
326
-
327
- describe('chapterProgress', () => {
328
- it('counts an empty chapter as nothing at all', () => {
329
- expect(chapterProgress({}, [])).toEqual({ done: 0, review: 0, total: 0 });
330
- });
331
-
332
- it('counts every page when the chapter is finished', () => {
333
- const cards = { A: { status: 'done' }, B: { status: 'done' } } as const;
334
- expect(chapterProgress(cards, ['A', 'B'])).toEqual({ done: 2, review: 0, total: 2 });
335
- });
336
-
337
- it('separates what is done from what is waiting to be looked over', () => {
338
- const cards = {
339
- A: { status: 'done' },
340
- B: { status: 'review' },
341
- C: { status: 'doing' },
342
- } as const;
343
- expect(chapterProgress(cards, ['A', 'B', 'C'])).toEqual({ done: 1, review: 1, total: 3 });
344
- });
345
-
346
- it('does not count a page with no status as done', () => {
347
- const cards = { A: { status: 'done' }, B: { memo: 'still open' } } as const;
348
- expect(chapterProgress(cards, ['A', 'B', 'C'])).toEqual({ done: 1, review: 0, total: 3 });
349
- });
350
- });
@@ -1,113 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import type { Block } from '../blocks/classify';
3
- import {
4
- estimateSeconds,
5
- formatDuration,
6
- sanitizeTargetMinutes,
7
- speakingSeconds,
8
- } from './timing.ts';
9
-
10
- const block = (kind: Block['kind'], text = ''): Block => ({
11
- id: `${kind}-${text}`,
12
- kind,
13
- text,
14
- loc: null,
15
- box: { x: 0, y: 0, w: 0, h: 0 },
16
- });
17
-
18
- /** A run of Chinese characters, one second per four of them. */
19
- const han = (count: number) => '字'.repeat(count);
20
- const words = (count: number) => Array.from({ length: count }, (_, i) => `word${i}`).join(' ');
21
-
22
- describe('estimateSeconds', () => {
23
- it('reads Chinese by the character: 240 a minute', () => {
24
- expect(estimateSeconds({ blocks: null, notes: han(240) })).toEqual({
25
- seconds: 60,
26
- basis: 'notes',
27
- });
28
- });
29
-
30
- it('reads English by the word: 150 a minute', () => {
31
- expect(estimateSeconds({ blocks: null, notes: words(150) })).toEqual({
32
- seconds: 60,
33
- basis: 'notes',
34
- });
35
- });
36
-
37
- it('adds up a page that mixes both', () => {
38
- // Half a minute of Chinese plus half a minute of English.
39
- expect(speakingSeconds(`${han(120)} ${words(75)}`)).toBeCloseTo(60, 5);
40
- });
41
-
42
- it('gives a page with only a chart the minimum', () => {
43
- expect(estimateSeconds({ blocks: [block('chart')] })).toEqual({
44
- seconds: 15,
45
- basis: 'page',
46
- });
47
- });
48
-
49
- it('prefers the speaker notes over the words on the page', () => {
50
- const timing = estimateSeconds({ notes: han(240), blocks: [block('text', words(300))] });
51
- expect(timing).toEqual({ seconds: 60, basis: 'notes' });
52
- });
53
-
54
- it('never goes under fifteen seconds', () => {
55
- expect(estimateSeconds({ blocks: null, notes: 'Hi' }).seconds).toBe(15);
56
- expect(estimateSeconds({ blocks: [block('text', han(4))] }).seconds).toBe(15);
57
- });
58
-
59
- it('rounds to five seconds', () => {
60
- // 224 characters is 56 s, 232 is 58 s.
61
- expect(estimateSeconds({ blocks: null, notes: han(224) }).seconds).toBe(55);
62
- expect(estimateSeconds({ blocks: null, notes: han(232) }).seconds).toBe(60);
63
- });
64
-
65
- it('adds five seconds for each picture when the page is the source', () => {
66
- // 120 characters is 30 s, plus two pictures.
67
- const timing = estimateSeconds({
68
- blocks: [block('text', han(120)), block('image'), block('chart')],
69
- });
70
- expect(timing).toEqual({ seconds: 40, basis: 'page' });
71
- });
72
-
73
- it('cannot tell how long a page whose blocks were not read takes', () => {
74
- expect(estimateSeconds({ blocks: null })).toEqual({ seconds: 15, basis: 'none' });
75
- });
76
-
77
- it('falls back to the page when the notes are blank', () => {
78
- expect(estimateSeconds({ notes: ' ', blocks: [block('text', han(120))] })).toEqual({
79
- seconds: 30,
80
- basis: 'page',
81
- });
82
- });
83
- });
84
-
85
- describe('formatDuration', () => {
86
- it('writes seconds, minutes and seconds, and whole minutes', () => {
87
- expect(formatDuration(45, 'en')).toBe('45s');
88
- expect(formatDuration(80, 'en')).toBe('1m 20s');
89
- expect(formatDuration(720, 'en')).toBe('12 min');
90
- });
91
-
92
- it('writes the same in Chinese', () => {
93
- expect(formatDuration(45, 'zh-CN')).toBe('45 秒');
94
- expect(formatDuration(80, 'zh-CN')).toBe('1 分 20 秒');
95
- expect(formatDuration(720, 'zh-CN')).toBe('12 分钟');
96
- });
97
- });
98
-
99
- describe('sanitizeTargetMinutes', () => {
100
- it('keeps a whole number of minutes within an hour and a half', () => {
101
- expect(sanitizeTargetMinutes(12)).toBe(12);
102
- expect(sanitizeTargetMinutes('7')).toBe(7);
103
- expect(sanitizeTargetMinutes(180)).toBe(180);
104
- });
105
-
106
- it('refuses what cannot be a target', () => {
107
- expect(sanitizeTargetMinutes(0)).toBeNull();
108
- expect(sanitizeTargetMinutes(181)).toBeNull();
109
- expect(sanitizeTargetMinutes('')).toBeNull();
110
- expect(sanitizeTargetMinutes('soon')).toBeNull();
111
- expect(sanitizeTargetMinutes(null)).toBeNull();
112
- });
113
- });
@@ -1,49 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { isFeatureEnabled } from './features';
3
-
4
- describe('isFeatureEnabled', () => {
5
- it('opens the board in dev', () => {
6
- expect(isFeatureEnabled('board', { dev: true })).toBe(true);
7
- });
8
-
9
- it('keeps the board closed outside dev', () => {
10
- expect(isFeatureEnabled('board', { dev: false })).toBe(false);
11
- });
12
-
13
- it('returns false for an unknown feature', () => {
14
- expect(isFeatureEnabled('nope' as never, { dev: true })).toBe(false);
15
- });
16
-
17
- it('returns false when the tier is locked', () => {
18
- expect(isFeatureEnabled('board', { dev: true }, () => false)).toBe(false);
19
- });
20
-
21
- it('keeps the trash to dev, where the server that holds it runs', () => {
22
- expect(isFeatureEnabled('trash', { dev: true })).toBe(true);
23
- expect(isFeatureEnabled('trash', { dev: false })).toBe(false);
24
- });
25
-
26
- it('offers settings in a built site too', () => {
27
- expect(isFeatureEnabled('settings', { dev: false })).toBe(true);
28
- });
29
-
30
- it('keeps the guided outline to dev, where the agent it drives runs', () => {
31
- expect(isFeatureEnabled('outline', { dev: true })).toBe(true);
32
- expect(isFeatureEnabled('outline', { dev: false })).toBe(false);
33
- });
34
-
35
- it('keeps the template library to dev, where its files sit', () => {
36
- expect(isFeatureEnabled('templates', { dev: true })).toBe(true);
37
- expect(isFeatureEnabled('templates', { dev: false })).toBe(false);
38
- });
39
-
40
- it('keeps sharing to dev, where the pack and import endpoints run', () => {
41
- expect(isFeatureEnabled('share', { dev: true })).toBe(true);
42
- expect(isFeatureEnabled('share', { dev: false })).toBe(false);
43
- });
44
-
45
- it('keeps backup to dev, where the backup endpoints run', () => {
46
- expect(isFeatureEnabled('backup', { dev: true })).toBe(true);
47
- expect(isFeatureEnabled('backup', { dev: false })).toBe(false);
48
- });
49
- });
@@ -1,44 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { clearPendingToast, savePendingToast, takePendingToast } from './pending-toast';
3
-
4
- function memoryStorage(): Storage {
5
- const map = new Map<string, string>();
6
- return {
7
- get length() {
8
- return map.size;
9
- },
10
- clear: () => map.clear(),
11
- getItem: (k) => map.get(k) ?? null,
12
- key: (i) => [...map.keys()][i] ?? null,
13
- removeItem: (k) => {
14
- map.delete(k);
15
- },
16
- setItem: (k, v) => {
17
- map.set(k, v);
18
- },
19
- };
20
- }
21
-
22
- describe('pending toast', () => {
23
- it('shows once after the reload', () => {
24
- const storage = memoryStorage();
25
- savePendingToast({ kind: 'trashed', slideId: 'alpha', name: 'Alpha' }, storage);
26
- expect(takePendingToast(storage)).toEqual({ kind: 'trashed', slideId: 'alpha', name: 'Alpha' });
27
- expect(takePendingToast(storage)).toBeNull();
28
- });
29
-
30
- it('is dropped when the request fails', () => {
31
- const storage = memoryStorage();
32
- savePendingToast({ kind: 'restored', slideId: 'alpha', name: 'Alpha' }, storage);
33
- clearPendingToast(storage);
34
- expect(takePendingToast(storage)).toBeNull();
35
- });
36
-
37
- it('ignores anything it did not write', () => {
38
- const storage = memoryStorage();
39
- storage.setItem('lemonriver:pending-toast', '{"kind":"trashed","name":"x"}');
40
- expect(takePendingToast(storage)).toBeNull();
41
- storage.setItem('lemonriver:pending-toast', 'not json');
42
- expect(takePendingToast(storage)).toBeNull();
43
- });
44
- });
@@ -1,26 +0,0 @@
1
- import { describe, expect, it, vi } from 'vitest';
2
-
3
- vi.mock('sonner', () => ({ toast: { error: vi.fn() } }));
4
-
5
- import { toast } from 'sonner';
6
- import { ASSET_MAX_BYTES } from '../../../files/assets';
7
- import { en } from '../../../locale/en';
8
- import { toastUploadFailed, UPLOAD_LIMIT_BYTES } from './upload';
9
-
10
- describe('toastUploadFailed', () => {
11
- it('uses the same limit as the server', () => {
12
- expect(UPLOAD_LIMIT_BYTES).toBe(ASSET_MAX_BYTES);
13
- });
14
-
15
- it('explains a file that is too large', () => {
16
- toastUploadFailed(en, 413);
17
- expect(toast.error).toHaveBeenLastCalledWith('The file is over 25 MB', {
18
- description: 'Compress the image or pick a smaller file, then upload again.',
19
- });
20
- });
21
-
22
- it('keeps the official message for other failures', () => {
23
- toastUploadFailed(en, 500);
24
- expect(toast.error).toHaveBeenLastCalledWith('Upload failed (500)');
25
- });
26
- });