Skip to content

Commit

Permalink
fix: add more test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Jocs committed Oct 26, 2024
1 parent f0eed4c commit 98c0fff
Showing 1 changed file with 66 additions and 7 deletions.
73 changes: 66 additions & 7 deletions packages/core/src/docs/data-model/text-x/__tests__/apply.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,13 +459,6 @@ describe('apply method', () => {
const resultC = TextX.apply(doc3, composedAction1);
const resultD = TextX.apply(doc4, composedAction2);

// console.log(JSON.stringify(resultA, null, 2));
// console.log(JSON.stringify(resultB, null, 2));

// console.log('composedAction1', JSON.stringify(composedAction1, null, 2));

// console.log(JSON.stringify(resultC, null, 2));

expect(resultA).toEqual(resultB);
expect(resultC).toEqual(resultD);
expect(resultA).toEqual(resultC);
Expand Down Expand Up @@ -527,6 +520,72 @@ describe('apply method', () => {
const resultC = TextX.apply(doc3, composedAction1);
const resultD = TextX.apply(doc4, composedAction2);

expect(resultA).toEqual(resultB);
expect(resultC).toEqual(resultD);
expect(resultA).toEqual(resultC);
expect(composedAction1).toEqual(composedAction2);
});

it('should get the same result when one is break line and the other is edit after the break point', () => {
const actionsA: TextXAction[] = [
{
t: TextXActionType.RETAIN,
len: 1,
segmentId: '',
}, {
t: TextXActionType.INSERT,
len: 1,
segmentId: '',
line: 0,
body: {
dataStream: '\r',
paragraphs: [{
startIndex: 0,
paragraphStyle: {
horizontalAlign: HorizontalAlign.LEFT,
},
}],
},
},
];

const actionsB: TextXAction[] = [
{
t: TextXActionType.RETAIN,
len: 2,
segmentId: '',
}, {
t: TextXActionType.INSERT,
len: 1,
segmentId: '',
line: 0,
body: {
dataStream: 'X',
textRuns: [{
st: 0,
ed: 1,
ts: {
bl: BooleanNumber.TRUE,
},
}],
},
},
];

const doc1 = getDefaultDocWithLength2();
const doc2 = getDefaultDocWithLength2();
const doc3 = getDefaultDocWithLength2();
const doc4 = getDefaultDocWithLength2();

const resultA = TextX.apply(TextX.apply(doc1, actionsA), TextX.transform(actionsB, actionsA, 'left'));
const resultB = TextX.apply(TextX.apply(doc2, actionsB), TextX.transform(actionsA, actionsB, 'right'));

const composedAction1 = TextX.compose(actionsA, TextX.transform(actionsB, actionsA, 'left'));
const composedAction2 = TextX.compose(actionsB, TextX.transform(actionsA, actionsB, 'right'));

const resultC = TextX.apply(doc3, composedAction1);
const resultD = TextX.apply(doc4, composedAction2);

// console.log(JSON.stringify(resultA, null, 2));
// console.log(JSON.stringify(resultB, null, 2));

Expand Down

0 comments on commit 98c0fff

Please sign in to comment.