Plain diff --git a/tests/src/unit/core/formatConversion/export/__snapshots__/blocknoteHTML/partial/empty.html b/tests/src/unit/core/formatConversion/export/__snapshots__/blocknoteHTML/partial/empty.html new file mode 100644 index 0000000000..8c0240ae7c --- /dev/null +++ b/tests/src/unit/core/formatConversion/export/__snapshots__/blocknoteHTML/partial/empty.html @@ -0,0 +1,9 @@ +
Plain
\ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/export/__snapshots__/html/partial/noChildren.html b/tests/src/unit/core/formatConversion/export/__snapshots__/html/partial/noChildren.html new file mode 100644 index 0000000000..281c6866c3 --- /dev/null +++ b/tests/src/unit/core/formatConversion/export/__snapshots__/html/partial/noChildren.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/export/__snapshots__/html/partial/noId.html b/tests/src/unit/core/formatConversion/export/__snapshots__/html/partial/noId.html new file mode 100644 index 0000000000..c6280d2338 --- /dev/null +++ b/tests/src/unit/core/formatConversion/export/__snapshots__/html/partial/noId.html @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/export/__snapshots__/html/partial/noProps.html b/tests/src/unit/core/formatConversion/export/__snapshots__/html/partial/noProps.html new file mode 100644 index 0000000000..c6280d2338 --- /dev/null +++ b/tests/src/unit/core/formatConversion/export/__snapshots__/html/partial/noProps.html @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/export/__snapshots__/html/partial/noType.html b/tests/src/unit/core/formatConversion/export/__snapshots__/html/partial/noType.html new file mode 100644 index 0000000000..0ba6caf1bc --- /dev/null +++ b/tests/src/unit/core/formatConversion/export/__snapshots__/html/partial/noType.html @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/export/__snapshots__/markdown/partial/empty.md b/tests/src/unit/core/formatConversion/export/__snapshots__/markdown/partial/empty.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/src/unit/core/formatConversion/export/__snapshots__/markdown/partial/noChildren.md b/tests/src/unit/core/formatConversion/export/__snapshots__/markdown/partial/noChildren.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/src/unit/core/formatConversion/export/__snapshots__/markdown/partial/noId.md b/tests/src/unit/core/formatConversion/export/__snapshots__/markdown/partial/noId.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/src/unit/core/formatConversion/export/__snapshots__/markdown/partial/noProps.md b/tests/src/unit/core/formatConversion/export/__snapshots__/markdown/partial/noProps.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/src/unit/core/formatConversion/export/__snapshots__/markdown/partial/noType.md b/tests/src/unit/core/formatConversion/export/__snapshots__/markdown/partial/noType.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/src/unit/core/formatConversion/export/__snapshots__/nodes/partial/empty.json b/tests/src/unit/core/formatConversion/export/__snapshots__/nodes/partial/empty.json new file mode 100644 index 0000000000..8fdcafd2e5 --- /dev/null +++ b/tests/src/unit/core/formatConversion/export/__snapshots__/nodes/partial/empty.json @@ -0,0 +1,18 @@ +[ + { + "attrs": { + "id": "1", + }, + "content": [ + { + "attrs": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "paragraph", + }, + ], + "type": "blockContainer", + }, +] \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/export/__snapshots__/nodes/partial/noChildren.json b/tests/src/unit/core/formatConversion/export/__snapshots__/nodes/partial/noChildren.json new file mode 100644 index 0000000000..d6bd0378f6 --- /dev/null +++ b/tests/src/unit/core/formatConversion/export/__snapshots__/nodes/partial/noChildren.json @@ -0,0 +1,18 @@ +[ + { + "attrs": { + "id": "exportTestBlock", + }, + "content": [ + { + "attrs": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "exportTestBlock", + }, + ], + "type": "blockContainer", + }, +] \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/export/__snapshots__/nodes/partial/noId.json b/tests/src/unit/core/formatConversion/export/__snapshots__/nodes/partial/noId.json new file mode 100644 index 0000000000..10cb759fac --- /dev/null +++ b/tests/src/unit/core/formatConversion/export/__snapshots__/nodes/partial/noId.json @@ -0,0 +1,39 @@ +[ + { + "attrs": { + "id": "1", + }, + "content": [ + { + "attrs": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "exportTestBlock", + }, + { + "content": [ + { + "attrs": { + "id": "2", + }, + "content": [ + { + "attrs": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "exportTestBlock", + }, + ], + "type": "blockContainer", + }, + ], + "type": "blockGroup", + }, + ], + "type": "blockContainer", + }, +] \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/export/__snapshots__/nodes/partial/noProps.json b/tests/src/unit/core/formatConversion/export/__snapshots__/nodes/partial/noProps.json new file mode 100644 index 0000000000..071417670f --- /dev/null +++ b/tests/src/unit/core/formatConversion/export/__snapshots__/nodes/partial/noProps.json @@ -0,0 +1,39 @@ +[ + { + "attrs": { + "id": "exportTestBlock", + }, + "content": [ + { + "attrs": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "exportTestBlock", + }, + { + "content": [ + { + "attrs": { + "id": "exportTestBlock", + }, + "content": [ + { + "attrs": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "exportTestBlock", + }, + ], + "type": "blockContainer", + }, + ], + "type": "blockGroup", + }, + ], + "type": "blockContainer", + }, +] \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/export/__snapshots__/nodes/partial/noType.json b/tests/src/unit/core/formatConversion/export/__snapshots__/nodes/partial/noType.json new file mode 100644 index 0000000000..96ecb6b69f --- /dev/null +++ b/tests/src/unit/core/formatConversion/export/__snapshots__/nodes/partial/noType.json @@ -0,0 +1,39 @@ +[ + { + "attrs": { + "id": "exportTestBlock", + }, + "content": [ + { + "attrs": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "paragraph", + }, + { + "content": [ + { + "attrs": { + "id": "exportTestBlock", + }, + "content": [ + { + "attrs": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "paragraph", + }, + ], + "type": "blockContainer", + }, + ], + "type": "blockGroup", + }, + ], + "type": "blockContainer", + }, +] \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/export/exportTestInstances.ts b/tests/src/unit/core/formatConversion/export/exportTestInstances.ts index 298e361884..e65619ae31 100644 --- a/tests/src/unit/core/formatConversion/export/exportTestInstances.ts +++ b/tests/src/unit/core/formatConversion/export/exportTestInstances.ts @@ -1678,6 +1678,112 @@ export const exportTestInstancesBlockNoteHTML: TestInstance< }, executeTest: testExportBlockNoteHTML, }, + { + testCase: { + name: "partial/empty", + content: [{}], + }, + executeTest: testExportBlockNoteHTML, + }, + { + testCase: { + name: "partial/noId", + content: [ + { + type: "exportTestBlock", + props: { + textAlignment: "left", + textColor: "default", + backgroundColor: "default", + }, + content: undefined, + children: [ + { + type: "exportTestBlock", + props: { + textAlignment: "left", + textColor: "default", + backgroundColor: "default", + }, + content: undefined, + children: [], + }, + ], + }, + ], + }, + executeTest: testExportBlockNoteHTML, + }, + { + testCase: { + name: "partial/noType", + content: [ + { + id: "exportTestBlock", + props: { + textAlignment: "left", + textColor: "default", + backgroundColor: "default", + invalidProp: true, + }, + content: undefined, + children: [ + { + id: "exportTestBlock", + props: { + textAlignment: "left", + textColor: "default", + backgroundColor: "default", + invalidProp: true, + }, + content: undefined, + children: [], + }, + ], + }, + ], + }, + executeTest: testExportBlockNoteHTML, + }, + { + testCase: { + name: "partial/noProps", + content: [ + { + id: "exportTestBlock", + type: "exportTestBlock", + content: undefined, + children: [ + { + id: "exportTestBlock", + type: "exportTestBlock", + content: undefined, + children: [], + }, + ], + }, + ], + }, + executeTest: testExportBlockNoteHTML, + }, + { + testCase: { + name: "partial/noChildren", + content: [ + { + id: "exportTestBlock", + type: "exportTestBlock", + props: { + textAlignment: "left", + textColor: "default", + backgroundColor: "default", + }, + content: undefined, + }, + ], + }, + executeTest: testExportBlockNoteHTML, + }, { testCase: { name: "inlineContent/mentionWithToExternalHTML", diff --git a/tests/src/unit/core/formatConversion/exportParseEquality/exportParseEqualityTestInstances.ts b/tests/src/unit/core/formatConversion/exportParseEquality/exportParseEqualityTestInstances.ts index 33d9b09c15..84e355f026 100644 --- a/tests/src/unit/core/formatConversion/exportParseEquality/exportParseEqualityTestInstances.ts +++ b/tests/src/unit/core/formatConversion/exportParseEquality/exportParseEqualityTestInstances.ts @@ -20,10 +20,12 @@ export const exportParseEqualityTestInstancesBlockNoteHTML: TestInstance< TestBlockSchema, TestInlineContentSchema, TestStyleSchema ->[] = exportTestInstancesBlockNoteHTML.map(({ testCase }) => ({ - testCase, - executeTest: testExportParseEqualityBlockNoteHTML, -})); +>[] = exportTestInstancesBlockNoteHTML + .filter(({ testCase }) => !testCase.name.startsWith("partial/")) + .map(({ testCase }) => ({ + testCase, + executeTest: testExportParseEqualityBlockNoteHTML, + })); export const exportParseEqualityTestInstancesHTML: TestInstance< ExportParseEqualityTestCase< diff --git a/tests/src/unit/core/schema/__snapshots__/blocks.json b/tests/src/unit/core/schema/__snapshots__/blocks.json index b54e1b4d93..3c9946a695 100644 --- a/tests/src/unit/core/schema/__snapshots__/blocks.json +++ b/tests/src/unit/core/schema/__snapshots__/blocks.json @@ -510,6 +510,74 @@ "toExternalHTML": [Function], }, }, + "exportTestBlock": { + "config": { + "content": "none", + "propSchema": { + "backgroundColor": { + "default": "default", + }, + "textAlignment": { + "default": "left", + "values": [ + "left", + "center", + "right", + "justify", + ], + }, + "textColor": { + "default": "default", + }, + }, + "type": "exportTestBlock", + }, + "extensions": undefined, + "implementation": { + "node": _Node { + "child": _Node { + "child": null, + "config": { + "addAttributes": [Function], + "addNodeView": [Function], + "addOptions": [Function], + "code": false, + "content": "", + "defining": true, + "group": "blockContent", + "isolating": true, + "name": "exportTestBlock", + "parseHTML": [Function], + "priority": 101, + "renderHTML": [Function], + "selectable": true, + }, + "name": "exportTestBlock", + "parent": null, + "type": "node", + }, + "config": { + "addAttributes": [Function], + "addNodeView": [Function], + "code": false, + "content": "", + "defining": true, + "group": "blockContent", + "isolating": true, + "name": "exportTestBlock", + "parseHTML": [Function], + "priority": 101, + "renderHTML": [Function], + "selectable": true, + }, + "name": "exportTestBlock", + "parent": null, + "type": "node", + }, + "render": [Function], + "toExternalHTML": [Function], + }, + }, "file": { "config": { "content": "none", diff --git a/tests/src/unit/core/testSchema.ts b/tests/src/unit/core/testSchema.ts index 537350eb78..4d29e7bb81 100644 --- a/tests/src/unit/core/testSchema.ts +++ b/tests/src/unit/core/testSchema.ts @@ -1,6 +1,9 @@ import { + BlockFromConfig, + BlockNoteEditor, BlockNoteSchema, addNodeAndExtensionsToSpec, + createBlockSpec, createImageBlockConfig, createImageBlockSpec, createInlineContentSpec, @@ -78,6 +81,94 @@ const SimpleCustomParagraph = addNodeAndExtensionsToSpec( }, ); +// This block is used to test converting partial blocks into full blocks when +// exporting. If any of the fields are incorrectly defined, will throw an +// error. +const validateBlock = ( + block: BlockFromConfigHello World
\ No newline at end of file diff --git a/tests/src/unit/react/formatConversion/export/__snapshots__/html/simpleCustomParagraph/styled.html b/tests/src/unit/react/formatConversion/export/__snapshots__/html/simpleCustomParagraph/styled.html index 87efb71bf5..772e08fc9a 100644 --- a/tests/src/unit/react/formatConversion/export/__snapshots__/html/simpleCustomParagraph/styled.html +++ b/tests/src/unit/react/formatConversion/export/__snapshots__/html/simpleCustomParagraph/styled.html @@ -1,8 +1,8 @@Plain