1- import { devide2Buckets } from "@src/background/backup/gist/compressor"
1+ import { devide2Buckets , gistData2Rows } from "@src/background/backup/gist/compressor"
22
33test ( 'devide 1' , ( ) => {
44 const rows : timer . stat . Row [ ] = [ {
@@ -8,6 +8,14 @@ test('devide 1', () => {
88 time : 10 ,
99 total : 1000 ,
1010 mergedHosts : [ ]
11+ } , {
12+ host : 'www.baidu.com' ,
13+ // Invalid date, count be compress
14+ date : '' ,
15+ focus : 0 ,
16+ time : 10 ,
17+ total : 1000 ,
18+ mergedHosts : [ ]
1119 } ]
1220 const devided = devide2Buckets ( rows )
1321 expect ( devided . length ) . toEqual ( 1 )
@@ -19,3 +27,28 @@ test('devide 1', () => {
1927 }
2028 } )
2129} )
30+
31+ test ( 'gistData2Rows' , ( ) => {
32+ const gistData : GistData = {
33+ '01' : {
34+ 'baidu.com' : [ 0 , 1 , 2 ]
35+ } ,
36+ '08' : {
37+ 'google.com' : [ 1 , 1 , 1 , ]
38+ }
39+ }
40+ const rows = gistData2Rows ( '202209' , gistData )
41+ expect ( rows . length ) . toEqual ( 2 )
42+ rows . sort ( ( a , b ) => a . date > b . date ? 1 : - 1 )
43+ const row0 = rows [ 0 ]
44+ const row1 = rows [ 1 ]
45+ expect ( row0 . date ) . toEqual ( '20220901' )
46+ expect ( row0 . time ) . toEqual ( 0 )
47+ expect ( row0 . focus ) . toEqual ( 1 )
48+ expect ( row0 . total ) . toEqual ( 2 )
49+
50+ expect ( row1 . date ) . toEqual ( '20220908' )
51+ expect ( row1 . time ) . toEqual ( 1 )
52+ expect ( row1 . focus ) . toEqual ( 1 )
53+ expect ( row1 . total ) . toEqual ( 1 )
54+ } )
0 commit comments