All files / json-crdt-extensions/peritext/slice/__tests__ setup.ts

100% Statements 19/19
100% Branches 0/0
100% Functions 2/2
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 253x 3x   3x 601x 601x       601x 601x 601x 601x 601x 601x 601x 601x 7x 7x 7x 7x   601x    
import {Model} from '../../../../json-crdt/model';
import {Peritext} from '../../Peritext';
 
export const setup = () => {
  const model = Model.withLogicalClock(12345678);
  model.api.root({
    text: '',
    slices: [],
  });
  model.api.str(['text']).ins(0, 'wworld');
  model.api.str(['text']).ins(0, 'helo ');
  model.api.str(['text']).ins(2, 'l');
  model.api.str(['text']).del(7, 1);
  model.api.str(['text']).ins(11, ' this game is awesome');
  const peritext = new Peritext(model, model.api.str(['text']).node, model.api.arr(['slices']).node);
  const slices = peritext.savedSlices;
  const encodeAndDecode = () => {
    const buf = model.toBinary();
    const model2 = Model.fromBinary(buf);
    const peritext2 = new Peritext(model2, model2.api.str(['text']).node, model2.api.arr(['slices']).node);
    return {model2, peritext2};
  };
  return {model, peritext, slices, encodeAndDecode};
};