@@ -702,141 +702,142 @@ describe('query-history', () => {
702702 } ) ;
703703 } ) ;
704704
705- it ( 'should get children' , ( ) => {
706- const mockQuery = createMockLocalQuery ( ) ;
707- historyTreeDataProvider . allHistory . push ( mockQuery ) ;
708- expect ( historyTreeDataProvider . getChildren ( ) ) . to . deep . eq ( [ mockQuery ] ) ;
709- expect ( historyTreeDataProvider . getChildren ( mockQuery ) ) . to . deep . eq ( [ ] ) ;
710- } ) ;
711-
712705 describe ( 'getChildren' , ( ) => {
713- const history = [
714- item ( 'a' , 2 , 'remote' , 24 ) ,
715- item ( 'b' , 10 , 'local' , 20 ) ,
716- item ( 'c' , 5 , 'local' , 30 ) ,
717- item ( 'd' , 1 , 'local' , 25 ) ,
718- item ( 'e' , 6 , 'remote' , 5 ) ,
719- ] ;
720- let treeDataProvider : HistoryTreeDataProvider ;
721-
722- beforeEach ( async ( ) => {
723- queryHistoryManager = await createMockQueryHistory ( allHistory ) ;
724- ( queryHistoryManager . treeDataProvider as any ) . history = [ ...history ] ;
725- treeDataProvider = queryHistoryManager . treeDataProvider ;
726- } ) ;
706+ it ( 'fetch children correctly' , ( ) => {
707+ const mockQuery = createMockLocalQuery ( ) ;
708+ historyTreeDataProvider . allHistory . push ( mockQuery ) ;
709+ expect ( historyTreeDataProvider . getChildren ( ) ) . to . deep . eq ( [ mockQuery ] ) ;
710+ expect ( historyTreeDataProvider . getChildren ( mockQuery ) ) . to . deep . eq ( [ ] ) ;
711+ } ) ;
712+
713+ describe ( 'sorting' , ( ) => {
714+ const history = [
715+ item ( 'a' , 2 , 'remote' , 24 ) ,
716+ item ( 'b' , 10 , 'local' , 20 ) ,
717+ item ( 'c' , 5 , 'local' , 30 ) ,
718+ item ( 'd' , 1 , 'local' , 25 ) ,
719+ item ( 'e' , 6 , 'remote' , 5 ) ,
720+ ] ;
721+ let treeDataProvider : HistoryTreeDataProvider ;
722+
723+ beforeEach ( async ( ) => {
724+ queryHistoryManager = await createMockQueryHistory ( allHistory ) ;
725+ ( queryHistoryManager . treeDataProvider as any ) . history = [ ...history ] ;
726+ treeDataProvider = queryHistoryManager . treeDataProvider ;
727+ } ) ;
727728
728- it ( 'should get children for name ascending' , async ( ) => {
729- const expected = [ ...history ] ;
730- treeDataProvider . sortOrder = SortOrder . NameAsc ;
729+ it ( 'should get children for name ascending' , async ( ) => {
730+ const expected = [ ...history ] ;
731+ treeDataProvider . sortOrder = SortOrder . NameAsc ;
731732
732- const children = await treeDataProvider . getChildren ( ) ;
733- expect ( children ) . to . deep . eq ( expected ) ;
734- } ) ;
733+ const children = await treeDataProvider . getChildren ( ) ;
734+ expect ( children ) . to . deep . eq ( expected ) ;
735+ } ) ;
735736
736- it ( 'should get children for name descending' , async ( ) => {
737- const expected = [ ...history ] . reverse ( ) ;
738- treeDataProvider . sortOrder = SortOrder . NameDesc ;
737+ it ( 'should get children for name descending' , async ( ) => {
738+ const expected = [ ...history ] . reverse ( ) ;
739+ treeDataProvider . sortOrder = SortOrder . NameDesc ;
739740
740- const children = await treeDataProvider . getChildren ( ) ;
741- expect ( children ) . to . deep . eq ( expected ) ;
742- } ) ;
741+ const children = await treeDataProvider . getChildren ( ) ;
742+ expect ( children ) . to . deep . eq ( expected ) ;
743+ } ) ;
743744
744- it ( 'should get children for date ascending' , async ( ) => {
745- const expected = [ history [ 3 ] , history [ 0 ] , history [ 2 ] , history [ 4 ] , history [ 1 ] ] ;
746- treeDataProvider . sortOrder = SortOrder . DateAsc ;
745+ it ( 'should get children for date ascending' , async ( ) => {
746+ const expected = [ history [ 3 ] , history [ 0 ] , history [ 2 ] , history [ 4 ] , history [ 1 ] ] ;
747+ treeDataProvider . sortOrder = SortOrder . DateAsc ;
747748
748- const children = await treeDataProvider . getChildren ( ) ;
749- expect ( children ) . to . deep . eq ( expected ) ;
750- } ) ;
749+ const children = await treeDataProvider . getChildren ( ) ;
750+ expect ( children ) . to . deep . eq ( expected ) ;
751+ } ) ;
751752
752- it ( 'should get children for date descending' , async ( ) => {
753- const expected = [ history [ 3 ] , history [ 0 ] , history [ 2 ] , history [ 4 ] , history [ 1 ] ] . reverse ( ) ;
754- treeDataProvider . sortOrder = SortOrder . DateDesc ;
753+ it ( 'should get children for date descending' , async ( ) => {
754+ const expected = [ history [ 3 ] , history [ 0 ] , history [ 2 ] , history [ 4 ] , history [ 1 ] ] . reverse ( ) ;
755+ treeDataProvider . sortOrder = SortOrder . DateDesc ;
755756
756- const children = await treeDataProvider . getChildren ( ) ;
757- expect ( children ) . to . deep . eq ( expected ) ;
758- } ) ;
757+ const children = await treeDataProvider . getChildren ( ) ;
758+ expect ( children ) . to . deep . eq ( expected ) ;
759+ } ) ;
759760
760- it ( 'should get children for result count ascending' , async ( ) => {
761- const expected = [ history [ 4 ] , history [ 1 ] , history [ 0 ] , history [ 3 ] , history [ 2 ] ] ;
762- treeDataProvider . sortOrder = SortOrder . CountAsc ;
761+ it ( 'should get children for result count ascending' , async ( ) => {
762+ const expected = [ history [ 4 ] , history [ 1 ] , history [ 0 ] , history [ 3 ] , history [ 2 ] ] ;
763+ treeDataProvider . sortOrder = SortOrder . CountAsc ;
763764
764- const children = await treeDataProvider . getChildren ( ) ;
765- expect ( children ) . to . deep . eq ( expected ) ;
766- } ) ;
765+ const children = await treeDataProvider . getChildren ( ) ;
766+ expect ( children ) . to . deep . eq ( expected ) ;
767+ } ) ;
767768
768- it ( 'should get children for result count descending' , async ( ) => {
769- const expected = [ history [ 4 ] , history [ 1 ] , history [ 0 ] , history [ 3 ] , history [ 2 ] ] . reverse ( ) ;
770- treeDataProvider . sortOrder = SortOrder . CountDesc ;
769+ it ( 'should get children for result count descending' , async ( ) => {
770+ const expected = [ history [ 4 ] , history [ 1 ] , history [ 0 ] , history [ 3 ] , history [ 2 ] ] . reverse ( ) ;
771+ treeDataProvider . sortOrder = SortOrder . CountDesc ;
771772
772- const children = await treeDataProvider . getChildren ( ) ;
773- expect ( children ) . to . deep . eq ( expected ) ;
774- } ) ;
773+ const children = await treeDataProvider . getChildren ( ) ;
774+ expect ( children ) . to . deep . eq ( expected ) ;
775+ } ) ;
775776
776- it ( 'should get children for result count ascending when there are no results' , async ( ) => {
777- // fall back to name
778- const thisHistory = [ item ( 'a' , 10 ) , item ( 'b' , 50 ) , item ( 'c' , 1 ) ] ;
779- ( queryHistoryManager ! . treeDataProvider as any ) . history = [ ...thisHistory ] ;
780- const expected = [ ...thisHistory ] ;
781- treeDataProvider . sortOrder = SortOrder . CountAsc ;
777+ it ( 'should get children for result count ascending when there are no results' , async ( ) => {
778+ // fall back to name
779+ const thisHistory = [ item ( 'a' , 10 ) , item ( 'b' , 50 ) , item ( 'c' , 1 ) ] ;
780+ ( queryHistoryManager ! . treeDataProvider as any ) . history = [ ...thisHistory ] ;
781+ const expected = [ ...thisHistory ] ;
782+ treeDataProvider . sortOrder = SortOrder . CountAsc ;
782783
783- const children = await treeDataProvider . getChildren ( ) ;
784- expect ( children ) . to . deep . eq ( expected ) ;
785- } ) ;
784+ const children = await treeDataProvider . getChildren ( ) ;
785+ expect ( children ) . to . deep . eq ( expected ) ;
786+ } ) ;
786787
787- it ( 'should get children for result count descending when there are no results' , async ( ) => {
788- // fall back to name
789- const thisHistory = [ item ( 'a' , 10 ) , item ( 'b' , 50 ) , item ( 'c' , 1 ) ] ;
790- ( queryHistoryManager ! . treeDataProvider as any ) . history = [ ...thisHistory ] ;
791- const expected = [ ...thisHistory ] . reverse ( ) ;
792- treeDataProvider . sortOrder = SortOrder . CountDesc ;
788+ it ( 'should get children for result count descending when there are no results' , async ( ) => {
789+ // fall back to name
790+ const thisHistory = [ item ( 'a' , 10 ) , item ( 'b' , 50 ) , item ( 'c' , 1 ) ] ;
791+ ( queryHistoryManager ! . treeDataProvider as any ) . history = [ ...thisHistory ] ;
792+ const expected = [ ...thisHistory ] . reverse ( ) ;
793+ treeDataProvider . sortOrder = SortOrder . CountDesc ;
793794
794- const children = await treeDataProvider . getChildren ( ) ;
795- expect ( children ) . to . deep . eq ( expected ) ;
796- } ) ;
795+ const children = await treeDataProvider . getChildren ( ) ;
796+ expect ( children ) . to . deep . eq ( expected ) ;
797+ } ) ;
797798
798- function item ( label : string , start : number , t = 'local' , resultCount ?: number ) {
799- if ( t === 'local' ) {
800- return {
801- getQueryName ( ) {
802- return label ;
803- } ,
804- getQueryFileName ( ) {
805- return label + '.ql' ;
806- } ,
807- initialInfo : {
808- start : new Date ( start ) ,
809- databaseInfo : {
810- name : 'test' ,
811- }
812- } ,
813- completedQuery : {
814- resultCount,
815- } ,
816- t
817- } ;
818- } else {
819- return {
820- status : 'success' ,
821- remoteQuery : {
822- queryFilePath : label + '.ql' ,
823- queryName : label ,
824- executionStartTime : start ,
825- controllerRepository : {
826- name : 'test' ,
827- owner : 'user' ,
799+ function item ( label : string , start : number , t = 'local' , resultCount ?: number ) {
800+ if ( t === 'local' ) {
801+ return {
802+ getQueryName ( ) {
803+ return label ;
828804 } ,
829- repositories : [ ]
830- } ,
831- resultCount,
832- t
833- } ;
805+ getQueryFileName ( ) {
806+ return label + '.ql' ;
807+ } ,
808+ initialInfo : {
809+ start : new Date ( start ) ,
810+ databaseInfo : {
811+ name : 'test' ,
812+ }
813+ } ,
814+ completedQuery : {
815+ resultCount,
816+ } ,
817+ t
818+ } ;
819+ } else {
820+ return {
821+ status : 'success' ,
822+ remoteQuery : {
823+ queryFilePath : label + '.ql' ,
824+ queryName : label ,
825+ executionStartTime : start ,
826+ controllerRepository : {
827+ name : 'test' ,
828+ owner : 'user' ,
829+ } ,
830+ repositories : [ ]
831+ } ,
832+ resultCount,
833+ t
834+ } ;
835+ }
834836 }
835- }
837+ } ) ;
836838 } ) ;
837839 } ) ;
838840
839-
840841 async function createMockQueryHistory ( allHistory : QueryHistoryInfo [ ] ) {
841842 const qhm = new QueryHistoryManager (
842843 { } as QueryRunner ,
0 commit comments