11import * as fs from 'fs-extra' ;
22import * as path from 'path' ;
3- import { expect , assert } from 'chai' ;
3+ import { assert , expect } from 'chai' ;
44import * as vscode from 'vscode' ;
55import * as sinon from 'sinon' ;
66
77import { logger } from '../../logging' ;
88import { registerQueryHistoryScrubber } from '../../query-history-scrubber' ;
9- import { QueryHistoryManager , HistoryTreeDataProvider , SortOrder } from '../../query-history' ;
9+ import { HistoryTreeDataProvider , QueryHistoryManager , SortOrder } from '../../query-history' ;
1010import { QueryHistoryConfig , QueryHistoryConfigListener } from '../../config' ;
1111import { LocalQueryInfo } from '../../query-results' ;
1212import { DatabaseManager } from '../../databases' ;
1313import * as tmp from 'tmp-promise' ;
14- import { ONE_DAY_IN_MS , ONE_HOUR_IN_MS , TWO_HOURS_IN_MS , THREE_HOURS_IN_MS } from '../../pure/time' ;
14+ import { ONE_DAY_IN_MS , ONE_HOUR_IN_MS , THREE_HOURS_IN_MS , TWO_HOURS_IN_MS } from '../../pure/time' ;
1515import { tmpDir } from '../../helpers' ;
1616import { getErrorMessage } from '../../pure/helpers-pure' ;
1717import { HistoryItemLabelProvider } from '../../history-item-label-provider' ;
@@ -27,6 +27,7 @@ import { RemoteQueryHistoryItem } from '../../remote-queries/remote-query-histor
2727import { shuffleHistoryItems } from '../utils/query-history-helpers' ;
2828import { createMockVariantAnalysisHistoryItem } from '../factories/remote-queries/variant-analysis-history-item' ;
2929import { VariantAnalysisHistoryItem } from '../../remote-queries/variant-analysis-history-item' ;
30+ import { QueryStatus } from '../../query-status' ;
3031
3132describe ( 'query-history' , ( ) => {
3233 const mockExtensionLocation = path . join ( tmpDir . name , 'mock-extension-location' ) ;
@@ -93,16 +94,16 @@ describe('query-history', () => {
9394 createMockLocalQuery ( 'a' , createMockQueryWithResults ( sandbox , true ) ) ,
9495 ] ;
9596 remoteQueryHistory = [
96- createMockRemoteQueryHistoryItem ( { } ) ,
97- createMockRemoteQueryHistoryItem ( { } ) ,
98- createMockRemoteQueryHistoryItem ( { } ) ,
99- createMockRemoteQueryHistoryItem ( { } )
97+ createMockRemoteQueryHistoryItem ( { status : QueryStatus . Completed } ) ,
98+ createMockRemoteQueryHistoryItem ( { status : QueryStatus . Failed } ) ,
99+ createMockRemoteQueryHistoryItem ( { status : QueryStatus . InProgress } ) ,
100+ createMockRemoteQueryHistoryItem ( { status : QueryStatus . InProgress } )
100101 ] ;
101102 variantAnalysisHistory = [
102- createMockVariantAnalysisHistoryItem ( ) ,
103- createMockVariantAnalysisHistoryItem ( ) ,
104- createMockVariantAnalysisHistoryItem ( ) ,
105- createMockVariantAnalysisHistoryItem ( )
103+ createMockVariantAnalysisHistoryItem ( QueryStatus . Completed ) ,
104+ createMockVariantAnalysisHistoryItem ( QueryStatus . InProgress ) ,
105+ createMockVariantAnalysisHistoryItem ( QueryStatus . Failed ) ,
106+ createMockVariantAnalysisHistoryItem ( QueryStatus . InProgress )
106107 ] ;
107108 allHistory = shuffleHistoryItems ( [ ...localQueryHistory , ...remoteQueryHistory , ...variantAnalysisHistory ] ) ;
108109
@@ -158,45 +159,105 @@ describe('query-history', () => {
158159 } ) ;
159160 } ) ;
160161
161- describe ( 'handleItemClicked' , ( ) => {
162- it ( 'should call the selectedCallback when an item is clicked' , async ( ) => {
163- queryHistoryManager = await createMockQueryHistory ( allHistory ) ;
164- const itemClicked = allHistory [ 0 ] ;
165- await queryHistoryManager . handleItemClicked ( itemClicked , [ itemClicked ] ) ;
166-
167- if ( itemClicked . t == 'local' ) {
168- expect ( localQueriesResultsViewStub . showResults ) . to . have . been . calledOnceWith ( itemClicked ) ;
169- } else if ( itemClicked . t == 'remote' ) {
170- expect ( remoteQueriesManagerStub . openRemoteQueryResults ) . to . have . been . calledOnceWith ( itemClicked . queryId ) ;
171- } else if ( itemClicked . t == 'variant-analysis' ) {
172- expect ( variantAnalysisManagerStub . showView ) . to . have . been . calledOnceWith ( itemClicked . variantAnalysis . id ) ;
173- }
162+ describe ( 'handleItemClicked' , async ( ) => {
163+ describe ( 'single click' , async ( ) => {
164+ describe ( 'local query' , async ( ) => {
165+ describe ( 'when complete' , async ( ) => {
166+ it ( 'should show results' , async ( ) => {
167+ queryHistoryManager = await createMockQueryHistory ( allHistory ) ;
168+ const itemClicked = localQueryHistory [ 0 ] ;
169+ await queryHistoryManager . handleItemClicked ( itemClicked , [ itemClicked ] ) ;
170+
171+ expect ( localQueriesResultsViewStub . showResults ) . to . have . been . calledOnceWith ( itemClicked ) ;
172+ expect ( queryHistoryManager . treeDataProvider . getCurrent ( ) ) . to . eq ( itemClicked ) ;
173+ } ) ;
174+ } ) ;
175+
176+ describe ( 'when incomplete' , async ( ) => {
177+ it ( 'should do nothing' , async ( ) => {
178+ queryHistoryManager = await createMockQueryHistory ( allHistory ) ;
179+ const itemClicked = localQueryHistory [ 2 ] ;
180+ await queryHistoryManager . handleItemClicked ( itemClicked , [ itemClicked ] ) ;
181+
182+ expect ( localQueriesResultsViewStub . showResults ) . not . to . have . been . calledWith ( itemClicked ) ;
183+ } ) ;
184+ } ) ;
185+ } ) ;
186+
187+ describe ( 'remote query' , async ( ) => {
188+ describe ( 'when complete' , async ( ) => {
189+ it ( 'should show results' , async ( ) => {
190+ queryHistoryManager = await createMockQueryHistory ( allHistory ) ;
191+ const itemClicked = remoteQueryHistory [ 0 ] ;
192+ await queryHistoryManager . handleItemClicked ( itemClicked , [ itemClicked ] ) ;
193+
194+ expect ( remoteQueriesManagerStub . openRemoteQueryResults ) . to . have . been . calledOnceWith ( itemClicked . queryId ) ;
195+ expect ( queryHistoryManager . treeDataProvider . getCurrent ( ) ) . to . eq ( itemClicked ) ;
196+ } ) ;
197+ } ) ;
198+
199+ describe ( 'when incomplete' , async ( ) => {
200+ it ( 'should do nothing' , async ( ) => {
201+ queryHistoryManager = await createMockQueryHistory ( allHistory ) ;
202+ const itemClicked = remoteQueryHistory [ 2 ] ;
203+ await queryHistoryManager . handleItemClicked ( itemClicked , [ itemClicked ] ) ;
204+
205+ expect ( remoteQueriesManagerStub . openRemoteQueryResults ) . not . to . have . been . calledWith ( itemClicked . queryId ) ;
206+ } ) ;
207+ } ) ;
208+ } ) ;
209+
210+ describe ( 'variant analysis' , async ( ) => {
211+ describe ( 'when complete' , async ( ) => {
212+ it ( 'should show results' , async ( ) => {
213+ queryHistoryManager = await createMockQueryHistory ( allHistory ) ;
214+ const itemClicked = variantAnalysisHistory [ 0 ] ;
215+ await queryHistoryManager . handleItemClicked ( itemClicked , [ itemClicked ] ) ;
216+
217+ expect ( variantAnalysisManagerStub . showView ) . to . have . been . calledOnceWith ( itemClicked . variantAnalysis . id ) ;
218+ expect ( queryHistoryManager . treeDataProvider . getCurrent ( ) ) . to . eq ( itemClicked ) ;
219+ } ) ;
220+ } ) ;
174221
175- expect ( queryHistoryManager . treeDataProvider . getCurrent ( ) ) . to . eq ( itemClicked ) ;
222+ describe ( 'when incomplete' , async ( ) => {
223+ it ( 'should show results' , async ( ) => {
224+ queryHistoryManager = await createMockQueryHistory ( allHistory ) ;
225+ const itemClicked = variantAnalysisHistory [ 1 ] ;
226+ await queryHistoryManager . handleItemClicked ( itemClicked , [ itemClicked ] ) ;
227+
228+ expect ( variantAnalysisManagerStub . showView ) . to . have . been . calledOnceWith ( itemClicked . variantAnalysis . id ) ;
229+ expect ( queryHistoryManager . treeDataProvider . getCurrent ( ) ) . to . eq ( itemClicked ) ;
230+ } ) ;
231+ } ) ;
232+ } ) ;
176233 } ) ;
177234
178- it ( 'should do nothing if there is a multi-selection' , async ( ) => {
179- queryHistoryManager = await createMockQueryHistory ( allHistory ) ;
180- const itemClicked = allHistory [ 0 ] ;
181- const secondItemClicked = allHistory [ 1 ] ;
235+ describe ( 'double click' , ( ) => {
236+ it ( 'should do nothing' , async ( ) => {
237+ queryHistoryManager = await createMockQueryHistory ( allHistory ) ;
238+ const itemClicked = allHistory [ 0 ] ;
239+ const secondItemClicked = allHistory [ 1 ] ;
182240
183- await queryHistoryManager . handleItemClicked ( itemClicked , [ itemClicked , secondItemClicked ] ) ;
241+ await queryHistoryManager . handleItemClicked ( itemClicked , [ itemClicked , secondItemClicked ] ) ;
184242
185- expect ( localQueriesResultsViewStub . showResults ) . not . to . have . been . called ;
186- expect ( remoteQueriesManagerStub . openRemoteQueryResults ) . not . to . have . been . called ;
187- expect ( variantAnalysisManagerStub . showView ) . not . to . have . been . called ;
188- expect ( queryHistoryManager . treeDataProvider . getCurrent ( ) ) . to . be . undefined ;
243+ expect ( localQueriesResultsViewStub . showResults ) . not . to . have . been . called ;
244+ expect ( remoteQueriesManagerStub . openRemoteQueryResults ) . not . to . have . been . called ;
245+ expect ( variantAnalysisManagerStub . showView ) . not . to . have . been . called ;
246+ expect ( queryHistoryManager . treeDataProvider . getCurrent ( ) ) . to . be . undefined ;
247+ } ) ;
189248 } ) ;
190249
191- it ( 'should do nothing if there is no selection' , async ( ) => {
192- queryHistoryManager = await createMockQueryHistory ( allHistory ) ;
250+ describe ( 'no selection' , ( ) => {
251+ it ( 'should do nothing' , async ( ) => {
252+ queryHistoryManager = await createMockQueryHistory ( allHistory ) ;
193253
194- await queryHistoryManager . handleItemClicked ( undefined ! , [ ] ) ;
254+ await queryHistoryManager . handleItemClicked ( undefined ! , [ ] ) ;
195255
196- expect ( localQueriesResultsViewStub . showResults ) . not . to . have . been . called ;
197- expect ( remoteQueriesManagerStub . openRemoteQueryResults ) . not . to . have . been . called ;
198- expect ( variantAnalysisManagerStub . showView ) . not . to . have . been . called ;
199- expect ( queryHistoryManager . treeDataProvider . getCurrent ( ) ) . to . be . undefined ;
256+ expect ( localQueriesResultsViewStub . showResults ) . not . to . have . been . called ;
257+ expect ( remoteQueriesManagerStub . openRemoteQueryResults ) . not . to . have . been . called ;
258+ expect ( variantAnalysisManagerStub . showView ) . not . to . have . been . called ;
259+ expect ( queryHistoryManager . treeDataProvider . getCurrent ( ) ) . to . be . undefined ;
260+ } ) ;
200261 } ) ;
201262 } ) ;
202263
0 commit comments