1
+ import { s } from '../../../json-crdt-patch' ;
1
2
import { Model } from '../../model' ;
2
3
import { Log } from '../Log' ;
3
4
@@ -8,6 +9,34 @@ const setup = (view: unknown) => {
8
9
return { log} ;
9
10
} ;
10
11
12
+ test ( 'can create a new log from a new model with right starting logical clock' , ( ) => {
13
+ const schema0 = s . obj ( {
14
+ id : s . con < string > ( '' ) ,
15
+ name : s . str ( 'John Doe' ) ,
16
+ age : s . val ( s . con < number > ( 42 ) ) ,
17
+ tags : s . arr ( [ s . str ( 'tag1' ) , s . str ( 'tag2' ) ] ) ,
18
+ } ) ;
19
+ const model = Model . create ( schema0 ) ;
20
+ const sid = model . clock . sid ;
21
+ const log = Log . fromNewModel ( model ) ;
22
+ log . end . s . toApi ( ) . set ( { id : s . con ( 'xyz' ) as any } ) ;
23
+ log . end . api . flush ( ) ;
24
+ log . end . s . age . toApi ( ) . set ( 35 ) ;
25
+ log . end . api . flush ( ) ;
26
+ log . end . s . tags . toApi ( ) . del ( 0 , 1 ) ;
27
+ log . end . api . flush ( ) ;
28
+ log . end . s . name . toApi ( ) . del ( 0 , 8 ) ;
29
+ log . end . s . name . toApi ( ) . ins ( 0 , 'Va Da' ) ;
30
+ log . end . api . flush ( ) ;
31
+ log . end . s . tags [ 0 ] . toApi ( ) . del ( 0 , 4 ) ;
32
+ log . end . s . tags [ 0 ] . toApi ( ) . ins ( 0 , 'happy' ) ;
33
+ log . end . api . flush ( ) ;
34
+ expect ( log . start ( ) . clock . sid ) . toBe ( sid ) ;
35
+ expect ( log . start ( ) . clock . time ) . toBe ( 1 ) ;
36
+ expect ( log . end . clock . sid ) . toBe ( sid ) ;
37
+ expect ( log . end . clock . time > 10 ) . toBe ( true ) ;
38
+ } ) ;
39
+
11
40
test ( 'can replay to specific patch' , ( ) => {
12
41
const { log} = setup ( { foo : 'bar' } ) ;
13
42
const model = log . end . clone ( ) ;
0 commit comments