Skip to content

Commit 8dd59e8

Browse files
authored
Merge pull request #288 from RedHatInsights/bot/RHCLOUD-46462
fix(help-panel): default new tab to Search
2 parents 53baa83 + 8451cac commit 8dd59e8

2 files changed

Lines changed: 64 additions & 1 deletion

File tree

src/components/HelpPanel/HelpPanelCustomTabs.test.tsx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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: /add tab/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: /search/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: /add tab/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: /learn/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: /add tab/i }));

src/components/HelpPanel/HelpPanelCustomTabs.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,12 @@ const HelpPanelCustomTabs = React.forwardRef<HelpPanelCustomTabsRef>(
429429
// The title will be a placeholder until action is taken by the user
430430
setNewActionTitle(undefined);
431431
const newTabId = crypto.randomUUID();
432+
const defaultTabType = searchFlag ? TabType.search : TabType.learn;
432433
const tab = {
433434
id: newTabId,
434435
title: NEW_TAB_PLACEHOLDER,
435436
closeable: true,
436-
tabType: TabType.learn,
437+
tabType: defaultTabType,
437438
isNewTab: true,
438439
};
439440
addTab(tab);

0 commit comments

Comments
 (0)