testomatio-editor-blocks 0.4.20 → 0.4.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -43,6 +43,10 @@ const writeStepViewMode = (mode) => {
|
|
|
43
43
|
//
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
|
+
export const isEmptyParagraph = (b) => b.type === "paragraph" &&
|
|
47
|
+
(!Array.isArray(b.content) ||
|
|
48
|
+
b.content.length === 0 ||
|
|
49
|
+
b.content.every((n) => { var _a; return n.type === "text" && !((_a = n.text) === null || _a === void 0 ? void 0 : _a.trim()); }));
|
|
46
50
|
export const stepBlock = createReactBlockSpec({
|
|
47
51
|
type: "testStep",
|
|
48
52
|
content: "none",
|
|
@@ -82,9 +86,13 @@ export const stepBlock = createReactBlockSpec({
|
|
|
82
86
|
return 1;
|
|
83
87
|
let count = 1;
|
|
84
88
|
for (let i = blockIndex - 1; i >= 0; i--) {
|
|
85
|
-
|
|
89
|
+
const b = allBlocks[i];
|
|
90
|
+
if (b.type === "testStep") {
|
|
86
91
|
count++;
|
|
87
92
|
}
|
|
93
|
+
else if (isEmptyParagraph(b)) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
88
96
|
else {
|
|
89
97
|
break;
|
|
90
98
|
}
|
|
@@ -99,7 +107,7 @@ export const stepBlock = createReactBlockSpec({
|
|
|
99
107
|
return false;
|
|
100
108
|
for (let i = blockIndex - 1; i >= 0; i--) {
|
|
101
109
|
const b = allBlocks[i];
|
|
102
|
-
if (b.type === "testStep" || b.type === "snippet") {
|
|
110
|
+
if (b.type === "testStep" || b.type === "snippet" || isEmptyParagraph(b)) {
|
|
103
111
|
continue;
|
|
104
112
|
}
|
|
105
113
|
if (b.type === "heading") {
|
package/package.json
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import { customSchema } from "../customSchema";
|
|
3
|
+
import { isEmptyParagraph } from "./step";
|
|
4
|
+
|
|
5
|
+
describe("isEmptyParagraph", () => {
|
|
6
|
+
it("returns true for paragraph with no content", () => {
|
|
7
|
+
expect(isEmptyParagraph({ type: "paragraph", content: [], children: [] })).toBe(true);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("returns true for paragraph with undefined content", () => {
|
|
11
|
+
expect(isEmptyParagraph({ type: "paragraph", children: [] })).toBe(true);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("returns true for paragraph with only whitespace text", () => {
|
|
15
|
+
expect(
|
|
16
|
+
isEmptyParagraph({
|
|
17
|
+
type: "paragraph",
|
|
18
|
+
content: [{ type: "text", text: " " }],
|
|
19
|
+
children: [],
|
|
20
|
+
}),
|
|
21
|
+
).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("returns false for paragraph with text content", () => {
|
|
25
|
+
expect(
|
|
26
|
+
isEmptyParagraph({
|
|
27
|
+
type: "paragraph",
|
|
28
|
+
content: [{ type: "text", text: "hello" }],
|
|
29
|
+
children: [],
|
|
30
|
+
}),
|
|
31
|
+
).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("returns false for non-paragraph blocks", () => {
|
|
35
|
+
expect(isEmptyParagraph({ type: "heading", content: [], children: [] })).toBe(false);
|
|
36
|
+
expect(isEmptyParagraph({ type: "testStep", content: [], children: [] })).toBe(false);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
3
39
|
|
|
4
40
|
describe("custom block specs", () => {
|
|
5
41
|
it("registers the step block", () => {
|
|
@@ -47,6 +47,12 @@ const writeStepViewMode = (mode: StepViewMode) => {
|
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
+
export const isEmptyParagraph = (b: any): boolean =>
|
|
51
|
+
b.type === "paragraph" &&
|
|
52
|
+
(!Array.isArray(b.content) ||
|
|
53
|
+
b.content.length === 0 ||
|
|
54
|
+
b.content.every((n: any) => n.type === "text" && !n.text?.trim()));
|
|
55
|
+
|
|
50
56
|
export const stepBlock = createReactBlockSpec(
|
|
51
57
|
{
|
|
52
58
|
type: "testStep",
|
|
@@ -91,8 +97,11 @@ export const stepBlock = createReactBlockSpec(
|
|
|
91
97
|
|
|
92
98
|
let count = 1;
|
|
93
99
|
for (let i = blockIndex - 1; i >= 0; i--) {
|
|
94
|
-
|
|
100
|
+
const b = allBlocks[i];
|
|
101
|
+
if (b.type === "testStep") {
|
|
95
102
|
count++;
|
|
103
|
+
} else if (isEmptyParagraph(b)) {
|
|
104
|
+
continue;
|
|
96
105
|
} else {
|
|
97
106
|
break;
|
|
98
107
|
}
|
|
@@ -108,7 +117,7 @@ export const stepBlock = createReactBlockSpec(
|
|
|
108
117
|
|
|
109
118
|
for (let i = blockIndex - 1; i >= 0; i--) {
|
|
110
119
|
const b = allBlocks[i];
|
|
111
|
-
if (b.type === "testStep" || b.type === "snippet") {
|
|
120
|
+
if (b.type === "testStep" || b.type === "snippet" || isEmptyParagraph(b)) {
|
|
112
121
|
continue;
|
|
113
122
|
}
|
|
114
123
|
if (b.type === "heading") {
|
|
@@ -920,6 +920,46 @@ describe("markdownToBlocks", () => {
|
|
|
920
920
|
);
|
|
921
921
|
});
|
|
922
922
|
|
|
923
|
+
it("parses multiple steps separated by blank lines", () => {
|
|
924
|
+
const markdown = [
|
|
925
|
+
"## Steps",
|
|
926
|
+
"* asjkldnkasndkj",
|
|
927
|
+
" *Expected*: slkednfkjsdnfkjsdnf",
|
|
928
|
+
"",
|
|
929
|
+
"* sdfnsikdfnsikdn",
|
|
930
|
+
" *Expected*: sedfnskdijfns",
|
|
931
|
+
"",
|
|
932
|
+
"* sdfnksdjfnsdknf",
|
|
933
|
+
" *Expected*: sdjfnskdjfnskdfn",
|
|
934
|
+
].join("\n");
|
|
935
|
+
|
|
936
|
+
const blocks = markdownToBlocks(markdown);
|
|
937
|
+
const stepBlocks = blocks.filter((block) => block.type === "testStep");
|
|
938
|
+
|
|
939
|
+
expect(stepBlocks).toHaveLength(3);
|
|
940
|
+
|
|
941
|
+
expect(stepBlocks[0].props).toEqual({
|
|
942
|
+
stepTitle: "asjkldnkasndkj",
|
|
943
|
+
stepData: "",
|
|
944
|
+
expectedResult: "slkednfkjsdnfkjsdnf\n",
|
|
945
|
+
listStyle: "bullet",
|
|
946
|
+
});
|
|
947
|
+
|
|
948
|
+
expect(stepBlocks[1].props).toEqual({
|
|
949
|
+
stepTitle: "sdfnsikdfnsikdn",
|
|
950
|
+
stepData: "",
|
|
951
|
+
expectedResult: "sedfnskdijfns\n",
|
|
952
|
+
listStyle: "bullet",
|
|
953
|
+
});
|
|
954
|
+
|
|
955
|
+
expect(stepBlocks[2].props).toEqual({
|
|
956
|
+
stepTitle: "sdfnksdjfnsdknf",
|
|
957
|
+
stepData: "",
|
|
958
|
+
expectedResult: "sdjfnskdjfnskdfn",
|
|
959
|
+
listStyle: "bullet",
|
|
960
|
+
});
|
|
961
|
+
});
|
|
962
|
+
|
|
923
963
|
it("round-trips simple blocks", () => {
|
|
924
964
|
const blocks: CustomEditorBlock[] = [
|
|
925
965
|
{
|