Skip to content

Commit 9d03f01

Browse files
committed
test(track-changes): update upsertMarkSnapshotByType tests for merge semantics
Update existing test to reflect in-place merge behavior (attrs merged, position preserved) and add two new cases: disjoint attr accumulation across sequential changes, and append when no matching type exists.
1 parent 3ecb10f commit 9d03f01

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

packages/super-editor/src/editors/v1/extensions/track-changes/trackChangesHelpers/markSnapshotHelpers.test.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe('markSnapshotHelpers', () => {
7272
expect(hasMatchingMark(existing, schema.marks.italic.create())).toBe(false);
7373
});
7474

75-
it('upsertMarkSnapshotByType replaces same-type snapshot and preserves others', () => {
75+
it('upsertMarkSnapshotByType merges attrs for same-type snapshot in place', () => {
7676
const snapshots = [
7777
{ type: 'bold', attrs: {} },
7878
{ type: 'textStyle', attrs: { color: '#112233' } },
@@ -83,7 +83,29 @@ describe('markSnapshotHelpers', () => {
8383

8484
expect(updated).toEqual([
8585
{ type: 'bold', attrs: {} },
86+
{ type: 'textStyle', attrs: { color: '#FF0000' } },
8687
{ type: 'italic', attrs: {} },
88+
]);
89+
});
90+
91+
it('upsertMarkSnapshotByType merges disjoint attrs for same-type snapshot', () => {
92+
const snapshots = [{ type: 'textStyle', attrs: { color: '#112233' } }];
93+
94+
const after1 = upsertMarkSnapshotByType(snapshots, { type: 'textStyle', attrs: { fontFamily: 'Courier New' } });
95+
const after2 = upsertMarkSnapshotByType(after1, { type: 'textStyle', attrs: { fontSize: '18pt' } });
96+
97+
expect(after2).toEqual([
98+
{ type: 'textStyle', attrs: { color: '#112233', fontFamily: 'Courier New', fontSize: '18pt' } },
99+
]);
100+
});
101+
102+
it('upsertMarkSnapshotByType appends when no matching type exists', () => {
103+
const snapshots = [{ type: 'bold', attrs: {} }];
104+
105+
const updated = upsertMarkSnapshotByType(snapshots, { type: 'textStyle', attrs: { color: '#FF0000' } });
106+
107+
expect(updated).toEqual([
108+
{ type: 'bold', attrs: {} },
87109
{ type: 'textStyle', attrs: { color: '#FF0000' } },
88110
]);
89111
});

0 commit comments

Comments
 (0)