From 1d2fca99b60c19a1824a48f48337eb3661097e8e Mon Sep 17 00:00:00 2001 From: Scott Wei Date: Mon, 25 Nov 2024 10:58:43 +0800 Subject: [PATCH] Test editable --- .../model/src/behaviors/editable.spec.ts | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/packages/@ot-doc/model/src/behaviors/editable.spec.ts b/packages/@ot-doc/model/src/behaviors/editable.spec.ts index 5869a5a..9e1d239 100644 --- a/packages/@ot-doc/model/src/behaviors/editable.spec.ts +++ b/packages/@ot-doc/model/src/behaviors/editable.spec.ts @@ -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()); + }); });