-
-
Notifications
You must be signed in to change notification settings - Fork 346
/
list.spec.ts
345 lines (299 loc) 路 8.56 KB
/
list.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
import { test } from '@playwright/test';
import {
assertBlockChildrenFlavours,
assertBlockChildrenIds,
assertBlockCount,
assertBlockType,
assertRichTexts,
assertSelection,
assertStoreMatchJSX,
assertTextContent,
} from './utils/asserts';
import {
convertToBulletedListByClick,
convertToNumberedListByClick,
enterPlaygroundRoom,
enterPlaygroundWithList,
focusRichText,
pressEnter,
redoByClick,
pressShiftTab,
undoByClick,
undoByKeyboard,
pressTab,
initEmptyState,
} from './utils/actions';
test('add new bulleted list', async ({ page }) => {
await enterPlaygroundRoom(page);
await initEmptyState(page);
await focusRichText(page, 0);
await convertToBulletedListByClick(page);
await page.keyboard.type('aa');
await pressEnter(page);
await page.keyboard.type('aa');
await pressEnter(page);
await assertRichTexts(page, ['aa', 'aa', '\n']);
await assertBlockCount(page, 'list', 3);
});
test('convert to numbered list block', async ({ page }) => {
await enterPlaygroundRoom(page);
await initEmptyState(page);
await focusRichText(page, 0); // created 0, 1, 2
await convertToBulletedListByClick(page); // replaced 2 to 3
await convertToNumberedListByClick(page);
await focusRichText(page, 0);
const listSelector = '.affine-list-rich-text-wrapper';
const bulletIconSelector = `${listSelector} > div`;
await assertTextContent(page, bulletIconSelector, /1 \./);
await undoByClick(page);
// const numberIconSelector = `${listSelector} > svg`;
// await expect(page.locator(numberIconSelector)).toHaveCount(1);
await redoByClick(page);
await focusRichText(page, 0);
await page.keyboard.type('aa');
await pressEnter(page); // created 4
await assertBlockType(page, '4', 'numbered');
await page.keyboard.type('aa');
await pressEnter(page); // created 5
await assertBlockType(page, '5', 'numbered');
await page.keyboard.press('Tab');
await assertBlockType(page, '6', 'numbered');
});
test('indent list block', async ({ page }) => {
await enterPlaygroundWithList(page); // 0(1(2,3,4))
await focusRichText(page, 1);
await page.keyboard.type('hello');
await assertRichTexts(page, ['\n', 'hello', '\n']);
await page.keyboard.press('Tab'); // 0(1(2(5)4))
await assertRichTexts(page, ['\n', 'hello', '\n']);
await assertBlockChildrenIds(page, '1', ['2', '4']);
await assertBlockChildrenIds(page, '2', ['5']);
await undoByKeyboard(page); // 0(1(2,3,4))
await assertBlockChildrenIds(page, '1', ['2', '3', '4']);
});
test('unindent list block', async ({ page }) => {
await enterPlaygroundWithList(page); // 0(1(2,3,4))
await focusRichText(page, 1);
await page.keyboard.press('Tab'); // 0(1(2(5)4))
await assertBlockChildrenIds(page, '1', ['2', '4']);
await assertBlockChildrenIds(page, '2', ['5']);
await pressShiftTab(page); // 0(1(2,6,4))
await assertBlockChildrenIds(page, '1', ['2', '6', '4']);
await pressShiftTab(page);
await assertBlockChildrenIds(page, '1', ['2', '6', '4']);
});
test('insert new list block by enter', async ({ page }) => {
await enterPlaygroundWithList(page);
await assertRichTexts(page, ['\n', '\n', '\n']);
await focusRichText(page, 1);
await page.keyboard.type('hello');
await assertRichTexts(page, ['\n', 'hello', '\n']);
await pressEnter(page);
await page.keyboard.type('world');
await assertRichTexts(page, ['\n', 'hello', 'world', '\n']);
await assertBlockChildrenFlavours(page, '1', [
'affine:list',
'affine:list',
'affine:list',
'affine:list',
]);
});
test('delete at start of list block', async ({ page }) => {
await enterPlaygroundWithList(page);
await focusRichText(page, 1);
await page.keyboard.press('Backspace');
await assertBlockChildrenFlavours(page, '1', [
'affine:list',
'affine:paragraph',
'affine:list',
]);
await assertSelection(page, 1, 0, 0);
await undoByClick(page);
await assertBlockChildrenFlavours(page, '1', [
'affine:list',
'affine:list',
'affine:list',
]);
await assertSelection(page, 1, 0, 0);
});
test('nested list blocks', async ({ page }) => {
await enterPlaygroundWithList(page);
await focusRichText(page, 0);
await page.keyboard.type('123');
await focusRichText(page, 1);
await pressTab(page);
await page.keyboard.type('456');
await focusRichText(page, 2);
await pressTab(page);
await pressTab(page);
await page.keyboard.type('789');
await assertStoreMatchJSX(
page,
/*xml*/ `
<affine:page>
<affine:group
prop:xywh="[0,0,720,96]"
>
<affine:list
prop:checked={false}
prop:text="123"
prop:type="bulleted"
>
<affine:list
prop:checked={false}
prop:text="456"
prop:type="bulleted"
>
<affine:list
prop:checked={false}
prop:text="789"
prop:type="bulleted"
/>
</affine:list>
</affine:list>
</affine:group>
</affine:page>`
);
await focusRichText(page, 1);
await pressShiftTab(page);
await assertStoreMatchJSX(
page,
/*xml*/ `
<affine:page>
<affine:group
prop:xywh="[0,0,720,96]"
>
<affine:list
prop:checked={false}
prop:text="123"
prop:type="bulleted"
/>
<affine:list
prop:checked={false}
prop:text="456"
prop:type="bulleted"
>
<affine:list
prop:checked={false}
prop:text="789"
prop:type="bulleted"
/>
</affine:list>
</affine:group>
</affine:page>`
);
});
test('basic indent and unindent', async ({ page }) => {
await enterPlaygroundRoom(page);
await initEmptyState(page);
await focusRichText(page);
await page.keyboard.type('text1');
await pressEnter(page);
await page.keyboard.type('text2');
await assertStoreMatchJSX(
page,
/*xml*/ `
<affine:page>
<affine:group
prop:xywh="[0,0,720,72]"
>
<affine:paragraph
prop:text="text1"
prop:type="text"
/>
<affine:paragraph
prop:text="text2"
prop:type="text"
/>
</affine:group>
</affine:page>`
);
await page.keyboard.press('Tab');
await assertStoreMatchJSX(
page,
/*xml*/ `
<affine:page>
<affine:group
prop:xywh="[0,0,720,72]"
>
<affine:paragraph
prop:text="text1"
prop:type="text"
>
<affine:paragraph
prop:text="text2"
prop:type="text"
/>
</affine:paragraph>
</affine:group>
</affine:page>`
);
await pressShiftTab(page);
await assertStoreMatchJSX(
page,
/*xml*/ `
<affine:page>
<affine:group
prop:xywh="[0,0,720,72]"
>
<affine:paragraph
prop:text="text1"
prop:type="text"
/>
<affine:paragraph
prop:text="text2"
prop:type="text"
/>
</affine:group>
</affine:page>`
);
});
test('enter list block with empty text', async ({ page }) => {
await enterPlaygroundWithList(page); // 0(1(2,3,4))
await focusRichText(page, 1);
await pressTab(page);
await focusRichText(page, 2);
await pressTab(page);
await assertBlockChildrenIds(page, '2', ['5', '6']); // 0(1(2,(5,6)))
await focusRichText(page, 2);
await pressEnter(page);
await assertBlockChildrenIds(page, '2', ['5']);
await assertBlockType(page, '7', 'bulleted');
await pressEnter(page);
await assertBlockType(page, '8', 'text');
await undoByClick(page);
await undoByClick(page);
await assertBlockChildrenIds(page, '2', ['5', '6']); // 0(1(2,(5,6)))
await focusRichText(page, 1);
await pressEnter(page);
await assertBlockChildrenIds(page, '2', ['5', '9', '6']);
await undoByClick(page);
await assertBlockChildrenIds(page, '2', ['5', '6']); // 0(1(2,(5,6)))
await focusRichText(page, 0);
await pressEnter(page);
await assertBlockChildrenIds(page, '2', ['10', '5', '6']);
await undoByClick(page);
await assertBlockChildrenIds(page, '2', ['5', '6']); // 0(1(2,(5,6)))
});
test('enter list block with non-empty text', async ({ page }) => {
await enterPlaygroundWithList(page); // 0(1(2,3,4))
await focusRichText(page, 0);
await page.keyboard.type('aa');
await focusRichText(page, 1);
await page.keyboard.type('bb');
await pressTab(page);
await focusRichText(page, 2);
await page.keyboard.type('cc');
await pressTab(page);
await assertBlockChildrenIds(page, '2', ['5', '6']); // 0(1(2,(5,6)))
await focusRichText(page, 1);
await pressEnter(page);
await assertBlockChildrenIds(page, '2', ['5', '7', '6']);
await undoByClick(page);
await assertBlockChildrenIds(page, '2', ['5', '6']); // 0(1(2,(5,6)))
await focusRichText(page, 0);
await pressEnter(page);
await assertBlockChildrenIds(page, '2', ['8', '5', '6']);
await undoByClick(page);
await assertBlockChildrenIds(page, '2', ['5', '6']); // 0(1(2,(5,6)))
});