|
2 | 2 | * @vitest-environment jsdom |
3 | 3 | */ |
4 | 4 | import { |
| 5 | + Node, |
5 | 6 | DOMParser as PMDOMParser, |
6 | 7 | DOMSerializer, |
7 | 8 | } from "@tiptap/pm/model"; |
@@ -105,7 +106,7 @@ describe("SuggestionNode - structural", () => { |
105 | 106 | ]; |
106 | 107 |
|
107 | 108 | for (const type of expectedSuggestionTypes) { |
108 | | - expect(nodeTypes, `Expected node type "${type}" to be registered`).toContain(type); |
| 109 | + expect(nodeTypes).toContain(type); |
109 | 110 | } |
110 | 111 | }); |
111 | 112 |
|
@@ -230,10 +231,7 @@ describe("SuggestionNode - HTML parsing transparency", () => { |
230 | 231 |
|
231 | 232 | // Verify no block has a type starting with "suggestion-" |
232 | 233 | const hasSuggestion = JSON.stringify(blocks).includes('"suggestion-'); |
233 | | - expect( |
234 | | - hasSuggestion, |
235 | | - `Parsing "${html}" should not produce suggestion blocks in block JSON`, |
236 | | - ).toBe(false); |
| 234 | + expect(hasSuggestion).toBe(false); |
237 | 235 |
|
238 | 236 | // Verify all blocks have expected types |
239 | 237 | for (const block of blocks) { |
@@ -499,11 +497,12 @@ describe("SuggestionNode - getBlockInfo interaction", () => { |
499 | 497 | const blockInfo = getBlockInfoWithManualOffset(blockContainerNode, 0); |
500 | 498 |
|
501 | 499 | expect(blockInfo.isBlockContainer).toBe(true); |
502 | | - if (blockInfo.isBlockContainer) { |
503 | | - expect(blockInfo.blockContent.node.type.name).toBe("paragraph"); |
504 | | - // The blockNoteType should be derived from the blockContent, not the suggestion |
505 | | - expect(blockInfo.blockNoteType).toBe("paragraph"); |
| 500 | + if (!blockInfo.isBlockContainer) { |
| 501 | + throw new Error("Expected blockInfo to be a blockContainer"); |
506 | 502 | } |
| 503 | + expect(blockInfo.blockContent.node.type.name).toBe("paragraph"); |
| 504 | + // The blockNoteType should be derived from the blockContent, not the suggestion |
| 505 | + expect(blockInfo.blockNoteType).toBe("paragraph"); |
507 | 506 |
|
508 | 507 | destroy(); |
509 | 508 | }); |
@@ -546,13 +545,14 @@ describe("SuggestionNode - getBlockInfo interaction", () => { |
546 | 545 | const blockInfo = getBlockInfoWithManualOffset(blockContainerNode, 0); |
547 | 546 |
|
548 | 547 | expect(blockInfo.isBlockContainer).toBe(true); |
549 | | - if (blockInfo.isBlockContainer) { |
550 | | - expect(blockInfo.blockContent.node.type.name).toBe("paragraph"); |
551 | | - expect(blockInfo.blockNoteType).toBe("paragraph"); |
552 | | - // childContainer should be found (the blockGroup with children) |
553 | | - expect(blockInfo.childContainer).toBeDefined(); |
554 | | - expect(blockInfo.childContainer!.node.type.name).toBe("blockGroup"); |
| 548 | + if (!blockInfo.isBlockContainer) { |
| 549 | + throw new Error("Expected blockInfo to be a blockContainer"); |
555 | 550 | } |
| 551 | + expect(blockInfo.blockContent.node.type.name).toBe("paragraph"); |
| 552 | + expect(blockInfo.blockNoteType).toBe("paragraph"); |
| 553 | + // childContainer should be found (the blockGroup with children) |
| 554 | + expect(blockInfo.childContainer).toBeDefined(); |
| 555 | + expect(blockInfo.childContainer!.node.type.name).toBe("blockGroup"); |
556 | 556 |
|
557 | 557 | destroy(); |
558 | 558 | }); |
@@ -604,17 +604,14 @@ describe("SuggestionNode - schema transparency comparison", () => { |
604 | 604 | }, |
605 | 605 | ]; |
606 | 606 |
|
607 | | - for (const { html, expectedFirstType, description } of testCases) { |
| 607 | + for (const { html, expectedFirstType } of testCases) { |
608 | 608 | const blocks = editor.tryParseHTMLToBlocks(html); |
609 | 609 | expect(blocks.length).toBeGreaterThan(0); |
610 | 610 | expect(blocks[0].type).toBe(expectedFirstType); |
611 | 611 |
|
612 | 612 | // No block should ever be a suggestion node |
613 | 613 | for (const block of blocks) { |
614 | | - expect( |
615 | | - block.type, |
616 | | - `${description}: block should not be a suggestion node`, |
617 | | - ).not.toMatch(/^suggestion-/); |
| 614 | + expect(block.type).not.toMatch(/^suggestion-/); |
618 | 615 | } |
619 | 616 | } |
620 | 617 |
|
@@ -655,21 +652,21 @@ describe("SuggestionNode - PM-level HTML round-trip", () => { |
655 | 652 | }); |
656 | 653 |
|
657 | 654 | // The parsed node should contain a suggestion node |
658 | | - let foundSuggestion = false; |
659 | | - let foundBlockContent = false; |
| 655 | + let suggestionChild: Node | undefined; |
| 656 | + let blockContentChild: Node | undefined; |
660 | 657 | parsed.forEach((child) => { |
661 | 658 | if (child.type.name === "suggestion-paragraph") { |
662 | | - foundSuggestion = true; |
663 | | - expect(child.textContent).toBe("Suggestion text"); |
664 | | - expect(child.attrs.__suggestionData).toBe("true"); |
| 659 | + suggestionChild = child; |
665 | 660 | } |
666 | 661 | if (child.type.spec.group === "blockContent") { |
667 | | - foundBlockContent = true; |
668 | | - expect(child.textContent).toBe("Main text"); |
| 662 | + blockContentChild = child; |
669 | 663 | } |
670 | 664 | }); |
671 | | - expect(foundSuggestion).toBe(true); |
672 | | - expect(foundBlockContent).toBe(true); |
| 665 | + expect(suggestionChild).toBeDefined(); |
| 666 | + expect(suggestionChild!.textContent).toBe("Suggestion text"); |
| 667 | + expect(suggestionChild!.attrs.__suggestionData).toBe("true"); |
| 668 | + expect(blockContentChild).toBeDefined(); |
| 669 | + expect(blockContentChild!.textContent).toBe("Main text"); |
673 | 670 |
|
674 | 671 | destroy(); |
675 | 672 | }); |
|
0 commit comments