MCPcopy
hub / github.com/slab/quill / editTest

Function editTest

packages/quill/test/unit/core/quill.spec.ts:343–384  ·  view source on GitHub ↗
(
      oldText: string,
      oldSelection: number | Range,
      newText: string,
      newSelection: number | Range,
      expectedDelta: Delta,
    )

Source from the content-addressed store, hash-verified

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(

Callers 1

quill.spec.tsFile · 0.85

Calls 6

setTextMethod · 0.80
setNativeRangeMethod · 0.80
setupFunction · 0.70
setSelectionMethod · 0.45
updateMethod · 0.45
getContentsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…