Skip to content

Commit

Permalink
Test editable
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Wei committed Nov 25, 2024
1 parent 33c75f4 commit 1d2fca9
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions packages/@ot-doc/model/src/behaviors/editable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,59 @@ describe('Editable behavior', () => {
).toEqual(nothing());
});

it('should edit the dict correctly', () => {
const dict = $dict($number);
expect(
dict.update(() => ({
Foo: { o: 0, n: 1, t: 0 },
}))({}).value
).toEqual(just({ Foo: 1 }));

expect(
dict.update(() => ({
Foo: { o: 1, n: 0, t: 0 },
}))({ Foo: 1 }).value
).toEqual(just({}));
});

it('should reject if the action conflicts with the current dict', () => {
const dict = $dict($number);
expect(
dict.update(() => ({
Foo: { o: 1, n: 0, t: 0 },
Bar: { o: 0, n: 1, t: 0 },
}))({}).value
).toEqual(nothing());
});

it('should edit the struct correctly', () => {
const stt = $struct({
Foo: $number,
Bar: $string,
});
expect(
stt.update(() => ({
Foo: { o: 1, n: 0, t: 0 },
}))({
Foo: 1,
Bar: 'Hello',
}).value
).toEqual(just({ Foo: 0, Bar: 'Hello' }));
});

it('should reject if the action conflicts with the curretn struct', () => {
const stt = $struct({
Foo: $number,
Bar: $string,
});
expect(
stt.update(() => ({
Foo: { o: 1, n: 0, t: 0 },
Bar: { o: '', n: 'World', t: 0 },
}))({
Foo: 1,
Bar: 'Hello',
}).value
).toEqual(nothing());
});
});

0 comments on commit 1d2fca9

Please sign in to comment.