@astryxdesign/richtext 0.7.5 → 0.7.6-canary.0bd3b37

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 (44) hide show
  1. package/package.json +19 -6
  2. package/src/CodeBlockHeaderPlugin.test.tsx +0 -100
  3. package/src/CodeSyntaxPlugin.test.tsx +0 -60
  4. package/src/MarkdownExtensionsPlugin.test.tsx +0 -279
  5. package/src/RichTextEditor.test.tsx +0 -2258
  6. package/src/TableColumnFloorPlugin.test.tsx +0 -49
  7. package/src/TableScrollRegionPlugin.test.tsx +0 -138
  8. package/src/__tests__/MarkdownParitySandbox.a11y.chromium.spec.ts +0 -2092
  9. package/src/__tests__/MarkdownPlugins.a11y.chromium.spec.ts +0 -483
  10. package/src/__tests__/MarkdownPluginsImportExport.a11y.chromium.spec.ts +0 -152
  11. package/src/__tests__/Playground.a11y.chromium.spec.ts +0 -755
  12. package/src/__tests__/RichTextCodeLanguages.a11y.chromium.spec.ts +0 -61
  13. package/src/__tests__/RichTextEditorToolbar.a11y.chromium.spec.ts +0 -113
  14. package/src/__tests__/RichTextView.a11y.chromium.spec.ts +0 -101
  15. package/src/__tests__/TableCellSelection.a11y.chromium.spec.ts +0 -380
  16. package/src/markdownAngleCodeSpans.test.ts +0 -92
  17. package/src/markdownAngleDestinations.test.ts +0 -332
  18. package/src/markdownCharacterReferences.test.ts +0 -202
  19. package/src/markdownCodeFence.test.ts +0 -195
  20. package/src/markdownCodeSpans.test.ts +0 -399
  21. package/src/markdownEscapes.test.ts +0 -234
  22. package/src/markdownExtensionSelection.test.ts +0 -102
  23. package/src/markdownExtensions.test.ts +0 -765
  24. package/src/markdownHeadingMarkers.test.ts +0 -132
  25. package/src/markdownIndentedFences.test.ts +0 -43
  26. package/src/markdownIndentedTables.test.ts +0 -43
  27. package/src/markdownListContinuation.test.ts +0 -34
  28. package/src/markdownListIndentation.test.ts +0 -235
  29. package/src/markdownListThematicBreak.test.ts +0 -31
  30. package/src/markdownListThematicBreakInside.test.ts +0 -64
  31. package/src/markdownOpenFence.test.ts +0 -35
  32. package/src/markdownOrderedList.test.ts +0 -62
  33. package/src/markdownQuoteMarkers.test.ts +0 -206
  34. package/src/markdownRefusedLinks.test.tsx +0 -193
  35. package/src/markdownSource.test.tsx +0 -750
  36. package/src/markdownSpaceRuns.test.ts +0 -204
  37. package/src/markdownSpacedBlockStarts.test.ts +0 -96
  38. package/src/markdownTabRuns.test.ts +0 -75
  39. package/src/markdownTable.test.tsx +0 -214
  40. package/src/markdownTableLinks.test.ts +0 -69
  41. package/src/markdownTaskList.test.tsx +0 -445
  42. package/src/markdownThematicBreak.test.tsx +0 -185
  43. package/src/publicSurface.test.ts +0 -42
  44. package/src/textSemantics.test.tsx +0 -368
