@@ -225,6 +225,68 @@ describe('HelpPanelCustomTabs UI interactions', () => {
225225 expect ( tabs [ 2 ] ) . toHaveTextContent ( 'New tab' ) ;
226226 } ) ;
227227
228+ it ( 'new tab defaults to Search sub-tab when search flag is enabled' , async ( ) => {
229+ renderWithIntl ( < HelpPanelCustomTabs /> ) ;
230+ const addTabButton = screen . getByRole ( 'button' , { name : / a d d t a b / i } ) ;
231+ fireEvent . click ( addTabButton ) ;
232+
233+ // Click the new tab to make it active
234+ await waitFor ( ( ) => {
235+ const newTab = screen . getByText ( 'New tab' ) ;
236+ expect ( newTab ) . toBeInTheDocument ( ) ;
237+ fireEvent . click ( newTab ) ;
238+ } ) ;
239+
240+ // The new tab should have sub-tabs; the Search sub-tab should be active
241+ await waitFor ( ( ) => {
242+ // Find all sub-tab containers — there may be multiple (one per main tab)
243+ const subtabContainers = document . querySelectorAll (
244+ '[data-ouia-component-id="help-panel-subtabs"]'
245+ ) ;
246+ // The last sub-tab container belongs to the newly added tab
247+ const lastSubtabs = subtabContainers [ subtabContainers . length - 1 ] ;
248+ const searchSubTab = within ( lastSubtabs as HTMLElement ) . getByRole ( 'tab' , {
249+ name : / s e a r c h / i,
250+ } ) ;
251+ expect ( searchSubTab ) . toHaveAttribute ( 'aria-selected' , 'true' ) ;
252+ } ) ;
253+ } ) ;
254+
255+ it ( 'new tab defaults to Learn sub-tab when search flag is disabled' , async ( ) => {
256+ mockUseFlag . mockImplementation ( ( flagName : string ) => {
257+ if ( flagName === 'platform.chrome.help-panel_search' ) return false ;
258+ if ( flagName === 'platform.chrome.help-panel_chatbot' ) return true ;
259+ return true ;
260+ } ) ;
261+
262+ renderWithIntl ( < HelpPanelCustomTabs /> ) ;
263+ const addTabButton = screen . getByRole ( 'button' , { name : / a d d t a b / i } ) ;
264+ fireEvent . click ( addTabButton ) ;
265+
266+ await waitFor ( ( ) => {
267+ const newTab = screen . getByText ( 'New tab' ) ;
268+ expect ( newTab ) . toBeInTheDocument ( ) ;
269+ fireEvent . click ( newTab ) ;
270+ } ) ;
271+
272+ await waitFor ( ( ) => {
273+ const subtabContainers = document . querySelectorAll (
274+ '[data-ouia-component-id="help-panel-subtabs"]'
275+ ) ;
276+ const lastSubtabs = subtabContainers [ subtabContainers . length - 1 ] ;
277+ const learnSubTab = within ( lastSubtabs as HTMLElement ) . getByRole ( 'tab' , {
278+ name : / l e a r n / i,
279+ } ) ;
280+ expect ( learnSubTab ) . toHaveAttribute ( 'aria-selected' , 'true' ) ;
281+ } ) ;
282+
283+ // Restore default mock
284+ mockUseFlag . mockImplementation ( ( flagName : string ) => {
285+ if ( flagName === 'platform.chrome.help-panel_chatbot' ) return true ;
286+ return true ;
287+ } ) ;
288+ } ) ;
289+
228290 it ( 'closes an added tab when clicking its close button' , ( ) => {
229291 renderWithIntl ( < HelpPanelCustomTabs /> ) ;
230292 fireEvent . click ( screen . getByRole ( 'button' , { name : / a d d t a b / i } ) ) ;
0 commit comments