(
oldText: string,
oldSelection: number | Range,
newText: string,
newSelection: number | Range,
expectedDelta: Delta,
)
| 341 | }); |
| 342 | |
| 343 | const editTest = ( |
| 344 | oldText: string, |
| 345 | oldSelection: number | Range, |
| 346 | newText: string, |
| 347 | newSelection: number | Range, |
| 348 | expectedDelta: Delta, |
| 349 | ) => { |
| 350 | return async () => { |
| 351 | const { quill } = setup(); |
| 352 | quill.setText(`${oldText}\n`); |
| 353 | // @ts-expect-error |
| 354 | quill.setSelection(oldSelection); |
| 355 | quill.update(); |
| 356 | const oldContents = quill.getContents(); |
| 357 | const textNode = quill.root.firstChild?.firstChild as Text; |
| 358 | textNode.data = newText; |
| 359 | if (typeof newSelection === 'number') { |
| 360 | quill.selection.setNativeRange(textNode, newSelection); |
| 361 | } else { |
| 362 | quill.selection.setNativeRange( |
| 363 | textNode, |
| 364 | newSelection.index, |
| 365 | textNode, |
| 366 | newSelection.index + newSelection.length, |
| 367 | ); |
| 368 | } |
| 369 | await new Promise((r) => setTimeout(r, 1)); |
| 370 | const calls = ( |
| 371 | quill.emitter.emit as MockedFunction<typeof quill.emitter.emit> |
| 372 | ).mock.calls; |
| 373 | if (calls[calls.length - 1][1] === Emitter.events.SELECTION_CHANGE) { |
| 374 | calls.pop(); |
| 375 | } |
| 376 | const args = calls.pop(); |
| 377 | expect(args).toEqual([ |
| 378 | Emitter.events.TEXT_CHANGE, |
| 379 | expectedDelta, |
| 380 | oldContents, |
| 381 | Emitter.sources.USER, |
| 382 | ]); |
| 383 | }; |
| 384 | }; |
| 385 | |
| 386 | describe('insert a in aaaa', () => { |
| 387 | test( |
no test coverage detected
searching dependent graphs…