Skip to content

Commit 97068ee

Browse files
committed
Separated tests for different formats
1 parent d92dcac commit 97068ee

21 files changed

+369
-255
lines changed

tests/src/unit/core/clipboard/copy/getCopyTestInstances.ts renamed to tests/src/unit/core/clipboard/copy/copyTestInstances.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import {
1414
getPosOfTextNode,
1515
} from "../clipboardTestUtil.js";
1616

17-
export const getCopyTestInstances = (): TestInstance<
17+
export const copyTestInstancesHTML: TestInstance<
1818
CopyTestCase<TestBlockSchema, TestInlineContentSchema, TestStyleSchema>,
1919
TestBlockSchema,
2020
TestInlineContentSchema,
2121
TestStyleSchema
22-
>[] => [
22+
>[] = [
2323
{
2424
testCase: {
2525
name: "multipleChildren",

tests/src/unit/core/clipboard/copy/runTests.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { describe, it } from "vitest";
22

33
import { setupTestEditor } from "../../setupTestEditor.js";
44
import { testSchema } from "../../testSchema.js";
5-
import { getCopyTestInstances } from "./getCopyTestInstances.js";
5+
import { copyTestInstancesHTML } from "./copyTestInstances.js";
66

77
// Tests for verifying content that gets put on the clipboard when copying
88
// within the editor. Used broadly to ensure each block or set of blocks is correctly
99
// converted into different types of clipboard data.
10-
describe("Copy tests", () => {
10+
describe("Copy tests (HTML)", () => {
1111
const getEditor = setupTestEditor(testSchema);
1212

13-
for (const { testCase, executeTest } of getCopyTestInstances()) {
13+
for (const { testCase, executeTest } of copyTestInstancesHTML) {
1414
it(`${testCase.name}`, async () => {
1515
await executeTest(getEditor(), testCase);
1616
});

tests/src/unit/core/clipboard/copyPaste/getCopyPasteTestInstances.ts renamed to tests/src/unit/core/clipboard/copyPaste/copyPasteTestInstances.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import { testCopyPaste } from "../../../shared/clipboard/copyPaste/copyPasteTest
1010
import { TestInstance } from "../../../types.js";
1111
import { getPosOfTextNode } from "../clipboardTestUtil.js";
1212

13-
export const getCopyPasteTestInstances = (): TestInstance<
13+
export const copyPasteTestInstances: TestInstance<
1414
CopyPasteTestCase<TestBlockSchema, TestInlineContentSchema, TestStyleSchema>,
1515
TestBlockSchema,
1616
TestInlineContentSchema,
1717
TestStyleSchema
18-
>[] => [
18+
>[] = [
1919
{
2020
testCase: {
2121
name: "paragraphInCustomBlock",

tests/src/unit/core/clipboard/copyPaste/runTests.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { describe, it } from "vitest";
22

33
import { setupTestEditor } from "../../setupTestEditor.js";
44
import { testSchema } from "../../testSchema.js";
5-
import { getCopyPasteTestInstances } from "./getCopyPasteTestInstances.js";
5+
import { copyPasteTestInstances } from "./copyPasteTestInstances.js";
66

77
// Tests for verifying that copying and pasting content within the editor works
88
// as expected. Used for specific cases where unexpected behaviour was noticed.
99
describe("Copy/paste tests", () => {
1010
const getEditor = setupTestEditor(testSchema);
1111

12-
for (const { testCase, executeTest } of getCopyPasteTestInstances()) {
12+
for (const { testCase, executeTest } of copyPasteTestInstances) {
1313
it(`${testCase.name}`, async () => {
1414
await executeTest(getEditor(), testCase);
1515
});

tests/src/unit/core/clipboard/copyPasteEquality/getCopyPasteEqualityTestInstances.ts renamed to tests/src/unit/core/clipboard/copyPasteEquality/copyPasteEqualityTestInstances.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import {
66
import { CopyPasteEqualityTestCase } from "../../../shared/clipboard/copyPasteEquality/copyPasteEqualityTestCase.js";
77
import { testCopyPasteEquality } from "../../../shared/clipboard/copyPasteEquality/copyPasteEqualityTestExecutors.js";
88
import { TestInstance } from "../../../types.js";
9-
import { getCopyTestInstances } from "../copy/getCopyTestInstances.js";
9+
import { copyTestInstancesHTML } from "../copy/copyTestInstances.js";
1010

11-
export const getCopyPasteEqualityTestInstances = (): TestInstance<
11+
export const copyPasteEqualityTestInstances: TestInstance<
1212
CopyPasteEqualityTestCase<
1313
TestBlockSchema,
1414
TestInlineContentSchema,
@@ -17,12 +17,11 @@ export const getCopyPasteEqualityTestInstances = (): TestInstance<
1717
TestBlockSchema,
1818
TestInlineContentSchema,
1919
TestStyleSchema
20-
>[] =>
21-
getCopyTestInstances().map(({ testCase }) => ({
22-
testCase: {
23-
name: testCase.name,
24-
document: testCase.document,
25-
getCopyAndPasteSelection: testCase.getCopySelection,
26-
},
27-
executeTest: testCopyPasteEquality,
28-
}));
20+
>[] = copyTestInstancesHTML.map(({ testCase }) => ({
21+
testCase: {
22+
name: testCase.name,
23+
document: testCase.document,
24+
getCopyAndPasteSelection: testCase.getCopySelection,
25+
},
26+
executeTest: testCopyPasteEquality,
27+
}));

tests/src/unit/core/clipboard/copyPasteEquality/runTests.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { describe, it } from "vitest";
22

33
import { setupTestEditor } from "../../setupTestEditor.js";
44
import { testSchema } from "../../testSchema.js";
5-
import { getCopyPasteEqualityTestInstances } from "./getCopyPasteEqualityTestInstances.js";
5+
import { copyPasteEqualityTestInstances } from "./copyPasteEqualityTestInstances.js";
66

77
// Tests for verifying that copying and pasting content in place within the
88
// editor results in the same document as the original. Used broadly to ensure
99
// that converting to and from clipboard data does not result in any data loss.
1010
describe("Copy/paste equality tests", () => {
1111
const getEditor = setupTestEditor(testSchema);
1212

13-
for (const { testCase, executeTest } of getCopyPasteEqualityTestInstances()) {
13+
for (const { testCase, executeTest } of copyPasteEqualityTestInstances) {
1414
it(`${testCase.name}`, async () => {
1515
await executeTest(getEditor(), testCase);
1616
});

tests/src/unit/core/clipboard/paste/getPasteTestInstances.ts renamed to tests/src/unit/core/clipboard/paste/pasteTestInstances.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import {
1313
import { TestInstance } from "../../../types.js";
1414
import { getPosOfTextNode } from "../clipboardTestUtil.js";
1515

16-
export const getPasteTestInstances = (): TestInstance<
16+
export const pasteTestInstancesHTML: TestInstance<
1717
PasteTestCase<TestBlockSchema, TestInlineContentSchema, TestStyleSchema>,
1818
TestBlockSchema,
1919
TestInlineContentSchema,
2020
TestStyleSchema
21-
>[] => [
21+
>[] = [
2222
{
2323
testCase: {
2424
name: "pasteEndOfParagraph",
@@ -37,24 +37,6 @@ export const getPasteTestInstances = (): TestInstance<
3737
},
3838
executeTest: testPasteHTML,
3939
},
40-
{
41-
testCase: {
42-
name: "pasteEndOfParagraphText",
43-
content: `Paragraph`,
44-
document: [
45-
{
46-
type: "paragraph",
47-
content: "Paragraph 1",
48-
},
49-
],
50-
getPasteSelection: (doc) => {
51-
const startPos = getPosOfTextNode(doc, "Paragraph 1", true);
52-
53-
return TextSelection.create(doc, startPos);
54-
},
55-
},
56-
executeTest: testPasteMarkdown,
57-
},
5840
{
5941
testCase: {
6042
name: "pasteImage",
@@ -156,3 +138,29 @@ export const getPasteTestInstances = (): TestInstance<
156138
executeTest: testPasteHTML,
157139
},
158140
];
141+
142+
export const pasteTestInstancesMarkdown: TestInstance<
143+
PasteTestCase<TestBlockSchema, TestInlineContentSchema, TestStyleSchema>,
144+
TestBlockSchema,
145+
TestInlineContentSchema,
146+
TestStyleSchema
147+
>[] = [
148+
{
149+
testCase: {
150+
name: "pasteEndOfParagraphText",
151+
content: `Paragraph`,
152+
document: [
153+
{
154+
type: "paragraph",
155+
content: "Paragraph 1",
156+
},
157+
],
158+
getPasteSelection: (doc) => {
159+
const startPos = getPosOfTextNode(doc, "Paragraph 1", true);
160+
161+
return TextSelection.create(doc, startPos);
162+
},
163+
},
164+
executeTest: testPasteMarkdown,
165+
},
166+
];

tests/src/unit/core/clipboard/paste/runTests.test.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,29 @@ import { describe, it } from "vitest";
22

33
import { setupTestEditor } from "../../setupTestEditor.js";
44
import { testSchema } from "../../testSchema.js";
5-
import { getPasteTestInstances } from "./getPasteTestInstances.js";
5+
import {
6+
pasteTestInstancesHTML,
7+
pasteTestInstancesMarkdown,
8+
} from "./pasteTestInstances.js";
69

710
// Tests for verifying that clipboard data gets pasted into the editor properly.
811
// Used for specific cases for when content from outside the editor is pasted
912
// into it. This includes content from other editors, as well as content from
1013
// the web that has produced bugs in the past.
11-
describe("Paste tests", () => {
14+
describe("Paste tests (HTML)", () => {
1215
const getEditor = setupTestEditor(testSchema);
1316

14-
for (const { testCase, executeTest } of getPasteTestInstances()) {
17+
for (const { testCase, executeTest } of pasteTestInstancesHTML) {
18+
it(`${testCase.name}`, async () => {
19+
await executeTest(getEditor(), testCase);
20+
});
21+
}
22+
});
23+
24+
describe("Paste tests (Markdown)", () => {
25+
const getEditor = setupTestEditor(testSchema);
26+
27+
for (const { testCase, executeTest } of pasteTestInstancesMarkdown) {
1528
it(`${testCase.name}`, async () => {
1629
await executeTest(getEditor(), testCase);
1730
});

0 commit comments

Comments
 (0)