@@ -42,7 +42,7 @@ describe('ChatPlugin', () => {
4242 } ,
4343 chrome : {
4444 navControls : {
45- registerRight : jest . fn ( ) ,
45+ registerPrimaryHeaderRight : jest . fn ( ) ,
4646 } ,
4747 globalSearch : {
4848 registerSearchCommand : jest . fn ( ) ,
@@ -88,7 +88,7 @@ describe('ChatPlugin', () => {
8888 it ( 'should register chat button in header nav controls' , ( ) => {
8989 plugin . start ( mockCoreStart , mockDeps ) ;
9090
91- expect ( mockCoreStart . chrome . navControls . registerRight ) . toHaveBeenCalledWith ( {
91+ expect ( mockCoreStart . chrome . navControls . registerPrimaryHeaderRight ) . toHaveBeenCalledWith ( {
9292 order : 1000 ,
9393 mount : expect . any ( Function ) ,
9494 } ) ;
@@ -111,7 +111,7 @@ describe('ChatPlugin', () => {
111111 // ChatService should still be created (uses proxy endpoint)
112112 expect ( ChatService ) . toHaveBeenCalledWith ( ) ;
113113 expect ( startContract . chatService ) . toBeInstanceOf ( ChatService ) ;
114- expect ( mockCoreStart . chrome . navControls . registerRight ) . toHaveBeenCalled ( ) ;
114+ expect ( mockCoreStart . chrome . navControls . registerPrimaryHeaderRight ) . toHaveBeenCalled ( ) ;
115115 } ) ;
116116
117117 it ( 'should not initialize when plugin is disabled' , ( ) => {
@@ -124,7 +124,7 @@ describe('ChatPlugin', () => {
124124
125125 expect ( ChatService ) . not . toHaveBeenCalled ( ) ;
126126 expect ( startContract . chatService ) . toBeUndefined ( ) ;
127- expect ( mockCoreStart . chrome . navControls . registerRight ) . not . toHaveBeenCalled ( ) ;
127+ expect ( mockCoreStart . chrome . navControls . registerPrimaryHeaderRight ) . not . toHaveBeenCalled ( ) ;
128128 } ) ;
129129
130130 it ( 'should not initialize when enabled is missing (defaults to false)' , ( ) => {
@@ -136,7 +136,7 @@ describe('ChatPlugin', () => {
136136
137137 expect ( ChatService ) . not . toHaveBeenCalled ( ) ;
138138 expect ( startContract . chatService ) . toBeUndefined ( ) ;
139- expect ( mockCoreStart . chrome . navControls . registerRight ) . not . toHaveBeenCalled ( ) ;
139+ expect ( mockCoreStart . chrome . navControls . registerPrimaryHeaderRight ) . not . toHaveBeenCalled ( ) ;
140140 } ) ;
141141 } ) ;
142142
@@ -147,12 +147,12 @@ describe('ChatPlugin', () => {
147147 plugin . start ( mockCoreStart , mockDeps ) ;
148148
149149 // Get the mount function that was registered
150- const registerCall = ( mockCoreStart . chrome . navControls . registerRight as jest . Mock ) . mock
151- . calls [ 0 ] ;
150+ const registerCall = ( mockCoreStart . chrome . navControls
151+ . registerPrimaryHeaderRight as jest . Mock ) . mock . calls [ 0 ] ;
152152 mountFunction = registerCall [ 0 ] . mount ;
153153 } ) ;
154154
155- it ( 'should show chat button when app starts with "explore" ' , ( ) => {
155+ it ( 'should show chat button' , ( ) => {
156156 const mockElement = document . createElement ( 'div' ) ;
157157 const mockUnmount = jest . fn ( ) ;
158158 ( toMountPoint as jest . Mock ) . mockReturnValue ( jest . fn ( ) . mockReturnValue ( mockUnmount ) ) ;
@@ -167,101 +167,6 @@ describe('ChatPlugin', () => {
167167 // Cleanup
168168 cleanup ( ) ;
169169 } ) ;
170-
171- it ( 'should hide chat button when app does not start with "explore"' , ( ) => {
172- const mockElement = document . createElement ( 'div' ) ;
173- const mockUnmount = jest . fn ( ) ;
174- ( toMountPoint as jest . Mock ) . mockReturnValue ( jest . fn ( ) . mockReturnValue ( mockUnmount ) ) ;
175-
176- // Reset the mock to clear previous calls
177- ( toMountPoint as jest . Mock ) . mockClear ( ) ;
178-
179- // Start with a fresh BehaviorSubject for non-explore app
180- const nonExploreAppId$ = new BehaviorSubject < string | undefined > ( 'dashboard' ) ;
181- mockCoreStart . application . currentAppId$ = nonExploreAppId$ ;
182-
183- // Re-register the plugin with the new app ID
184- plugin . start ( mockCoreStart , mockDeps ) ;
185- const registerCall = ( mockCoreStart . chrome . navControls . registerRight as jest . Mock ) . mock
186- . calls [ 1 ] ;
187- const newMountFunction = registerCall [ 0 ] . mount ;
188-
189- const cleanup = newMountFunction ( mockElement ) ;
190-
191- // Should not mount the component for non-explore apps
192- expect ( toMountPoint ) . not . toHaveBeenCalled ( ) ;
193-
194- // Cleanup
195- cleanup ( ) ;
196- } ) ;
197-
198- it ( 'should handle app changes from explore to non-explore' , ( ) => {
199- const mockElement = document . createElement ( 'div' ) ;
200- const mockUnmount = jest . fn ( ) ;
201- ( toMountPoint as jest . Mock ) . mockReturnValue ( jest . fn ( ) . mockReturnValue ( mockUnmount ) ) ;
202-
203- const cleanup = mountFunction ( mockElement ) ;
204-
205- // Start with explore app
206- mockCurrentAppId$ . next ( 'explore-metrics' ) ;
207- expect ( toMountPoint ) . toHaveBeenCalled ( ) ;
208-
209- // Change to non-explore app
210- mockCurrentAppId$ . next ( 'discover' ) ;
211- expect ( mockUnmount ) . toHaveBeenCalled ( ) ;
212-
213- // Cleanup
214- cleanup ( ) ;
215- } ) ;
216-
217- it ( 'should handle undefined app id' , ( ) => {
218- const mockElement = document . createElement ( 'div' ) ;
219-
220- // Reset the mock to clear previous calls
221- ( toMountPoint as jest . Mock ) . mockClear ( ) ;
222-
223- // Create a new plugin instance for this test
224- const testPlugin = new ChatPlugin ( mockInitializerContext ) ;
225-
226- // Start with a fresh BehaviorSubject for undefined app
227- const undefinedAppId$ = new BehaviorSubject < string | undefined > ( undefined ) ;
228- const testCoreStart = {
229- ...mockCoreStart ,
230- application : {
231- currentAppId$ : undefinedAppId$ ,
232- } ,
233- } ;
234-
235- // Start the plugin with undefined app ID
236- testPlugin . start ( testCoreStart , mockDeps ) ;
237- const registerCall = ( testCoreStart . chrome . navControls . registerRight as jest . Mock ) . mock
238- . calls [ 0 ] ;
239- const newMountFunction = registerCall [ 0 ] . mount ;
240-
241- const cleanup = newMountFunction ( mockElement ) ;
242-
243- expect ( toMountPoint ) . not . toHaveBeenCalled ( ) ;
244-
245- // Cleanup
246- cleanup ( ) ;
247- } ) ;
248-
249- it ( 'should cleanup subscription on unmount' , ( ) => {
250- const mockElement = document . createElement ( 'div' ) ;
251- const mockSubscription = {
252- unsubscribe : jest . fn ( ) ,
253- } ;
254-
255- // Mock the subscription
256- jest . spyOn ( mockCurrentAppId$ , 'subscribe' ) . mockReturnValue ( mockSubscription as any ) ;
257-
258- const cleanup = mountFunction ( mockElement ) ;
259-
260- // Call cleanup
261- cleanup ( ) ;
262-
263- expect ( mockSubscription . unsubscribe ) . toHaveBeenCalled ( ) ;
264- } ) ;
265170 } ) ;
266171
267172 describe ( 'stop' , ( ) => {
@@ -301,8 +206,8 @@ describe('ChatPlugin', () => {
301206 it ( 'should pass correct props to ChatHeaderButton' , ( ) => {
302207 plugin . start ( mockCoreStart , mockDeps ) ;
303208
304- const registerCall = ( mockCoreStart . chrome . navControls . registerRight as jest . Mock ) . mock
305- . calls [ 0 ] ;
209+ const registerCall = ( mockCoreStart . chrome . navControls
210+ . registerPrimaryHeaderRight as jest . Mock ) . mock . calls [ 0 ] ;
306211 const mountFunction = registerCall [ 0 ] . mount ;
307212 const mockElement = document . createElement ( 'div' ) ;
308213
0 commit comments