@@ -119,3 +119,28 @@ describe('.unserialize()', () => {
119119 expect ( file2 . model . view ( ) ) . toEqual ( { foo : 'bar' , xyz : 123 } ) ;
120120 } ) ;
121121} ) ;
122+
123+ describe ( '.sync()' , ( ) => {
124+ test ( 'keeps track of local changes' , async ( ) => {
125+ const { file, model} = setup ( { foo : 'bar' } ) ;
126+ file . sync ( ) ;
127+ model . api . obj ( [ ] ) . set ( { x : 1 } ) ;
128+ await Promise . resolve ( ) ;
129+ expect ( file . model . view ( ) ) . toEqual ( { foo : 'bar' , x : 1 } ) ;
130+ expect ( file . log . replayToEnd ( ) . view ( ) ) . toEqual ( { foo : 'bar' , x : 1 } ) ;
131+ } ) ;
132+
133+ test ( 'keeps track of remote changes' , async ( ) => {
134+ const { file, model} = setup ( { foo : 'bar' } ) ;
135+ const clone = model . clone ( ) ;
136+ file . sync ( ) ;
137+ clone . api . obj ( [ ] ) . set ( { x : 1 } ) ;
138+ expect ( clone . view ( ) ) . toEqual ( { foo : 'bar' , x : 1 } ) ;
139+ expect ( file . model . view ( ) ) . toEqual ( { foo : 'bar' } ) ;
140+ const patch = clone . api . flush ( ) ;
141+ file . model . applyPatch ( patch ) ;
142+ await Promise . resolve ( ) ;
143+ expect ( file . model . view ( ) ) . toEqual ( { foo : 'bar' , x : 1 } ) ;
144+ expect ( file . log . replayToEnd ( ) . view ( ) ) . toEqual ( { foo : 'bar' , x : 1 } ) ;
145+ } ) ;
146+ } ) ;
0 commit comments