|
1 | 1 | import { describe, expect, it } from 'vitest'; |
2 | | -import { extractImplicitPart, extractPart } from './extractParts'; |
| 2 | +import { extractImplicitPart as extractImplicitPartOriginal, extractPart } from './extractParts'; |
3 | 3 | import type { GenericParent } from '../dist'; |
4 | 4 | import { copyNode } from './utils'; |
5 | 5 |
|
| 6 | +/** Remove keys for testing purposes from the parent nodes */ |
| 7 | +function extractImplicitPart(...args: Parameters<typeof extractImplicitPartOriginal>) { |
| 8 | + const part = extractImplicitPartOriginal(...args); |
| 9 | + part?.children?.forEach((child) => { |
| 10 | + delete child.key; |
| 11 | + }); |
| 12 | + return part; |
| 13 | +} |
| 14 | + |
6 | 15 | describe('extractPart', () => { |
7 | 16 | it('no part returns undefined', async () => { |
8 | 17 | expect( |
@@ -597,6 +606,36 @@ describe('extractImplicitPart', () => { |
597 | 606 | ], |
598 | 607 | }); |
599 | 608 | }); |
| 609 | + it('original extractImplicitPart adds keys to the children', async () => { |
| 610 | + const tree: GenericParent = { |
| 611 | + type: 'root', |
| 612 | + children: [ |
| 613 | + { |
| 614 | + type: 'block', |
| 615 | + children: [ |
| 616 | + { |
| 617 | + type: 'heading', |
| 618 | + children: [{ type: 'text', value: 'abstract' }], |
| 619 | + }, |
| 620 | + { |
| 621 | + type: 'paragraph', |
| 622 | + children: [{ type: 'text', value: 'two' }], |
| 623 | + }, |
| 624 | + ], |
| 625 | + }, |
| 626 | + { |
| 627 | + type: 'heading', |
| 628 | + children: [{ type: 'text', value: 'abstract' }], |
| 629 | + }, |
| 630 | + { |
| 631 | + type: 'paragraph', |
| 632 | + children: [{ type: 'text', value: 'four' }], |
| 633 | + }, |
| 634 | + ], |
| 635 | + }; |
| 636 | + const hasKeys = extractImplicitPartOriginal(tree, 'abstract'); |
| 637 | + expect(hasKeys?.children?.every((child) => child.key)).toBe(true); |
| 638 | + }); |
600 | 639 | it('part headings with no content remain', async () => { |
601 | 640 | const tree: GenericParent = { |
602 | 641 | type: 'root', |
|
0 commit comments