Skip to content

Commit 226020d

Browse files
committed
Fixed and added tests
1 parent bd6519b commit 226020d

File tree

5 files changed

+239
-61
lines changed

5 files changed

+239
-61
lines changed

packages/core/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export function moveFirstBlockInColumn(
101101
false,
102102
),
103103
);
104-
const pos = tr.doc.resolve(column.bnBlock.beforePos);
104+
const pos = tr.doc.resolve(columnList.bnBlock.beforePos);
105105
tr.setSelection(TextSelection.between(pos, pos));
106106

107107
return pos;

packages/xl-multi-column/src/test/commands/__snapshots__/removeBlocks.test.ts.snap

Lines changed: 106 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -54,78 +54,124 @@ exports[`Test removeBlocks > Remove all blocks in column 1`] = `
5454
},
5555
"type": "paragraph",
5656
},
57+
{
58+
"children": [],
59+
"content": [
60+
{
61+
"styles": {},
62+
"text": "Column Paragraph 2",
63+
"type": "text",
64+
},
65+
],
66+
"id": "column-paragraph-2",
67+
"props": {
68+
"backgroundColor": "default",
69+
"textAlignment": "left",
70+
"textColor": "default",
71+
},
72+
"type": "paragraph",
73+
},
74+
{
75+
"children": [],
76+
"content": [
77+
{
78+
"styles": {},
79+
"text": "Column Paragraph 3",
80+
"type": "text",
81+
},
82+
],
83+
"id": "column-paragraph-3",
84+
"props": {
85+
"backgroundColor": "default",
86+
"textAlignment": "left",
87+
"textColor": "default",
88+
},
89+
"type": "paragraph",
90+
},
91+
{
92+
"children": [],
93+
"content": [
94+
{
95+
"styles": {},
96+
"text": "Paragraph 2",
97+
"type": "text",
98+
},
99+
],
100+
"id": "paragraph-2",
101+
"props": {
102+
"backgroundColor": "default",
103+
"textAlignment": "left",
104+
"textColor": "default",
105+
},
106+
"type": "paragraph",
107+
},
108+
{
109+
"children": [],
110+
"content": [],
111+
"id": "trailing-paragraph",
112+
"props": {
113+
"backgroundColor": "default",
114+
"textAlignment": "left",
115+
"textColor": "default",
116+
},
117+
"type": "paragraph",
118+
},
119+
]
120+
`;
121+
122+
exports[`Test removeBlocks > Remove all blocks in columns 1`] = `
123+
[
57124
{
58125
"children": [
59126
{
60-
"children": [
127+
"children": [],
128+
"content": [
61129
{
62-
"children": [],
63-
"content": [],
64-
"id": "0",
65-
"props": {
66-
"backgroundColor": "default",
67-
"textAlignment": "left",
68-
"textColor": "default",
69-
},
70-
"type": "paragraph",
130+
"styles": {},
131+
"text": "Nested Paragraph 0",
132+
"type": "text",
71133
},
72134
],
73-
"content": undefined,
74-
"id": "column-0",
135+
"id": "nested-paragraph-0",
75136
"props": {
76-
"width": 1,
137+
"backgroundColor": "default",
138+
"textAlignment": "left",
139+
"textColor": "default",
77140
},
78-
"type": "column",
141+
"type": "paragraph",
79142
},
143+
],
144+
"content": [
80145
{
81-
"children": [
82-
{
83-
"children": [],
84-
"content": [
85-
{
86-
"styles": {},
87-
"text": "Column Paragraph 2",
88-
"type": "text",
89-
},
90-
],
91-
"id": "column-paragraph-2",
92-
"props": {
93-
"backgroundColor": "default",
94-
"textAlignment": "left",
95-
"textColor": "default",
96-
},
97-
"type": "paragraph",
98-
},
99-
{
100-
"children": [],
101-
"content": [
102-
{
103-
"styles": {},
104-
"text": "Column Paragraph 3",
105-
"type": "text",
106-
},
107-
],
108-
"id": "column-paragraph-3",
109-
"props": {
110-
"backgroundColor": "default",
111-
"textAlignment": "left",
112-
"textColor": "default",
113-
},
114-
"type": "paragraph",
115-
},
116-
],
117-
"content": undefined,
118-
"id": "column-1",
119-
"props": {
120-
"width": 1,
121-
},
122-
"type": "column",
146+
"styles": {},
147+
"text": "Paragraph 0",
148+
"type": "text",
123149
},
124150
],
125-
"content": undefined,
126-
"id": "column-list-0",
127-
"props": {},
128-
"type": "columnList",
151+
"id": "paragraph-0",
152+
"props": {
153+
"backgroundColor": "default",
154+
"textAlignment": "left",
155+
"textColor": "default",
156+
},
157+
"type": "paragraph",
158+
},
159+
{
160+
"children": [],
161+
"content": [
162+
{
163+
"styles": {},
164+
"text": "Paragraph 1",
165+
"type": "text",
166+
},
167+
],
168+
"id": "paragraph-1",
169+
"props": {
170+
"backgroundColor": "default",
171+
"textAlignment": "left",
172+
"textColor": "default",
173+
},
174+
"type": "paragraph",
129175
},
130176
{
131177
"children": [],

packages/xl-multi-column/src/test/commands/__snapshots__/replaceBlocks.test.ts.snap

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,107 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3+
exports[`Test replaceBlocks > Replace all blocks in columns with single block 1`] = `
4+
[
5+
{
6+
"children": [
7+
{
8+
"children": [],
9+
"content": [
10+
{
11+
"styles": {},
12+
"text": "Nested Paragraph 0",
13+
"type": "text",
14+
},
15+
],
16+
"id": "nested-paragraph-0",
17+
"props": {
18+
"backgroundColor": "default",
19+
"textAlignment": "left",
20+
"textColor": "default",
21+
},
22+
"type": "paragraph",
23+
},
24+
],
25+
"content": [
26+
{
27+
"styles": {},
28+
"text": "Paragraph 0",
29+
"type": "text",
30+
},
31+
],
32+
"id": "paragraph-0",
33+
"props": {
34+
"backgroundColor": "default",
35+
"textAlignment": "left",
36+
"textColor": "default",
37+
},
38+
"type": "paragraph",
39+
},
40+
{
41+
"children": [],
42+
"content": [
43+
{
44+
"styles": {},
45+
"text": "Paragraph 1",
46+
"type": "text",
47+
},
48+
],
49+
"id": "paragraph-1",
50+
"props": {
51+
"backgroundColor": "default",
52+
"textAlignment": "left",
53+
"textColor": "default",
54+
},
55+
"type": "paragraph",
56+
},
57+
{
58+
"children": [],
59+
"content": [
60+
{
61+
"styles": {},
62+
"text": "New Paragraph",
63+
"type": "text",
64+
},
65+
],
66+
"id": "0",
67+
"props": {
68+
"backgroundColor": "default",
69+
"textAlignment": "left",
70+
"textColor": "default",
71+
},
72+
"type": "paragraph",
73+
},
74+
{
75+
"children": [],
76+
"content": [
77+
{
78+
"styles": {},
79+
"text": "Paragraph 2",
80+
"type": "text",
81+
},
82+
],
83+
"id": "paragraph-2",
84+
"props": {
85+
"backgroundColor": "default",
86+
"textAlignment": "left",
87+
"textColor": "default",
88+
},
89+
"type": "paragraph",
90+
},
91+
{
92+
"children": [],
93+
"content": [],
94+
"id": "trailing-paragraph",
95+
"props": {
96+
"backgroundColor": "default",
97+
"textAlignment": "left",
98+
"textColor": "default",
99+
},
100+
"type": "paragraph",
101+
},
102+
]
103+
`;
104+
3105
exports[`Test replaceBlocks > Replace paragraph with column list above column list 1`] = `
4106
[
5107
{

packages/xl-multi-column/src/test/commands/removeBlocks.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ describe("Test removeBlocks", () => {
1111
expect(getEditor().document).toMatchSnapshot();
1212
});
1313

14+
it("Remove all blocks in columns", () => {
15+
getEditor().removeBlocks([
16+
"column-paragraph-0",
17+
"column-paragraph-1",
18+
"column-paragraph-2",
19+
"column-paragraph-3",
20+
]);
21+
22+
expect(getEditor().document).toMatchSnapshot();
23+
});
24+
1425
it("Remove all columns in columnList", () => {
1526
getEditor().removeBlocks(["column-0", "column-1"]);
1627

packages/xl-multi-column/src/test/commands/replaceBlocks.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,23 @@ describe("Test replaceBlocks", () => {
3737

3838
expect(getEditor().document).toMatchSnapshot();
3939
});
40+
41+
it("Replace all blocks in columns with single block", () => {
42+
getEditor().replaceBlocks(
43+
[
44+
"column-paragraph-0",
45+
"column-paragraph-1",
46+
"column-paragraph-2",
47+
"column-paragraph-3",
48+
],
49+
[
50+
{
51+
type: "paragraph",
52+
content: "New Paragraph",
53+
},
54+
],
55+
);
56+
57+
expect(getEditor().document).toMatchSnapshot();
58+
});
4059
});

0 commit comments

Comments
 (0)