@@ -1,483 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
- // @pr-a11y release-only
3
-
4
- /**
5
- * @file MarkdownPlugins.a11y.chromium.spec.ts
6
- * @input The built Storybook's RichText/RichTextEditor "Markdown plugins" story.
7
- * @output Real-browser proof for spec:AST-064 FR7 and FR8: a plugin node
8
- * renders the same DOM and accessibility in core Markdown, RichTextView, and
9
- * RichTextEditor, and the editor moves over, selects, deletes, restores,
10
- * copies, and pastes it as one unit.
11
- *
12
- * Run after building Storybook:
13
- * pnpm storybook:build
14
- * pnpm exec playwright test packages/richtext --project chromium
15
- */
16
-
17
- import AxeBuilder from '@axe-core/playwright';
18
- import {expect, test, type Page} from '@playwright/test';
19
- import {
20
- DEFAULT_STORYBOOK_DIR,
21
- serveStorybook,
22
- type StaticServer,
23
- } from '@astryxdesign/a11y-spec/storybook';
24
-
25
- const STORYBOOK_DIR = process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR;
26
- const STORY = 'richtext-richtexteditor--markdown-plugins';
27
-
28
- let storybook: StaticServer;
29
-
30
- test.beforeAll(async () => {
31
- storybook = await serveStorybook(STORYBOOK_DIR);
32
- });
33
-
34
- test.afterAll(async () => {
35
- await storybook?.close();
36
- });
37
-
38
- async function openStory(page: Page): Promise<string[]> {
39
- const errors: string[] = [];
40
- page.on('pageerror', error => errors.push(String(error)));
41
- page.on('console', message => {
42
- if (message.type() === 'error' && !message.text().includes('404')) {
43
- errors.push(message.text());
44
- }
45
- });
46
- await page.context().grantPermissions(['clipboard-read', 'clipboard-write'], {
47
- origin: storybook.origin,
48
- });
49
- await page.setViewportSize({width: 1440, height: 900});
50
- await page.goto(
51
- `${storybook.origin}/iframe.html?id=${STORY}&viewMode=story&globals=astryxTheme:neutral;colorMode:light;direction:ltr`,
52
- {waitUntil: 'load'},
53
- );
54
- await expect(
55
- page.locator('[data-plugin-surface="editor"] [data-mention="ada"]'),
56
- ).toBeVisible();
57
- return errors;
58
- }
59
-
60
- const surface = (page: Page, name: string) =>
61
- page.locator(`[data-plugin-surface="${name}"]`);
62
-
63
- async function markdownOutput(page: Page): Promise<string> {
64
- await page.getByRole('button', {name: 'Show Markdown'}).click();
65
- return (await page.locator('[data-markdown-output]').textContent()) ?? '';
66
- }
67
-
68
- test('a plugin node renders the same DOM and accessibility in Markdown, the view, and the editor', async ({
69
- page,
70
- }) => {
71
- const errors = await openStory(page);
72
- const html = async (name: string, selector: string) =>
73
- surface(page, name)
74
- .locator(selector)
75
- .first()
76
- .evaluate(element => element.outerHTML);
77
- for (const selector of [
78
- '[data-mention="ada"]',
79
- '[data-mention="grace"]',
80
- '[data-note]',
81
- ]) {
82
- const expected = await html('markdown', selector);
83
- expect(await html('view', selector), selector).toBe(expected);
84
- expect(await html('editor', selector), selector).toBe(expected);
85
- }
86
- for (const name of ['markdown', 'view', 'editor']) {
87
- // A node inside emphasis is drawn inside an emphasis element.
88
- await expect(
89
- surface(page, name).locator('em [data-mention="linus"]'),
90
- ).toHaveCount(1);
91
- await expect(
92
- surface(page, name).getByRole('link', {name: '@ada'}),
93
- ).toHaveAttribute('href', '#people/ada');
94
- await expect(
95
- surface(page, name).getByRole('note', {name: 'Note'}),
96
- ).toHaveText('Ship on Thursday');
97
- }
98
- // The node adds no tab stop of its own beyond the plugin's link.
99
- const decorators = surface(page, 'editor').locator(
100
- '[data-lexical-decorator="true"]',
101
- );
102
- for (const tabIndex of await decorators.evaluateAll(elements =>
103
- elements.map(element => element.getAttribute('tabindex')),
104
- )) {
105
- expect(tabIndex).toBeNull();
106
- }
107
- expect(errors).toEqual([]);
108
- });
109
-
110
- /**
111
- * The editor's own selection, as text that changes whenever it moves: its
112
- * anchor and focus, or the nodes it holds. `atLineStart` says whether it is a
113
- * caret at the start of the editor's first line.
114
- */
115
- async function editorSelection(
116
- page: Page,
117
- ): Promise<{position: string; atLineStart: boolean}> {
118
- return surface(page, 'editor')
119
- .locator('[contenteditable="true"]')
120
- .evaluate(root => {
121
- type Point = {key: string; offset: number};
122
- type LexicalNode = {__key: string; __first?: string | null};
123
- const editor = (
124
- root as HTMLElement & {
125
- __lexicalEditor?: {
126
- getEditorState(): {
127
- _nodeMap: Map<string, LexicalNode>;
128
- _selection: {
129
- anchor?: Point;
130
- focus?: Point;
131
- _nodes?: Set<string>;
132
- } | null;
133
- };
134
- };
135
- }
136
- ).__lexicalEditor;
137
- const state = editor?.getEditorState();
138
- const selection = state?._selection;
139
- if (state == null || selection == null) {
140
- return {position: 'none', atLineStart: false};
141
- }
142
- const {anchor, focus} = selection;
143
- if (anchor == null || focus == null) {
144
- return {
145
- position: `nodes ${[...(selection._nodes ?? [])].join(',')}`,
146
- atLineStart: false,
147
- };
148
- }
149
- // The first line and its first text, from the root down.
150
- const lineStart = new Set<string>();
151
- let node = state._nodeMap.get('root');
152
- while (node?.__first != null) {
153
- node = state._nodeMap.get(node.__first);
154
- if (node != null) {
155
- lineStart.add(node.__key);
156
- }
157
- }
158
- return {
159
- position: `${anchor.key}:${anchor.offset} ${focus.key}:${focus.offset}`,
160
- atLineStart:
161
- anchor.key === focus.key &&
162
- anchor.offset === 0 &&
163
- focus.offset === 0 &&
164
- lineStart.has(anchor.key),
165
- };
166
- });
167
- }
168
-
169
- /**
170
- * How many `selectionchange` events the page has delivered. The counter is a
171
- * listener added after the editor's own, so once it counts an event the editor
172
- * has handled that event too.
173
- */
174
- function selectionChanges(page: Page): Promise<number> {
175
- return page.evaluate(() => {
176
- const counted = window as Window & {selectionChanges?: number};
177
- if (counted.selectionChanges == null) {
178
- counted.selectionChanges = 0;
179
- document.addEventListener('selectionchange', () => {
180
- counted.selectionChanges = (counted.selectionChanges ?? 0) + 1;
181
- });
182
- }
183
- return counted.selectionChanges;
184
- });
185
- }
186
-
187
- /**
188
- * Presses `key` and waits until the editor has taken the move: its selection
189
- * has changed, and the page has delivered the move's `selectionchange`. The
190
- * editor ignores the `selectionchange` its own selection update causes; a key
191
- * pressed before that event arrives merges into it and is ignored with it, so
192
- * the next press must not come until the event has arrived.
193
- */
194
- async function pressAndSettle(page: Page, key: string): Promise<void> {
195
- const changes = await selectionChanges(page);
196
- const before = (await editorSelection(page)).position;
197
- await page.keyboard.press(key);
198
- await expect
199
- .poll(
200
- async () =>
201
- (await selectionChanges(page)) > changes &&
202
- (await editorSelection(page)).position !== before,
203
- )
204
- .toBe(true);
205
- }
206
-
207
- /**
208
- * Puts the caret `steps` arrow presses from the start of the editor's first
209
- * line, extending the selection when `extend` is set. Each press waits until
210
- * the editor has taken the one before (see `pressAndSettle`).
211
- */
212
- async function caretAt(
213
- page: Page,
214
- steps: number,
215
- extend = false,
216
- ): Promise<void> {
217
- await selectionChanges(page);
218
- await surface(page, 'editor')
219
- .locator('[contenteditable="true"]')
220
- .getByText('Ping', {exact: false})
221
- .first()
222
- .click();
223
- const changes = await selectionChanges(page);
224
- await page.keyboard.press('Home');
225
- await expect
226
- .poll(
227
- async () =>
228
- (await selectionChanges(page)) > changes &&
229
- (await editorSelection(page)).atLineStart,
230
- )
231
- .toBe(true);
232
- for (let index = 0; index < steps; index++) {
233
- await pressAndSettle(page, extend ? 'Shift+ArrowRight' : 'ArrowRight');
234
- }
235
- }
236
-
237
- /**
238
- * Waits until the editor's own selection holds `text`. The editor formats and
239
- * copies its selection, which follows the browser's a moment after each key.
240
- */
241
- async function expectEditorSelection(page: Page, text: string): Promise<void> {
242
- await expect
243
- .poll(() =>
244
- surface(page, 'editor')
245
- .locator('[contenteditable="true"]')
246
- .evaluate(root => {
247
- const editor = (
248
- root as HTMLElement & {
249
- __lexicalEditor?: {
250
- getEditorState(): {
251
- read<T>(fn: () => T): T;
252
- _selection: {getTextContent(): string} | null;
253
- };
254
- };
255
- }
256
- ).__lexicalEditor;
257
- const state = editor?.getEditorState();
258
- return state?.read(() => state._selection?.getTextContent());
259
- }),
260
- )
261
- .toBe(text);
262
- }
263
-
264
- test('the editor moves over, deletes, and restores a plugin node as one unit', async ({
265
- page,
266
- }) => {
267
- const errors = await openStory(page);
268
- const mention = surface(page, 'editor').locator('[data-mention="ada"]');
269
- // "Ping " is five steps. The next press selects the node alone, and one
270
- // more moves past it.
271
- await caretAt(page, 6);
272
- await expect.poll(() => editorNodeSelectionSize(page)).toBe(1);
273
- await caretAt(page, 7);
274
- await page.keyboard.type('X');
275
- expect(await markdownOutput(page)).toContain('Ping @{ada}X about');
276
- await caretAt(page, 8);
277
- // Backspace removes the X, then the whole node in one press.
278
- await page.keyboard.press('Backspace');
279
- await expect(mention).toHaveCount(1);
280
- await page.keyboard.press('Backspace');
281
- await expect(mention).toHaveCount(0);
282
- expect(await markdownOutput(page)).toContain('Ping about');
283
- await surface(page, 'editor').locator('[contenteditable="true"]').focus();
284
- await page.keyboard.press('ControlOrMeta+z');
285
- await expect(mention).toHaveCount(1);
286
- expect(await markdownOutput(page)).toContain('Ping @{ada} about');
287
- expect(errors).toEqual([]);
288
- });
289
-
290
- test('italic toggled on a range takes the plugin node in it along', async ({
291
- page,
292
- }) => {
293
- const errors = await openStory(page);
294
- const mention = surface(page, 'editor').locator('[data-mention="ada"]');
295
- const italic = surface(page, 'editor').getByRole('button', {name: 'Italic'});
296
- // Select "Ping " and the node, then make them italic.
297
- await caretAt(page, 6, true);
298
- await expectEditorSelection(page, 'Ping @{ada}');
299
- await italic.click();
300
- await expect(
301
- surface(page, 'editor').locator('em [data-mention="ada"]'),
302
- ).toHaveCount(1);
303
- expect(await markdownOutput(page)).toContain('*Ping @{ada}* about');
304
- // And back.
305
- await caretAt(page, 6, true);
306
- await expectEditorSelection(page, 'Ping @{ada}');
307
- await italic.click();
308
- await expect(
309
- surface(page, 'editor').locator('em [data-mention="ada"]'),
310
- ).toHaveCount(0);
311
- await expect(mention).toHaveCount(1);
312
- expect(await markdownOutput(page)).toContain('Ping @{ada} about');
313
- expect(errors).toEqual([]);
314
- });
315
-
316
- test('bold toggled with only a plugin node selected toggles that node', async ({
317
- page,
318
- }) => {
319
- const errors = await openStory(page);
320
- const bold = surface(page, 'editor').getByRole('button', {name: 'Bold'});
321
- const strongMention = surface(page, 'editor').locator(
322
- 'strong [data-mention="ada"]',
323
- );
324
- // From just after the node, one step back selects the node alone.
325
- await caretAt(page, 7);
326
- await page.keyboard.press('Shift+ArrowLeft');
327
- await expectEditorSelection(page, '@{ada}');
328
- await bold.click();
329
- await expect(strongMention).toHaveCount(1);
330
- expect(await markdownOutput(page)).toContain('Ping **@{ada}** about');
331
- await caretAt(page, 7);
332
- await page.keyboard.press('Shift+ArrowLeft');
333
- await expectEditorSelection(page, '@{ada}');
334
- await bold.click();
335
- await expect(strongMention).toHaveCount(0);
336
- expect(await markdownOutput(page)).toContain('Ping @{ada} about');
337
- expect(errors).toEqual([]);
338
- });
339
-
340
- test('the toolbar shows the format of a plugin node selected alone', async ({
341
- page,
342
- }) => {
343
- const errors = await openStory(page);
344
- const bold = surface(page, 'editor').getByRole('button', {name: 'Bold'});
345
- // From just after the node, one step back selects the node alone.
346
- await caretAt(page, 7);
347
- await page.keyboard.press('Shift+ArrowLeft');
348
- await expectEditorSelection(page, '@{ada}');
349
- await expect(bold).toHaveAttribute('aria-pressed', 'false');
350
- await bold.click();
351
- await expect(bold).toHaveAttribute('aria-pressed', 'true');
352
- // The text around the node is not bold, and the node still is.
353
- await caretAt(page, 2);
354
- await expect(bold).toHaveAttribute('aria-pressed', 'false');
355
- await caretAt(page, 7);
356
- await page.keyboard.press('Shift+ArrowLeft');
357
- await expectEditorSelection(page, '@{ada}');
358
- await expect(bold).toHaveAttribute('aria-pressed', 'true');
359
- expect(errors).toEqual([]);
360
- });
361
-
362
- /** How many nodes the editor's selection holds as a node selection; 0 else. */
363
- function editorNodeSelectionSize(page: Page): Promise<number> {
364
- return surface(page, 'editor')
365
- .locator('[contenteditable="true"]')
366
- .evaluate(root => {
367
- const editor = (
368
- root as HTMLElement & {
369
- __lexicalEditor?: {
370
- getEditorState(): {_selection: {_nodes?: Set<string>} | null};
371
- };
372
- }
373
- ).__lexicalEditor;
374
- return editor?.getEditorState()._selection?._nodes?.size ?? 0;
375
- });
376
- }
377
-
378
- test('a click selects a plugin node whole, with the focus ring, to format or delete it', async ({
379
- page,
380
- }) => {
381
- const errors = await openStory(page);
382
- const mention = surface(page, 'editor')
383
- .locator('[contenteditable="true"] [data-markdown-extension]')
384
- .first();
385
- await expect(mention).toHaveCSS('outline-style', 'none');
386
- await mention.click();
387
- await expect.poll(() => editorNodeSelectionSize(page)).toBe(1);
388
- await expectEditorSelection(page, '@{ada}');
389
- await expect(mention).not.toHaveCSS('outline-style', 'none');
390
- await page.keyboard.press('ControlOrMeta+b');
391
- expect(await markdownOutput(page)).toContain('Ping **@{ada}** about');
392
- // A click in the text takes the selection, and the ring, off the node.
393
- await caretAt(page, 2);
394
- await expect.poll(() => editorNodeSelectionSize(page)).toBe(0);
395
- await expect(mention).toHaveCSS('outline-style', 'none');
396
- await mention.click();
397
- await expect.poll(() => editorNodeSelectionSize(page)).toBe(1);
398
- await page.keyboard.press('Backspace');
399
- expect(await markdownOutput(page)).toContain('Ping about');
400
- expect(errors).toEqual([]);
401
- });
402
-
403
- test('the toolbar shows the format of a plugin node selected with a click', async ({
404
- page,
405
- }) => {
406
- const errors = await openStory(page);
407
- const bold = surface(page, 'editor').getByRole('button', {name: 'Bold'});
408
- const mention = surface(page, 'editor')
409
- .locator('[contenteditable="true"] [data-markdown-extension]')
410
- .first();
411
- // Bold text, with the caret in it.
412
- await surface(page, 'editor')
413
- .locator('[contenteditable="true"]')
414
- .getByText('Ping', {exact: false})
415
- .first()
416
- .click();
417
- await page.keyboard.press('ControlOrMeta+b');
418
- await page.keyboard.type('Z');
419
- await expect(bold).toHaveAttribute('aria-pressed', 'true');
420
- // A click on the plain node shows the node's own format.
421
- await mention.click();
422
- await expect.poll(() => editorNodeSelectionSize(page)).toBe(1);
423
- await expect(bold).toHaveAttribute('aria-pressed', 'false');
424
- // Bold then makes the node bold, and shows it.
425
- await bold.click();
426
- await expect(
427
- surface(page, 'editor').locator('strong [data-mention="ada"]'),
428
- ).toHaveCount(1);
429
- await expect(bold).toHaveAttribute('aria-pressed', 'true');
430
- expect(errors).toEqual([]);
431
- });
432
-
433
- test('a copied plugin node pastes whole, drawn where the plugin is given and as source where it is not', async ({
434
- page,
435
- }) => {
436
- const errors = await openStory(page);
437
- // Select "Ping " and the node, then copy them.
438
- await caretAt(page, 6, true);
439
- await expectEditorSelection(page, 'Ping @{ada}');
440
- await page.keyboard.press('ControlOrMeta+c');
441
- for (const [name, drawn] of [
442
- ['paste-with', true],
443
- ['paste-without', false],
444
- ] as const) {
445
- await surface(page, name).locator('[contenteditable="true"]').click();
446
- await page.keyboard.press('ControlOrMeta+v');
447
- if (drawn) {
448
- await expect(
449
- surface(page, name).locator('[data-mention="ada"]'),
450
- ).toHaveCount(1);
451
- } else {
452
- await expect(
453
- surface(page, name).locator('[data-lexical-decorator="true"]'),
454
- ).toHaveText('@{ada}');
455
- }
456
- }
457
- expect(await markdownOutput(page)).toContain('---\nPing @{ada}');
458
- expect(errors).toEqual([]);
459
- });
460
-
461
- // The repository's Storybook audit runs axe with these exemptions; the same
462
- // note on three surfaces must not make three identical landmarks.
463
- const AXE_DISABLED_RULES = [
464
- 'html-has-lang',
465
- 'document-title',
466
- 'landmark-one-main',
467
- 'page-has-heading-one',
468
- 'region',
469
- ];
470
-
471
- test('the story has no axe violations, landmarks included', async ({page}) => {
472
- const errors = await openStory(page);
473
- const results = await new AxeBuilder({page})
474
- .disableRules(AXE_DISABLED_RULES)
475
- .analyze();
476
- expect(
477
- results.violations.map(violation => [
478
- violation.id,
479
- violation.nodes.map(node => node.target.join(' ')),
480
- ]),
481
- ).toEqual([]);
482
- expect(errors).toEqual([]);
483
- });
@@ -1,152 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
- // @pr-a11y release-only
3
-
4
- /**
5
- * @file MarkdownPluginsImportExport.a11y.chromium.spec.ts
6
- * @input The built Storybook's "Markdown plugins: import and export" story.
7
- * @output Real-browser proof for spec:AST-064 FR4, FR5, and FR10: plugin
8
- * syntax is recognized as core recognizes it, nodes keep the marks around
9
- * them, a block after a paragraph line becomes its own block, the export is
10
- * byte for byte, edits keep every node's source, and a transform plugin is
11
- * refused.
12
- *
13
- * Run after building Storybook:
14
- * pnpm storybook:build
15
- * pnpm exec playwright test packages/richtext --project chromium
16
- */
17
-
18
- import AxeBuilder from '@axe-core/playwright';
19
- import {expect, test, type Page} from '@playwright/test';
20
- import {
21
- DEFAULT_STORYBOOK_DIR,
22
- serveStorybook,
23
- type StaticServer,
24
- } from '@astryxdesign/a11y-spec/storybook';
25
-
26
- const STORYBOOK_DIR = process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR;
27
- const STORY = 'richtext-richtexteditor--markdown-plugins-import-export';
28
-
29
- let storybook: StaticServer;
30
-
31
- test.beforeAll(async () => {
32
- storybook = await serveStorybook(STORYBOOK_DIR);
33
- });
34
-
35
- test.afterAll(async () => {
36
- await storybook?.close();
37
- });
38
-
39
- async function openStory(
40
- page: Page,
41
- colorMode: 'light' | 'dark' = 'light',
42
- ): Promise<string[]> {
43
- const errors: string[] = [];
44
- page.on('pageerror', error => errors.push(String(error)));
45
- page.on('console', message => {
46
- if (message.type() === 'error' && !message.text().includes('404')) {
47
- errors.push(message.text());
48
- }
49
- });
50
- await page.setViewportSize({width: 1440, height: 900});
51
- await page.goto(
52
- `${storybook.origin}/iframe.html?id=${STORY}&viewMode=story&globals=astryxTheme:neutral;colorMode:${colorMode};direction:ltr`,
53
- {waitUntil: 'load'},
54
- );
55
- await expect(page.locator('[data-plugins-identical]')).toBeVisible();
56
- return errors;
57
- }
58
-
59
- test('the story imports plugin syntax, keeps marks, and exports byte for byte', async ({
60
- page,
61
- }) => {
62
- const errors = await openStory(page);
63
- await expect(page.locator('[data-plugins-identical]')).toHaveText(
64
- '— identical, byte for byte',
65
- );
66
- const input = await page.locator('[data-plugins-input]').inputValue();
67
- await expect(page.locator('[data-plugins-output]')).toHaveText(input);
68
- const rows = page.locator('[data-plugins-nodes] tbody tr');
69
- await expect(rows).toHaveText([
70
- /story-mentions\s*inline\s*@\{ada\}\s*none/,
71
- /story-mentions\s*inline\s*@\{grace\}\s*italic/,
72
- /story-mentions\s*inline\s*@\{linus\}\s*bold/,
73
- /story-mentions\s*inline\s*@\{old\}\s*strikethrough/,
74
- /story-notes\s*block\s*:::note[\s\S]*:::\s*none/,
75
- ]);
76
- await expect(page.locator('[data-plugins-refusal]')).toContainText(
77
- 'RichTextExtensionError: RichText cannot adopt Markdown plugin "story-shouting"',
78
- );
79
- expect(errors).toEqual([]);
80
- });
81
-
82
- test('editing the text beside the nodes keeps every node and its marks', async ({
83
- page,
84
- }) => {
85
- const errors = await openStory(page);
86
- const editor = page.locator('[contenteditable="true"]');
87
- await editor.getByText('Ping', {exact: false}).first().click();
88
- await page.keyboard.press('Home');
89
- await page.keyboard.type('Please ');
90
- await page.getByRole('button', {name: 'Export'}).click();
91
- const edited =
92
- (await page.locator('[data-plugins-edited]').textContent()) ?? '';
93
- expect(edited).toContain('Please Ping @{ada} about the review.');
94
- expect(edited).toContain('*see @{grace} here*');
95
- expect(edited).toContain('**ask @{linus}**');
96
- expect(edited).toContain('~~not @{old}~~');
97
- expect(edited).toContain(
98
- ':::note\nand this note starts on the next line.\n:::',
99
- );
100
- expect(errors).toEqual([]);
101
- });
102
-
103
- // spec:AST-061 FR3: the first block's leading margin and the last block's
104
- // trailing margin are zero, a plugin block included. Lexical puts a zero-size
105
- // caret boundary element beside a decorator at either edge of the document, so
106
- // a plugin block there is not literally the first or last child.
107
- test('a plugin block at either edge of the document adds no outer margin', async ({
108
- page,
109
- }) => {
110
- const errors = await openStory(page);
111
- await page
112
- .locator('[data-plugins-input]')
113
- .fill(':::note\nfirst\n:::\n\nBetween the notes.\n\n:::note\nlast\n:::');
114
- const editor = page.locator('[contenteditable="true"]');
115
- await expect(editor.getByText('Between the notes.')).toBeVisible();
116
- const margins = await editor.evaluate(root => {
117
- const blocks = [...root.children].filter(
118
- child => !child.hasAttribute('data-lexical-decorator-boundary'),
119
- );
120
- const first = blocks[0];
121
- const last = blocks[blocks.length - 1];
122
- return {
123
- first: first?.hasAttribute('data-lexical-decorator') ?? false,
124
- last: last?.hasAttribute('data-lexical-decorator') ?? false,
125
- start: first == null ? null : getComputedStyle(first).marginTop,
126
- end: last == null ? null : getComputedStyle(last).marginBottom,
127
- };
128
- });
129
- // Both edge blocks are the plugin's note blocks.
130
- expect(margins.first).toBe(true);
131
- expect(margins.last).toBe(true);
132
- expect(margins.start).toBe('0px');
133
- expect(margins.end).toBe('0px');
134
- expect(errors).toEqual([]);
135
- });
136
-
137
- for (const colorMode of ['light', 'dark'] as const) {
138
- test(`the story meets text contrast in ${colorMode} mode`, async ({page}) => {
139
- const errors = await openStory(page, colorMode);
140
- await page.getByRole('button', {name: 'Export'}).click();
141
- const results = await new AxeBuilder({page})
142
- .include('#storybook-root')
143
- .withRules(['color-contrast'])
144
- .analyze();
145
- expect(
146
- results.violations.flatMap(violation =>
147
- violation.nodes.map(node => node.target.join(' ')),
148
- ),
149
- ).toEqual([]);
150
- expect(errors).toEqual([]);
151
- });
152
- }