Skip to content

feat: Unit testing setup restructure #1595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"@tiptap/pm": "^2.11.5",
"emoji-mart": "^5.6.0",
"hast-util-from-dom": "^5.0.1",
"htmlfy": "^0.6.7",
"prosemirror-dropcursor": "^1.8.1",
"prosemirror-highlight": "^0.13.0",
"prosemirror-model": "^1.24.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,39 @@
<p>Paragraph 1</p><h1>Heading 1</h1><ol><li><p>Numbered List Item 1</p></li></ol><ul><li><p>Bullet List Item 1</p></li><li><input type="checkbox"><p class="bn-inline-content">Check List Item 1</p></li></ul><pre><code class="bn-inline-content language-text" data-language="text">console.log("Hello World");</code></pre><table><tr><td colspan="1" rowspan="1"><p>Table Cell 1</p></td><td colspan="1" rowspan="1"><p>Table Cell 2</p></td></tr><tr><td colspan="1" rowspan="1"><p>Table Cell 3</p></td><td colspan="1" rowspan="1"><p>Table Cell 4</p></td></tr></table><p>Add image</p><p>Paragraph 2</p>
<p>Paragraph 1</p>
<h1>Heading 1</h1>
<ol>
<li>
<p>Numbered List Item 1</p>
</li>
</ol>
<ul>
<li>
<p>Bullet List Item 1</p>
</li>
<li>
<input type="checkbox" />
<p class="bn-inline-content">Check List Item 1</p>
</li>
</ul>
<pre>
<code class="bn-inline-content language-text" data-language="text">console.log("Hello World");</code>
</pre>
<table>
<tr>
<td colspan="1" rowspan="1">
<p>Table Cell 1</p>
</td>
<td colspan="1" rowspan="1">
<p>Table Cell 2</p>
</td>
</tr>
<tr>
<td colspan="1" rowspan="1">
<p>Table Cell 3</p>
</td>
<td colspan="1" rowspan="1">
<p>Table Cell 4</p>
</td>
</tr>
</table>
<p>Add image</p>
<p>Paragraph 2</p>
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
<p data-text-color="red">Paragraph 1</p><h2 data-level="2">Heading 1</h2><ol start="2"><li><p data-start="2">Numbered List Item 1</p></li></ol><ul><li><p data-background-color="red">Bullet List Item 1</p></li><li><input type="checkbox" checked="" data-checked="true"><p class="bn-inline-content">Check List Item 1</p></li></ul><pre><code class="bn-inline-content language-typescript" data-language="typescript">console.log("Hello World");</code></pre><table><tr><td colspan="1" rowspan="1"><p>Table Cell 1</p></td><td colspan="1" rowspan="1"><p>Table Cell 2</p></td></tr><tr><td colspan="1" rowspan="1"><p>Table Cell 3</p></td><td colspan="1" rowspan="1"><p>Table Cell 4</p></td></tr></table><figure data-name="1280px-Placeholder_view_vector.svg.png" data-url="https://upload.wikimedia.org/wikipedia/commons/thumb/3/3f/Placeholder_view_vector.svg/1280px-Placeholder_view_vector.svg.png" data-caption="Placeholder" data-preview-width="256"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/3f/Placeholder_view_vector.svg/1280px-Placeholder_view_vector.svg.png" alt="1280px-Placeholder_view_vector.svg.png" width="256"><figcaption>Placeholder</figcaption></figure><p>Paragraph 2</p>
<p data-text-color="red">Paragraph 1</p>
<h2 data-level="2">Heading 1</h2>
<ol start="2">
<li>
<p data-start="2">Numbered List Item 1</p>
</li>
</ol>
<ul>
<li>
<p data-background-color="red">Bullet List Item 1</p>
</li>
<li>
<input type="checkbox" checked="" data-checked="true" />
<p class="bn-inline-content">Check List Item 1</p>
</li>
</ul>
<pre>
<code class="bn-inline-content language-typescript" data-language="typescript">console.log("Hello World");</code>
</pre>
<table>
<tr>
<td colspan="1" rowspan="1">
<p>Table Cell 1</p>
</td>
<td colspan="1" rowspan="1">
<p>Table Cell 2</p>
</td>
</tr>
<tr>
<td colspan="1" rowspan="1">
<p>Table Cell 3</p>
</td>
<td colspan="1" rowspan="1">
<p>Table Cell 4</p>
</td>
</tr>
</table>
<figure
data-name="1280px-Placeholder_view_vector.svg.png"
data-url="https://upload.wikimedia.org/wikipedia/commons/thumb/3/3f/Placeholder_view_vector.svg/1280px-Placeholder_view_vector.svg.png"
data-caption="Placeholder"
data-preview-width="256"
>
<img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/3f/Placeholder_view_vector.svg/1280px-Placeholder_view_vector.svg.png"
alt="1280px-Placeholder_view_vector.svg.png"
width="256"
/>
<figcaption>Placeholder</figcaption>
</figure>
<p>Paragraph 2</p>
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<p>Paragraph 1</p><p>Nested Paragraph 1</p>
<p>Paragraph 1</p>
<p>Nested Paragraph 1</p>
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
<p>Nested Paragraph 1</p><p>Nested Paragraph 2</p><p>Nested Paragraph 3</p><p>Paragraph 2</p>
<p>Nested Paragraph 1</p>
<p>Nested Paragraph 2</p>
<p>Nested Paragraph 3</p>
<p>Paragraph 2</p>
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
<p>Nested Paragraph 1</p><p>Nested Paragraph 2</p><p>Nested Paragraph 3</p><p>Paragraph 2</p><p>Nested Paragraph 4</p><p>Nested Paragraph 5</p><p>Nested Paragraph 6</p>
<p>Nested Paragraph 1</p>
<p>Nested Paragraph 2</p>
<p>Nested Paragraph 3</p>
<p>Paragraph 2</p>
<p>Nested Paragraph 4</p>
<p>Nested Paragraph 5</p>
<p>Nested Paragraph 6</p>
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
<img src="https://ralfvanveen.com/wp-content/uploads/2021/06/Placeholder-_-Glossary.svg" alt="BlockNote image" width="512" data-url="https://ralfvanveen.com/wp-content/uploads/2021/06/Placeholder-_-Glossary.svg">
<img
src="https://ralfvanveen.com/wp-content/uploads/2021/06/Placeholder-_-Glossary.svg"
alt="BlockNote image"
width="512"
data-url="https://ralfvanveen.com/wp-content/uploads/2021/06/Placeholder-_-Glossary.svg"
/>
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<p>Nested Paragraph 1</p><p>Nested Paragraph 2</p><p>Nested Paragraph 3</p>
<p>Nested Paragraph 1</p>
<p>Nested Paragraph 2</p>
<p>Nested Paragraph 3</p>
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Unstyled Text<em>Italic Text</em><strong>Bold Text</strong>
Unstyled Text
<em>Italic Text</em>
<strong>Bold Text</strong>
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
<p>Paragraph 1</p><img src="https://ralfvanveen.com/wp-content/uploads/2021/06/Placeholder-_-Glossary.svg" alt="BlockNote image" width="512" data-url="https://ralfvanveen.com/wp-content/uploads/2021/06/Placeholder-_-Glossary.svg"><p>Nested Paragraph 1</p>
<p>Paragraph 1</p>
<img
src="https://ralfvanveen.com/wp-content/uploads/2021/06/Placeholder-_-Glossary.svg"
alt="BlockNote image"
width="512"
data-url="https://ralfvanveen.com/wp-content/uploads/2021/06/Placeholder-_-Glossary.svg"
/>
<p>Nested Paragraph 1</p>
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<p>aragraph 1</p><p>N</p>
<p>aragraph 1</p>
<p>N</p>
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
<table><tr><td colspan="1" rowspan="1"><p>Table Cell 1</p></td><td colspan="1" rowspan="1"><p>Table Cell 2</p></td></tr><tr><td colspan="1" rowspan="1"><p>Table Cell 3</p></td><td colspan="1" rowspan="1"><p>Table Cell 4</p></td></tr></table>
<table>
<tr>
<td colspan="1" rowspan="1">
<p>Table Cell 1</p>
</td>
<td colspan="1" rowspan="1">
<p>Table Cell 2</p>
</td>
</tr>
<tr>
<td colspan="1" rowspan="1">
<p>Table Cell 3</p>
</td>
<td colspan="1" rowspan="1">
<p>Table Cell 4</p>
</td>
</tr>
</table>
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
<table><tr><td colspan="1" rowspan="1"><p>Table Cell 1</p></td></tr></table>
<table>
<tr>
<td colspan="1" rowspan="1">
<p>Table Cell 1</p>
</td>
</tr>
</table>
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
<table><tr><td colspan="1" rowspan="1"><p>Table Cell 1</p></td></tr><tr><td colspan="1" rowspan="1"><p>Table Cell 3</p></td></tr></table>
<table>
<tr>
<td colspan="1" rowspan="1">
<p>Table Cell 1</p>
</td>
</tr>
<tr>
<td colspan="1" rowspan="1">
<p>Table Cell 3</p>
</td>
</tr>
</table>
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
<table><tr><td colspan="1" rowspan="1"><p>Table Cell 1</p></td><td colspan="1" rowspan="1"><p>Table Cell 2</p></td></tr></table>
<table>
<tr>
<td colspan="1" rowspan="1">
<p>Table Cell 1</p>
</td>
<td colspan="1" rowspan="1">
<p>Table Cell 2</p>
</td>
</tr>
</table>
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ export const getCopyTestCases = (): CopyTestCase[] => [
return TextSelection.create(doc, startPos, endPos);
},
},
// TODO: External HTML is wrapped in unnecessary `tr` element.
{
name: "tableCell",
clipboardDataType: "text/html",
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/api/tests/clipboard/copy/testCopy.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { prettify } from "htmlfy";
import { describe, expect, it } from "vitest";

import { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
Expand Down Expand Up @@ -41,11 +42,15 @@ const testCopyTest = async (
);

if (testCase.clipboardDataType === "blocknote/html") {
await expect(clipboardHTML).toMatchFileSnapshot(
await expect(
prettify(clipboardHTML, { tag_wrap: true })
).toMatchFileSnapshot(
`./__snapshots__/${testCase.clipboardDataType}/${testCase.name}.html`
);
} else if (testCase.clipboardDataType === "text/html") {
await expect(externalHTML).toMatchFileSnapshot(
await expect(
prettify(externalHTML, { tag_wrap: true })
).toMatchFileSnapshot(
`./__snapshots__/${testCase.clipboardDataType}/${testCase.name}.html`
);
} else if (testCase.clipboardDataType === "text/plain") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const testCopyPasteTest = async (
);
};

describe("Copy/paste tests", async () => {
describe("Copy/paste tests", () => {
const getEditor = setupTestEditor();

for (const testCase of getCopyPasteTestCases()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="null"><div class="bn-block" data-node-type="blockContainer" data-id="null"><div class="bn-block-content" data-content-type="codeBlock"><pre><code class="bn-inline-content language-javascript" data-language="javascript">const hello = 'world';
console.log(hello);
</code></pre></div></div></div></div>
<div class="bn-block-group" data-node-type="blockGroup">
<div class="bn-block-outer" data-node-type="blockOuter" data-id="1">
<div class="bn-block" data-node-type="blockContainer" data-id="1">
<div class="bn-block-content" data-content-type="codeBlock">
<pre>
<code class="bn-inline-content language-javascript" data-language="javascript">const hello ='world';console.log(hello);</code>
</pre>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
<div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="null"><div class="bn-block" data-node-type="blockContainer" data-id="null"><div class="bn-block-content" data-content-type="codeBlock"><pre><code class="bn-inline-content language-text" data-language="text">console.log('Hello, world!');</code></pre></div></div></div></div>
<div class="bn-block-group" data-node-type="blockGroup">
<div class="bn-block-outer" data-node-type="blockOuter" data-id="1">
<div class="bn-block" data-node-type="blockContainer" data-id="1">
<div class="bn-block-content" data-content-type="codeBlock">
<pre>
<code class="bn-inline-content language-text" data-language="text">console.log('Hello, world!');</code>
</pre>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
<div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="null"><div class="bn-block" data-node-type="blockContainer" data-id="null"><div class="bn-block-content" data-content-type="codeBlock"><pre><code class="bn-inline-content language-text" data-language="text"></code></pre></div></div></div></div>
<div class="bn-block-group" data-node-type="blockGroup">
<div class="bn-block-outer" data-node-type="blockOuter" data-id="1">
<div class="bn-block" data-node-type="blockContainer" data-id="1">
<div class="bn-block-content" data-content-type="codeBlock">
<pre>
<code class="bn-inline-content language-text" data-language="text"></code>
</pre>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
<div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="null"><div class="bn-block" data-node-type="blockContainer" data-id="null"><div class="bn-block-content" data-content-type="codeBlock"><pre><code class="bn-inline-content language-python" data-language="python">print('Hello, world!')</code></pre></div></div></div></div>
<div class="bn-block-group" data-node-type="blockGroup">
<div class="bn-block-outer" data-node-type="blockOuter" data-id="1">
<div class="bn-block" data-node-type="blockContainer" data-id="1">
<div class="bn-block-content" data-content-type="codeBlock">
<pre>
<code class="bn-inline-content language-python" data-language="python">print('Hello, world!')</code>
</pre>
</div>
</div>
</div>
</div>
Loading
Loading