-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
327 lines (314 loc) · 11.1 KB
/
index.test.js
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
const slateType = require('.');
describe('transformSelection', () => {
describe('text operations', () => {
function insertText(offset, path = [0, 0]) {
return {
type: 'insert_text',
path,
offset,
text: 'hello',
marks: [],
};
}
function removeText(offset, path = [0, 0]) {
return {
type: 'remove_text',
path,
offset,
text: 'hello',
};
}
function selection(anchorOffset, focusOffset, anchorPath = [0, 0], focusPath = [0, 0]) {
const anchorNode = anchorPath[0];
const focusNode = focusPath[0];
const isBackward = anchorNode === focusNode ?
focusOffset < anchorOffset :
focusNode < anchorNode;
return {
anchorPath,
anchorOffset,
focusPath,
focusOffset,
isBackward,
};
}
describe('insert_text', () => {
test('insert before selection position', () => {
expect(slateType.transformSelection(
selection(10, 10),
[insertText(5)],
)).toEqual(selection(15, 15));
});
test('insert at selection position', () => {
expect(slateType.transformSelection(
selection(10, 10),
[insertText(10)],
)).toEqual(selection(10, 10));
});
test('insert after selection position', () => {
expect(slateType.transformSelection(
selection(10, 10),
[insertText(15)],
)).toEqual(selection(10, 10));
});
test('insert before selection range anchor', () => {
expect(slateType.transformSelection(
selection(10, 20),
[insertText(5)],
)).toEqual(selection(15, 25));
});
test('insert at selection range anchor', () => {
expect(slateType.transformSelection(
selection(10, 20),
[insertText(10)],
)).toEqual(selection(10, 25));
});
test('insert between selection range anchor and focus', () => {
expect(slateType.transformSelection(
selection(10, 20),
[insertText(12)],
)).toEqual(selection(10, 25));
});
test('insert at selection range focus', () => {
expect(slateType.transformSelection(
selection(10, 20),
[insertText(20)],
)).toEqual(selection(10, 20));
});
test('insert after selection range focus', () => {
expect(slateType.transformSelection(
selection(10, 20),
[insertText(25)],
)).toEqual(selection(10, 20));
});
test('insert before backwards selection range focus', () => {
expect(slateType.transformSelection(
selection(20, 10),
[insertText(8)],
)).toEqual(selection(25, 15));
});
test('insert at backwards selection range focus', () => {
expect(slateType.transformSelection(
selection(20, 10),
[insertText(10)],
)).toEqual(selection(25, 10));
});
test('insert between backwards selection range focus and anchor', () => {
expect(slateType.transformSelection(
selection(20, 10),
[insertText(12)],
)).toEqual(selection(25, 10));
});
test('insert at backwards selection range anchor', () => {
expect(slateType.transformSelection(
selection(20, 10),
[insertText(20)],
)).toEqual(selection(20, 10));
});
test('insert after backwards selection range anchor', () => {
expect(slateType.transformSelection(
selection(20, 10),
[insertText(25)],
)).toEqual(selection(20, 10));
});
test('insert before multinode selection range anchor', () => {
expect(slateType.transformSelection(
selection(10, 20, [1, 0], [4, 0]),
[insertText(5, [1, 0])],
)).toEqual(selection(15, 20, [1, 0], [4, 0]));
});
test('insert after multinode selection range anchor', () => {
expect(slateType.transformSelection(
selection(10, 20, [1, 0], [4, 0]),
[insertText(15, [1, 0])],
)).toEqual(selection(10, 20, [1, 0], [4, 0]));
});
test('insert before multinode selection range focus', () => {
expect(slateType.transformSelection(
selection(10, 20, [1, 0], [4, 0]),
[insertText(15, [4, 0])],
)).toEqual(selection(10, 25, [1, 0], [4, 0]));
});
test('insert after multinode selection range focus', () => {
expect(slateType.transformSelection(
selection(10, 20, [1, 0], [4, 0]),
[insertText(25, [4, 0])],
)).toEqual(selection(10, 20, [1, 0], [4, 0]));
});
test('insert before backwards multinode selection range focus', () => {
expect(slateType.transformSelection(
selection(10, 20, [4, 0], [1, 0]),
[insertText(5, [4, 0])],
)).toEqual(selection(15, 20, [4, 0], [1, 0]));
});
test('insert after backwards multinode selection range focus', () => {
expect(slateType.transformSelection(
selection(10, 20, [4, 0], [1, 0]),
[insertText(15, [4, 0])],
)).toEqual(selection(10, 20, [4, 0], [1, 0]));
});
test('insert before backwards multinode selection range anchor', () => {
expect(slateType.transformSelection(
selection(10, 20, [4, 0], [1, 0]),
[insertText(15, [1, 0])],
)).toEqual(selection(10, 25, [4, 0], [1, 0]));
});
test('insert after backwards multinode selection range anchor', () => {
expect(slateType.transformSelection(
selection(10, 20, [4, 0], [1, 0]),
[insertText(25, [1, 0])],
)).toEqual(selection(10, 20, [4, 0], [1, 0]));
});
});
describe('remove_text', () => {
test('remove before selection position', () => {
expect(slateType.transformSelection(
selection(10, 10),
[removeText(5)],
)).toEqual(selection(5, 5));
});
test('remove at selection position', () => {
expect(slateType.transformSelection(
selection(10, 10),
[removeText(10)],
)).toEqual(selection(10, 10));
});
test('remove after selection position', () => {
expect(slateType.transformSelection(
selection(10, 10),
[removeText(15)],
)).toEqual(selection(10, 10));
});
test('remove before selection range anchor', () => {
expect(slateType.transformSelection(
selection(10, 20),
[removeText(5)],
)).toEqual(selection(5, 15));
});
test('remove at selection range anchor', () => {
expect(slateType.transformSelection(
selection(10, 20),
[removeText(10)],
)).toEqual(selection(10, 15));
});
test('remove between selection range anchor and focus', () => {
expect(slateType.transformSelection(
selection(10, 20),
[removeText(12)],
)).toEqual(selection(10, 15));
});
test('remove at selection range focus', () => {
expect(slateType.transformSelection(
selection(10, 20),
[removeText(20)],
)).toEqual(selection(10, 20));
});
test('remove after selection range focus', () => {
expect(slateType.transformSelection(
selection(10, 20),
[removeText(25)],
)).toEqual(selection(10, 20));
});
test('remove text from the beginning of the range', () => {
expect(slateType.transformSelection(
selection(10, 20),
[removeText(8)],
)).toEqual(selection(8, 15));
});
test('remove text from the end of the range', () => {
expect(slateType.transformSelection(
selection(10, 20),
[removeText(18)],
)).toEqual(selection(10, 18));
});
test('remove before backwards selection range focus', () => {
expect(slateType.transformSelection(
selection(20, 10),
[removeText(5)],
)).toEqual(selection(15, 5));
});
test('remove at backwards selection range focus', () => {
expect(slateType.transformSelection(
selection(20, 10),
[removeText(10)],
)).toEqual(selection(15, 10));
});
test('remove between backwards selection range focus and anchor', () => {
expect(slateType.transformSelection(
selection(20, 10),
[removeText(12)],
)).toEqual(selection(15, 10));
});
test('remove at backwards selection range anchor', () => {
expect(slateType.transformSelection(
selection(20, 10),
[removeText(20)],
)).toEqual(selection(20, 10));
});
test('remove after backwards selection range anchor', () => {
expect(slateType.transformSelection(
selection(20, 10),
[removeText(25)],
)).toEqual(selection(20, 10));
});
test('remove before multinode selection range anchor', () => {
expect(slateType.transformSelection(
selection(10, 20, [1, 0], [4, 0]),
[removeText(5, [1, 0])],
)).toEqual(selection(5, 20, [1, 0], [4, 0]));
});
test('remove after multinode selection range anchor', () => {
expect(slateType.transformSelection(
selection(10, 20, [1, 0], [4, 0]),
[removeText(15, [1, 0])],
)).toEqual(selection(10, 20, [1, 0], [4, 0]));
});
test('remove before multinode selection range focus', () => {
expect(slateType.transformSelection(
selection(10, 20, [1, 0], [4, 0]),
[removeText(15, [4, 0])],
)).toEqual(selection(10, 15, [1, 0], [4, 0]));
});
test('remove after multinode selection range focus', () => {
expect(slateType.transformSelection(
selection(10, 20, [1, 0], [4, 0]),
[removeText(25, [4, 0])],
)).toEqual(selection(10, 20, [1, 0], [4, 0]));
});
test('remove before backwards multinode selection range focus', () => {
expect(slateType.transformSelection(
selection(10, 20, [4, 0], [1, 0]),
[removeText(5, [4, 0])],
)).toEqual(selection(5, 20, [4, 0], [1, 0]));
});
test('remove after backwards multinode selection range focus', () => {
expect(slateType.transformSelection(
selection(10, 20, [4, 0], [1, 0]),
[removeText(15, [4, 0])],
)).toEqual(selection(10, 20, [4, 0], [1, 0]));
});
test('remove before backwards multinode selection range anchor', () => {
expect(slateType.transformSelection(
selection(10, 20, [4, 0], [1, 0]),
[removeText(15, [1, 0])],
)).toEqual(selection(10, 15, [4, 0], [1, 0]));
});
test('remove after backwards multinode selection range anchor', () => {
expect(slateType.transformSelection(
selection(10, 20, [4, 0], [1, 0]),
[removeText(25, [1, 0])],
)).toEqual(selection(10, 20, [4, 0], [1, 0]));
});
});
});
describe('node operations', () => {
describe('split_node', () => {
});
describe('insert_node', () => {
});
describe('remove_node', () => {
});
describe('merge_node', () => {
});
});
});