Skip to content

Commit ef34e36

Browse files
Merge pull request RedHatInsights#308 from platex-rehor-bot/bot/RHCLOUD-47391
fix(help-panel): guard rendering with environment feature flag
1 parent 123b719 commit ef34e36

4 files changed

Lines changed: 101 additions & 2 deletions

File tree

cypress/component/HelpPanel.cy.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ const defaultFlags: IConfig['bootstrap'] = [{
2222
enabled: true,
2323
impressionData: false,
2424
variant: {name: 'disabled', enabled: false},
25+
}, {
26+
name: 'platform.va.environment.enabled',
27+
enabled: true,
28+
impressionData: false,
29+
variant: {name: 'disabled', enabled: false},
2530
}]
2631

2732
// Helper function to get message text for testing
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import React from 'react';
2+
import { fireEvent, render, screen } from '@testing-library/react';
3+
import { IntlProvider } from 'react-intl';
4+
import HelpPanelContent from './HelpPanelContent';
5+
6+
jest.mock('@unleash/proxy-client-react', () => ({
7+
useFlag: () => true,
8+
useFlags: () => [
9+
{ name: 'platform.chrome.help-panel_search', enabled: true },
10+
{ name: 'platform.chrome.help-panel_knowledge-base', enabled: true },
11+
{ name: 'platform.chrome.help-panel_chatbot', enabled: true },
12+
],
13+
}));
14+
15+
jest.mock('./HelpPanelCustomTabs', () => {
16+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
17+
const MockTabs = React.forwardRef((_props: unknown, _ref: unknown) => (
18+
<div data-testid="help-panel-custom-tabs">Help Panel Tabs</div>
19+
));
20+
MockTabs.displayName = 'MockHelpPanelCustomTabs';
21+
return {
22+
__esModule: true,
23+
default: MockTabs,
24+
};
25+
});
26+
27+
jest.mock('./HelpPanelCustomTabs.scss', () => ({}));
28+
29+
const renderWithIntl = (ui: React.ReactElement) => {
30+
return render(
31+
<IntlProvider locale="en" defaultLocale="en" messages={{}}>
32+
{ui}
33+
</IntlProvider>
34+
);
35+
};
36+
37+
describe('HelpPanelContent', () => {
38+
const mockToggleDrawer = jest.fn();
39+
40+
beforeEach(() => {
41+
mockToggleDrawer.mockClear();
42+
});
43+
44+
it('renders the full help panel with tabs', () => {
45+
renderWithIntl(<HelpPanelContent toggleDrawer={mockToggleDrawer} />);
46+
47+
expect(screen.getByTestId('help-panel-custom-tabs')).toBeInTheDocument();
48+
expect(screen.getByText('Help')).toBeInTheDocument();
49+
});
50+
51+
it('renders the status page link in header', () => {
52+
renderWithIntl(<HelpPanelContent toggleDrawer={mockToggleDrawer} />);
53+
54+
const statusLink = screen.getByText('Red Hat status page');
55+
expect(statusLink).toBeInTheDocument();
56+
expect(statusLink.closest('a')).toHaveAttribute(
57+
'href',
58+
'https://status.redhat.com/'
59+
);
60+
});
61+
62+
it('renders close button that calls toggleDrawer', () => {
63+
renderWithIntl(<HelpPanelContent toggleDrawer={mockToggleDrawer} />);
64+
65+
const closeButton = document.querySelector(
66+
'[data-ouia-component-id="help-panel-close-button"]'
67+
);
68+
expect(closeButton).toBeInTheDocument();
69+
fireEvent.click(closeButton!);
70+
expect(mockToggleDrawer).toHaveBeenCalledTimes(1);
71+
});
72+
});

src/components/HelpPanel/HelpPanelCustomTabs.test.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ describe('HelpPanelCustomTabs styling hooks', () => {
148148
expect(findHelpTab).toHaveAttribute('aria-selected', 'true');
149149
});
150150

151-
it('hides Virtual Assistant tab when feature flag is disabled', () => {
151+
it('hides Virtual Assistant tab when chatbot feature flag is disabled', () => {
152152
// Override the mock to return false for VA flag
153153
mockUseFlag.mockImplementation((flagName: string) => {
154154
if (flagName === 'platform.chrome.help-panel_chatbot') return false;
@@ -170,6 +170,26 @@ describe('HelpPanelCustomTabs styling hooks', () => {
170170
return true;
171171
});
172172
});
173+
174+
it('hides Virtual Assistant tab when VA environment flag is disabled', () => {
175+
mockUseFlag.mockImplementation((flagName: string) => {
176+
if (flagName === 'platform.va.environment.enabled') return false;
177+
if (flagName === 'platform.chrome.help-panel_chatbot') return true;
178+
return true;
179+
});
180+
181+
renderWithIntl(<HelpPanelCustomTabs />);
182+
183+
const vaTab = screen.queryByRole('tab', { name: /virtual assistant/i });
184+
expect(vaTab).not.toBeInTheDocument();
185+
186+
expect(screen.getByText('Find help')).toBeInTheDocument();
187+
188+
mockUseFlag.mockImplementation((flagName: string) => {
189+
if (flagName === 'platform.chrome.help-panel_chatbot') return true;
190+
return true;
191+
});
192+
});
173193
});
174194

175195
describe('HelpPanelCustomTabs UI interactions', () => {

src/components/HelpPanel/HelpPanelCustomTabs.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,11 @@ const HelpPanelCustomTabs = React.forwardRef<HelpPanelCustomTabsRef>(
266266
const intl = useIntl();
267267
const chrome = useChrome();
268268
const vaFlag = useFlag('platform.chrome.help-panel_chatbot');
269+
const vaEnvFlag = useFlag('platform.va.environment.enabled');
269270
const searchFlag = useFlag('platform.chrome.help-panel_search');
271+
const showVA = vaFlag && vaEnvFlag;
270272

271-
const baseTabs = useMemo(() => createBaseTabs(vaFlag), [vaFlag]);
273+
const baseTabs = useMemo(() => createBaseTabs(showVA), [showVA]);
272274
// Initialize store with find-help tab already having the correct sub-tab (Search when flag on, else Learn)
273275
// so content is correct on first paint and tests don't depend on a follow-up effect.
274276
const initialTabs = useMemo(

0 commit comments

Comments
 (0)