1+ window . require = ( ( str : string ) => str ) as any
12import * as queries from '../../../frontend/lib/queries' ;
2- import type { QueryData } from '../../../frontend/types' ;
3+ import type { QueryData , ExplainJson } from '../../../frontend/types' ;
34
45const first : Partial < QueryData > = {
56 label : 'firstQuery' ,
67 db : 'firstDb' ,
8+ group : 'group1' ,
79 sqlString : 'select * from tests' ,
10+ executionPlan : {
11+ Plan : {
12+ 'Node Type' : 'Seq Scan' ,
13+ 'Relation Name' : 'users' ,
14+ Alias : 'users' ,
15+ 'Startup Cost' : 0 ,
16+ 'Total Cost' : 0 ,
17+ 'Plan Rows' : 0 ,
18+ 'Plan Width' : 0 ,
19+ 'Actual Startup Time' : 0 ,
20+ 'Actual Total Time' : 0 ,
21+ 'Actual Rows' : 0 ,
22+ 'Actual Loops' : 0 ,
23+ } ,
24+ 'Planning Time' : 1 ,
25+ 'Execution Time' : 1 ,
26+ } ,
827} ;
928
1029const second : Partial < QueryData > = {
@@ -15,15 +34,16 @@ const second: Partial<QueryData> = {
1534
1635describe ( 'key generation' , ( ) => {
1736 it ( 'should create key from label and db given as params' , ( ) => {
18- expect ( queries . keyFromData ( 'LABEL' , 'DB' ) ) . toEqual ( 'label:LABEL db:DB' ) ;
37+ expect ( queries . keyFromData ( 'LABEL' , 'DB' , 'GROUP' ) ) . toEqual ( 'label:LABEL db:DB group:GROUP ' ) ;
1938 } ) ;
2039
2140 it ( 'should create key from query object' , ( ) => {
2241 const query = {
2342 label : 'query1' ,
2443 db : 'db1' ,
44+ group : 'group1'
2545 } ;
26- expect ( queries . key ( query as QueryData ) ) . toEqual ( 'label:query1 db:db1' ) ;
46+ expect ( queries . key ( query as QueryData ) ) . toEqual ( 'label:query1 db:db1 group:group1 ' ) ;
2747 } ) ;
2848} ) ;
2949
@@ -137,23 +157,28 @@ describe('setCompare', () => {
137157
138158 it ( 'should not mutate original collection' , ( ) => {
139159 expect ( Object . keys ( collection ) . length ) . toBe ( 0 ) ;
140- const newCollection = queries . setCompare ( { } , first as QueryData , true ) ;
160+ const newCollection = queries . setCompare ( { } , { } , first as QueryData , true ) ;
141161 expect ( Object . keys ( collection ) . length ) . toBe ( 0 ) ;
142162 expect ( newCollection ) . not . toBe ( collection ) ;
143163 } ) ;
144164
145165 it ( 'should add query to new collection if given true for isCompared' , ( ) => {
146166 expect ( Object . keys ( collection ) . length ) . toBe ( 0 ) ;
147- const newCollection = queries . setCompare ( { } , first as QueryData , true ) ;
167+ const newCollection = queries . setCompare ( { } , { } , first as QueryData , true ) ;
148168 expect ( Object . keys ( newCollection ) . length ) . toBe ( 1 ) ;
149169 expect ( newCollection [ queries . key ( first as QueryData ) ] ) . toEqual ( first ) ;
150170 } ) ;
151171
152- it ( 'should remove query from new collection if given false for isCompared' , ( ) => {
172+ it ( 'should set execution time to 0 if given false for isCompared' , ( ) => {
173+ let qs :any = { [ `${ queries . key ( first as QueryData ) } ` ] : first } ;
153174 expect ( Object . keys ( collection ) . length ) . toBe ( 0 ) ;
154- const newCollection = queries . setCompare ( { } , first as QueryData , true ) ;
175+ const newCollection = queries . setCompare ( { } , qs , first as QueryData , true ) ;
155176 expect ( Object . keys ( newCollection ) . length ) . toBe ( 1 ) ;
156- const clearedCollection = queries . setCompare ( { } , first as QueryData , false ) ;
157- expect ( Object . keys ( clearedCollection ) . length ) . toBe ( 0 ) ;
177+ expect ( newCollection [ queries . key ( first as QueryData ) ] . executionPlan [ 'Planning Time' ] ) . toBe ( 1 ) ;
178+ expect ( newCollection [ queries . key ( first as QueryData ) ] . executionPlan [ 'Execution Time' ] ) . toBe ( 1 ) ;
179+ const newSetCollection = queries . setCompare ( newCollection , qs , first as QueryData , false ) ;
180+ expect ( Object . keys ( newSetCollection ) . length ) . toBe ( 1 ) ;
181+ expect ( newSetCollection [ queries . key ( first as QueryData ) ] . executionPlan [ 'Planning Time' ] ) . toBe ( 0 ) ;
182+ expect ( newSetCollection [ queries . key ( first as QueryData ) ] . executionPlan [ 'Execution Time' ] ) . toBe ( 0 ) ;
158183 } ) ;
159184} ) ;
0 commit comments