@@ -28,13 +28,15 @@ import {
28
28
NO_COMPATIBLE_DATASOURCES_MESSAGE ,
29
29
NO_DATASOURCES_CONNECTED_MESSAGE ,
30
30
} from '../constants' ;
31
+ import { DataSourceSelectionService } from '../../service/data_source_selection_service' ;
31
32
32
33
describe ( 'DataSourceAggregatedView: read all view (displayAllCompatibleDataSources is set to true)' , ( ) => {
33
34
let component : ShallowWrapper < any , Readonly < { } > , React . Component < { } , { } , any > > ;
34
35
let client : SavedObjectsClientContract ;
35
36
const { toasts } = notificationServiceMock . createStartContract ( ) ;
36
37
const uiSettings = uiSettingsServiceMock . createStartContract ( ) ;
37
38
const application = applicationServiceMock . createStartContract ( ) ;
39
+ const dataSourceSelection = new DataSourceSelectionService ( ) ;
38
40
const nextTick = ( ) => new Promise ( ( res ) => process . nextTick ( res ) ) ;
39
41
40
42
beforeEach ( ( ) => {
@@ -44,6 +46,7 @@ describe('DataSourceAggregatedView: read all view (displayAllCompatibleDataSourc
44
46
mockResponseForSavedObjectsCalls ( client , 'find' , getDataSourcesWithFieldsResponse ) ;
45
47
mockUiSettingsCalls ( uiSettings , 'get' , 'test1' ) ;
46
48
jest . spyOn ( utils , 'getApplication' ) . mockReturnValue ( application ) ;
49
+ jest . spyOn ( utils , 'getDataSourceSelection' ) . mockReturnValue ( dataSourceSelection ) ;
47
50
} ) ;
48
51
49
52
it . each ( [
@@ -163,6 +166,7 @@ describe('DataSourceAggregatedView: read active view (displayAllCompatibleDataSo
163
166
let client : SavedObjectsClientContract ;
164
167
const { toasts } = notificationServiceMock . createStartContract ( ) ;
165
168
const uiSettings = uiSettingsServiceMock . createStartContract ( ) ;
169
+ const dataSourceSelection = new DataSourceSelectionService ( ) ;
166
170
const nextTick = ( ) => new Promise ( ( res ) => process . nextTick ( res ) ) ;
167
171
168
172
beforeEach ( ( ) => {
@@ -171,6 +175,7 @@ describe('DataSourceAggregatedView: read active view (displayAllCompatibleDataSo
171
175
} as any ;
172
176
mockResponseForSavedObjectsCalls ( client , 'find' , getDataSourcesWithFieldsResponse ) ;
173
177
mockUiSettingsCalls ( uiSettings , 'get' , 'test1' ) ;
178
+ jest . spyOn ( utils , 'getDataSourceSelection' ) . mockReturnValue ( dataSourceSelection ) ;
174
179
} ) ;
175
180
176
181
it . each ( [
@@ -284,6 +289,7 @@ describe('DataSourceAggregatedView empty state test with local cluster hiding',
284
289
const { toasts } = notificationServiceMock . createStartContract ( ) ;
285
290
const uiSettings = uiSettingsServiceMock . createStartContract ( ) ;
286
291
const application = applicationServiceMock . createStartContract ( ) ;
292
+ const dataSourceSelection = new DataSourceSelectionService ( ) ;
287
293
const nextTick = ( ) => new Promise ( ( res ) => process . nextTick ( res ) ) ;
288
294
289
295
beforeEach ( ( ) => {
@@ -293,6 +299,7 @@ describe('DataSourceAggregatedView empty state test with local cluster hiding',
293
299
mockResponseForSavedObjectsCalls ( client , 'find' , { } ) ;
294
300
mockUiSettingsCalls ( uiSettings , 'get' , 'test1' ) ;
295
301
jest . spyOn ( utils , 'getApplication' ) . mockReturnValue ( application ) ;
302
+ jest . spyOn ( utils , 'getDataSourceSelection' ) . mockReturnValue ( dataSourceSelection ) ;
296
303
} ) ;
297
304
298
305
afterEach ( ( ) => {
@@ -369,6 +376,7 @@ describe('DataSourceAggregatedView empty state test due to filter out with local
369
376
const { toasts } = notificationServiceMock . createStartContract ( ) ;
370
377
const uiSettings = uiSettingsServiceMock . createStartContract ( ) ;
371
378
const application = applicationServiceMock . createStartContract ( ) ;
379
+ const dataSourceSelection = new DataSourceSelectionService ( ) ;
372
380
const nextTick = ( ) => new Promise ( ( res ) => process . nextTick ( res ) ) ;
373
381
374
382
beforeEach ( ( ) => {
@@ -378,6 +386,7 @@ describe('DataSourceAggregatedView empty state test due to filter out with local
378
386
mockResponseForSavedObjectsCalls ( client , 'find' , getDataSourcesWithFieldsResponse ) ;
379
387
mockUiSettingsCalls ( uiSettings , 'get' , 'test1' ) ;
380
388
jest . spyOn ( utils , 'getApplication' ) . mockReturnValue ( application ) ;
389
+ jest . spyOn ( utils , 'getDataSourceSelection' ) . mockReturnValue ( dataSourceSelection ) ;
381
390
} ) ;
382
391
383
392
afterEach ( ( ) => {
@@ -439,6 +448,7 @@ describe('DataSourceAggregatedView error state test no matter hide local cluster
439
448
const { toasts } = notificationServiceMock . createStartContract ( ) ;
440
449
const uiSettings = uiSettingsServiceMock . createStartContract ( ) ;
441
450
const application = applicationServiceMock . createStartContract ( ) ;
451
+ const dataSourceSelection = new DataSourceSelectionService ( ) ;
442
452
const nextTick = ( ) => new Promise ( ( res ) => process . nextTick ( res ) ) ;
443
453
444
454
beforeEach ( ( ) => {
@@ -448,6 +458,7 @@ describe('DataSourceAggregatedView error state test no matter hide local cluster
448
458
mockErrorResponseForSavedObjectsCalls ( client , 'find' ) ;
449
459
mockUiSettingsCalls ( uiSettings , 'get' , 'test1' ) ;
450
460
jest . spyOn ( utils , 'getApplication' ) . mockReturnValue ( application ) ;
461
+ jest . spyOn ( utils , 'getDataSourceSelection' ) . mockReturnValue ( dataSourceSelection ) ;
451
462
} ) ;
452
463
453
464
afterEach ( ( ) => {
@@ -514,6 +525,7 @@ describe('DataSourceAggregatedView error state test no matter hide local cluster
514
525
describe ( 'DataSourceAggregatedView warning messages' , ( ) => {
515
526
const client = { } as any ;
516
527
const uiSettings = uiSettingsServiceMock . createStartContract ( ) ;
528
+ const dataSourceSelection = new DataSourceSelectionService ( ) ;
517
529
const nextTick = ( ) => new Promise ( ( res ) => process . nextTick ( res ) ) ;
518
530
let toasts : IToasts ;
519
531
const noDataSourcesConnectedMessage = `${ NO_DATASOURCES_CONNECTED_MESSAGE } ${ CONNECT_DATASOURCES_MESSAGE } ` ;
@@ -522,6 +534,7 @@ describe('DataSourceAggregatedView warning messages', () => {
522
534
beforeEach ( ( ) => {
523
535
toasts = notificationServiceMock . createStartContract ( ) . toasts ;
524
536
mockUiSettingsCalls ( uiSettings , 'get' , 'test1' ) ;
537
+ jest . spyOn ( utils , 'getDataSourceSelection' ) . mockReturnValue ( dataSourceSelection ) ;
525
538
} ) ;
526
539
527
540
it . each ( [
@@ -571,3 +584,47 @@ describe('DataSourceAggregatedView warning messages', () => {
571
584
}
572
585
) ;
573
586
} ) ;
587
+
588
+ describe ( 'DataSourceAggregatedView: dataSourceSelection)' , ( ) => {
589
+ let client : SavedObjectsClientContract ;
590
+ const { toasts } = notificationServiceMock . createStartContract ( ) ;
591
+ const uiSettings = uiSettingsServiceMock . createStartContract ( ) ;
592
+ const dataSourceSelection = new DataSourceSelectionService ( ) ;
593
+ dataSourceSelection . selectDataSource = jest . fn ( ) ;
594
+ const nextTick = ( ) => new Promise ( ( res ) => process . nextTick ( res ) ) ;
595
+ const activeDataSourceIds = [ 'test1' , 'test2' ] ;
596
+ const selectedOptions = [
597
+ { checked : 'on' , disabled : true , id : 'test1' , label : 'test1' } ,
598
+ { checked : 'on' , disabled : true , id : 'test2' , label : 'test2' } ,
599
+ ] ;
600
+ const componentId = 'component-id' ;
601
+ beforeEach ( ( ) => {
602
+ client = {
603
+ find : jest . fn ( ) . mockResolvedValue ( [ ] ) ,
604
+ } as any ;
605
+ mockResponseForSavedObjectsCalls ( client , 'find' , getDataSourcesWithFieldsResponse ) ;
606
+ mockUiSettingsCalls ( uiSettings , 'get' , 'test1' ) ;
607
+ jest . spyOn ( utils , 'getDataSourceSelection' ) . mockReturnValue ( dataSourceSelection ) ;
608
+ jest . spyOn ( utils , 'generateComponentId' ) . mockReturnValue ( componentId ) ;
609
+ } ) ;
610
+
611
+ it ( 'should render normally and call selectDataSource' , async ( ) => {
612
+ const component = shallow (
613
+ < DataSourceAggregatedView
614
+ fullWidth = { false }
615
+ hideLocalCluster = { false }
616
+ savedObjectsClient = { client }
617
+ notifications = { toasts }
618
+ displayAllCompatibleDataSources = { false }
619
+ activeDataSourceIds = { activeDataSourceIds }
620
+ uiSettings = { uiSettings }
621
+ />
622
+ ) ;
623
+
624
+ // Should render normally
625
+ expect ( component ) . toMatchSnapshot ( ) ;
626
+ await nextTick ( ) ;
627
+
628
+ expect ( dataSourceSelection . selectDataSource ) . toHaveBeenCalledWith ( componentId , selectedOptions ) ;
629
+ } ) ;
630
+ } ) ;
0 commit comments