6
6
import { CoreSetup , CoreStart } from '../../../src/core/public' ;
7
7
import { QueryInsightsDashboardsPlugin } from './plugin' ;
8
8
import { PLUGIN_NAME } from '../common' ;
9
+ import { renderApp } from './application' ;
10
+ import { coreMock } from '../../../src/core/public/mocks' ;
9
11
10
12
jest . mock ( './application' , ( ) => ( {
11
13
renderApp : jest . fn ( ) ,
@@ -16,34 +18,13 @@ describe('QueryInsightsDashboardsPlugin', () => {
16
18
let coreSetupMock : jest . Mocked < CoreSetup > ;
17
19
let coreStartMock : jest . Mocked < CoreStart > ;
18
20
let registerMock : jest . Mock ;
19
- let addNavLinksMock : jest . Mock ;
20
21
21
22
beforeEach ( ( ) => {
22
- coreSetupMock = ( {
23
- application : {
24
- register : jest . fn ( ) ,
25
- } ,
26
- chrome : {
27
- navGroup : {
28
- addNavLinksToGroup : jest . fn ( ) ,
29
- } ,
30
- } ,
31
- getStartServices : jest . fn ( ) . mockResolvedValue ( [ coreStartMock , { } ] ) ,
32
- } as unknown ) as jest . Mocked < CoreSetup > ;
33
-
34
- coreStartMock = ( {
35
- http : {
36
- get : jest . fn ( ) ,
37
- put : jest . fn ( ) ,
38
- } ,
39
- uiSettings : {
40
- get : jest . fn ( ) . mockReturnValue ( false ) ,
41
- } ,
42
- } as unknown ) as jest . Mocked < CoreStart > ;
23
+ coreSetupMock = coreMock . createSetup ( ) ;
24
+ coreStartMock = coreMock . createStart ( ) ;
43
25
44
26
plugin = new QueryInsightsDashboardsPlugin ( ) ;
45
27
registerMock = coreSetupMock . application . register ;
46
- addNavLinksMock = coreSetupMock . chrome . navGroup . addNavLinksToGroup ;
47
28
} ) ;
48
29
49
30
it ( 'should register the application in setup' , ( ) => {
@@ -58,33 +39,40 @@ describe('QueryInsightsDashboardsPlugin', () => {
58
39
label : expect . any ( String ) ,
59
40
order : expect . any ( Number ) ,
60
41
} ) ,
61
- order : expect . any ( Number ) ,
62
42
mount : expect . any ( Function ) ,
43
+ order : expect . any ( Number ) ,
63
44
description : expect . any ( String ) ,
64
45
} )
65
46
) ;
66
47
} ) ;
67
48
68
- it ( 'should add the navigation link to nav group' , ( ) => {
49
+ it ( 'should mount the application correctly' , async ( ) => {
69
50
plugin . setup ( coreSetupMock , { } as any ) ;
70
51
71
- expect ( addNavLinksMock ) . toHaveBeenCalledWith (
72
- expect . objectContaining ( {
73
- id : expect . any ( String ) ,
74
- description : expect . any ( String ) ,
75
- } ) ,
76
- expect . arrayContaining ( [
77
- expect . objectContaining ( {
78
- id : 'query-insights-dashboards' ,
79
- order : expect . any ( Number ) ,
80
- category : expect . objectContaining ( {
81
- euiIconType : expect . any ( String ) ,
82
- id : 'performance' , // Adjusted to match received data
83
- label : expect . any ( String ) ,
84
- order : expect . any ( Number ) ,
85
- } ) ,
86
- } ) ,
87
- ] )
52
+ const appRegistration = registerMock . mock . calls [ 0 ] [ 0 ] ;
53
+ expect ( appRegistration ) . toBeDefined ( ) ;
54
+
55
+ const paramsMock = { element : document . createElement ( 'div' ) } ;
56
+ const mountFunction = appRegistration . mount ;
57
+
58
+ await mountFunction ( paramsMock ) ;
59
+
60
+ const depsMock = { dataSourceManagement : undefined } ;
61
+ coreSetupMock . getStartServices . mockResolvedValue ( [ coreStartMock , depsMock ] ) ;
62
+
63
+ await mountFunction ( paramsMock ) ;
64
+
65
+ expect ( renderApp ) . toHaveBeenCalledWith (
66
+ coreStartMock ,
67
+ depsMock ,
68
+ expect . objectContaining ( { element : expect . any ( HTMLElement ) } ) ,
69
+ depsMock . dataSourceManagement
88
70
) ;
89
71
} ) ;
72
+
73
+ it ( 'should return empty start and stop methods' , ( ) => {
74
+ // Ensures `start` and `stop` do not introduce unwanted behavior
75
+ expect ( plugin . start ( coreStartMock ) ) . toEqual ( { } ) ;
76
+ expect ( plugin . stop ( ) ) . toBeUndefined ( ) ;
77
+ } ) ;
90
78
} ) ;
0 commit comments