Skip to content

Commit a42edfe

Browse files
authored
Merge pull request RedHatInsights#291 from RedHatInsights/bot/RHCLOUD-45252
test(help-panel): add in-page link stories
2 parents 5ddd04b + fe30aa1 commit a42edfe

3 files changed

Lines changed: 640 additions & 0 deletions

File tree

Lines changed: 368 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,368 @@
1+
import type { Meta, StoryObj } from '@storybook/react-webpack5';
2+
import { expect, userEvent, waitFor, within } from 'storybook/test';
3+
import { AppEntryWithLinks } from './_shared/components/AppEntryWithLinks';
4+
import {
5+
helpPanelMswHandlers,
6+
supportPanelMswHandlers,
7+
waitForPageLoad,
8+
} from './_shared/helpPanelJourneyHelpers';
9+
import { TEST_TIMEOUTS, delay } from './_shared/testConstants';
10+
11+
/**
12+
* User Journey: Help Panel - In-Page Links
13+
*
14+
* Tests the complete user workflow for clicking in-page HelpPanelLink components
15+
* and verifying the help panel opens with the correct tab and content.
16+
*
17+
* This verifies that links embedded in console pages correctly trigger the
18+
* help panel drawer and navigate to the appropriate tab (Learn, APIs, Support,
19+
* Knowledge Base, Feedback) or display custom content.
20+
*/
21+
22+
const meta: Meta<typeof AppEntryWithLinks> = {
23+
title: 'User Journeys/Help Panel/In-Page Links',
24+
component: AppEntryWithLinks,
25+
parameters: {
26+
layout: 'fullscreen',
27+
msw: {
28+
handlers: [...helpPanelMswHandlers, ...supportPanelMswHandlers],
29+
},
30+
docs: {
31+
description: {
32+
component: `
33+
# Help Panel - In-Page Links User Journey
34+
35+
Tests the in-page link functionality where clicking a HelpPanelLink
36+
in the console opens the help panel with specific content:
37+
38+
- Clicking a Learn link opens the Learn tab
39+
- Clicking an API link opens the APIs tab
40+
- Clicking a Support link opens the Support tab
41+
- Clicking a link with custom content displays that content
42+
- Clicking a Knowledge Base link opens the KB tab
43+
- Clicking a Feedback link opens the Feedback tab
44+
`,
45+
},
46+
},
47+
},
48+
args: {
49+
initialRoute: '/',
50+
bundle: 'insights',
51+
},
52+
};
53+
54+
export default meta;
55+
56+
type Story = StoryObj<typeof meta>;
57+
58+
/**
59+
* Shared helper for clicking an in-page link and asserting the help panel
60+
* opens with the correct tab and (optionally) sub-tab or custom content.
61+
*
62+
* Uses scoped selectors to avoid "multiple elements" errors when tab titles
63+
* match card titles or custom content headings on the page.
64+
*/
65+
interface ClickLinkAndAssertTabOptions {
66+
canvasElement: HTMLElement;
67+
linkName: RegExp;
68+
tabTitle: string;
69+
subTabOuiaId?: string;
70+
customContentOuiaId?: string;
71+
}
72+
73+
const clickLinkAndAssertTab = async ({
74+
canvasElement,
75+
linkName,
76+
tabTitle,
77+
subTabOuiaId,
78+
customContentOuiaId,
79+
}: ClickLinkAndAssertTabOptions) => {
80+
const canvas = within(canvasElement);
81+
82+
// Click the link
83+
const link = await canvas.findByRole('button', { name: linkName });
84+
await userEvent.click(link);
85+
86+
// Wait for the help panel drawer to open
87+
await delay(TEST_TIMEOUTS.AFTER_DRAWER_OPEN);
88+
89+
// Verify the help panel is open by checking for the panel title
90+
await waitFor(
91+
() => {
92+
const helpTitle = canvasElement.querySelector(
93+
'[data-ouia-component-id="help-panel-title"]'
94+
);
95+
expect(helpTitle).toBeInTheDocument();
96+
},
97+
{ timeout: TEST_TIMEOUTS.ELEMENT_WAIT }
98+
);
99+
100+
// Verify the tab was created with the correct title.
101+
// Use queryAllByText to handle cases where the title appears in multiple
102+
// places (e.g., tab text + card title, or tab text + custom content heading).
103+
await waitFor(
104+
() => {
105+
const matches = canvas.queryAllByText(tabTitle);
106+
expect(matches.length).toBeGreaterThanOrEqual(1);
107+
},
108+
{ timeout: TEST_TIMEOUTS.ELEMENT_WAIT }
109+
);
110+
111+
// Verify the sub-tab is active (if specified)
112+
if (subTabOuiaId) {
113+
await waitFor(
114+
() => {
115+
const subTab = canvasElement.querySelector(
116+
`[data-ouia-component-id="${subTabOuiaId}"]`
117+
);
118+
expect(subTab).toBeInTheDocument();
119+
},
120+
{ timeout: TEST_TIMEOUTS.ELEMENT_WAIT }
121+
);
122+
}
123+
124+
// Verify custom content is rendered (if specified)
125+
if (customContentOuiaId) {
126+
await waitFor(
127+
() => {
128+
const customContent = canvasElement.querySelector(
129+
`[data-ouia-component-id="${customContentOuiaId}"]`
130+
);
131+
expect(customContent).toBeInTheDocument();
132+
},
133+
{ timeout: TEST_TIMEOUTS.ELEMENT_WAIT }
134+
);
135+
}
136+
};
137+
138+
/**
139+
* Manual Testing Entry Point
140+
*
141+
* Use this story to manually test in-page links.
142+
* Click any of the HelpPanelLink buttons on the page cards
143+
* and verify the help panel opens with the correct tab.
144+
*/
145+
export const ManualTesting: Story = {};
146+
147+
/**
148+
* 01 / Page Loads with In-Page Links
149+
*
150+
* Verifies the page loads with HelpPanelLink components visible in the cards.
151+
*/
152+
export const Step01_PageLoadsWithLinks: Story = {
153+
name: '01 / Page Loads with In-Page Links',
154+
play: async ({ canvasElement }) => {
155+
await waitForPageLoad(canvasElement);
156+
157+
const canvas = within(canvasElement);
158+
159+
// Verify HelpPanelLink buttons are present
160+
await canvas.findByRole('button', { name: /view getting started guide/i });
161+
await canvas.findByRole('button', { name: /view api documentation/i });
162+
await canvas.findByRole('button', { name: /get support/i });
163+
await canvas.findByRole('button', { name: /view feature help/i });
164+
await canvas.findByRole('button', { name: /browse knowledge base/i });
165+
await canvas.findByRole('button', { name: /give feedback/i });
166+
167+
console.log('UJ: \u2705 Page loaded with all in-page link buttons visible');
168+
},
169+
};
170+
171+
/**
172+
* 02 / Click Learn Link Opens Help Panel
173+
*
174+
* Clicking the "View getting started guide" link should open the help panel
175+
* with a new tab titled "Getting Started Guide" showing the Learn sub-tab.
176+
*/
177+
export const Step02_ClickLearnLink: Story = {
178+
name: '02 / Click Learn Link Opens Help Panel',
179+
play: async ({ canvasElement }) => {
180+
await waitForPageLoad(canvasElement);
181+
182+
await clickLinkAndAssertTab({
183+
canvasElement,
184+
linkName: /view getting started guide/i,
185+
tabTitle: 'Getting Started Guide',
186+
});
187+
188+
console.log(
189+
'UJ: \u2705 Learn link opened help panel with "Getting Started Guide" tab'
190+
);
191+
},
192+
};
193+
194+
/**
195+
* 03 / Click API Link Opens API Tab
196+
*
197+
* Clicking the "View API documentation" link should open the help panel
198+
* with a new tab showing the APIs sub-tab content.
199+
*/
200+
export const Step03_ClickAPILink: Story = {
201+
name: '03 / Click API Link Opens API Tab',
202+
play: async ({ canvasElement }) => {
203+
await waitForPageLoad(canvasElement);
204+
205+
await clickLinkAndAssertTab({
206+
canvasElement,
207+
linkName: /view api documentation/i,
208+
tabTitle: 'API Documentation',
209+
subTabOuiaId: 'help-panel-subtab-api',
210+
});
211+
212+
console.log(
213+
'UJ: \u2705 API link opened help panel with "API Documentation" tab'
214+
);
215+
},
216+
};
217+
218+
/**
219+
* 04 / Click Support Link Opens Support Tab
220+
*
221+
* Clicking the "Get support" link should open the help panel
222+
* with a new tab showing the Support sub-tab content.
223+
*/
224+
export const Step04_ClickSupportLink: Story = {
225+
name: '04 / Click Support Link Opens Support Tab',
226+
play: async ({ canvasElement }) => {
227+
await waitForPageLoad(canvasElement);
228+
229+
await clickLinkAndAssertTab({
230+
canvasElement,
231+
linkName: /get support/i,
232+
tabTitle: 'Support',
233+
subTabOuiaId: 'help-panel-subtab-support',
234+
});
235+
236+
console.log('UJ: \u2705 Support link opened help panel with "Support" tab');
237+
},
238+
};
239+
240+
/**
241+
* 05 / Click Custom Content Link Shows Custom Content
242+
*
243+
* Clicking the "View feature help" link should open the help panel
244+
* with a new tab containing custom content passed via HelpPanelLink.
245+
*/
246+
export const Step05_ClickCustomContentLink: Story = {
247+
name: '05 / Click Custom Content Link Shows Custom Content',
248+
play: async ({ canvasElement }) => {
249+
await waitForPageLoad(canvasElement);
250+
251+
const canvas = within(canvasElement);
252+
253+
await clickLinkAndAssertTab({
254+
canvasElement,
255+
linkName: /view feature help/i,
256+
tabTitle: 'Feature Help',
257+
customContentOuiaId: 'custom-help-content',
258+
});
259+
260+
// Verify the custom content text
261+
await canvas.findByText(
262+
'This is custom help content passed via HelpPanelLink.'
263+
);
264+
265+
console.log(
266+
'UJ: \u2705 Custom content link opened help panel with custom content displayed'
267+
);
268+
},
269+
};
270+
271+
/**
272+
* 06 / Click Knowledge Base Link Opens KB Tab
273+
*
274+
* Clicking the "Browse knowledge base" link should open the help panel
275+
* with a new tab showing the Knowledge Base sub-tab content.
276+
*/
277+
export const Step06_ClickKBLink: Story = {
278+
name: '06 / Click Knowledge Base Link Opens KB Tab',
279+
play: async ({ canvasElement }) => {
280+
await waitForPageLoad(canvasElement);
281+
282+
await clickLinkAndAssertTab({
283+
canvasElement,
284+
linkName: /browse knowledge base/i,
285+
tabTitle: 'Knowledge Base',
286+
subTabOuiaId: 'help-panel-subtab-kb',
287+
});
288+
289+
console.log(
290+
'UJ: \u2705 Knowledge Base link opened help panel with "Knowledge Base" tab'
291+
);
292+
},
293+
};
294+
295+
/**
296+
* 07 / Click Feedback Link Opens Feedback Tab
297+
*
298+
* Clicking the "Give feedback" link should open the help panel
299+
* with a new tab showing the Feedback sub-tab content.
300+
*/
301+
export const Step07_ClickFeedbackLink: Story = {
302+
name: '07 / Click Feedback Link Opens Feedback Tab',
303+
play: async ({ canvasElement }) => {
304+
await waitForPageLoad(canvasElement);
305+
306+
await clickLinkAndAssertTab({
307+
canvasElement,
308+
linkName: /give feedback/i,
309+
tabTitle: 'Share feedback',
310+
subTabOuiaId: 'help-panel-subtab-feedback',
311+
});
312+
313+
console.log(
314+
'UJ: \u2705 Feedback link opened help panel with "Share feedback" tab'
315+
);
316+
},
317+
};
318+
319+
/**
320+
* 08 / Multiple Links Create Separate Tabs
321+
*
322+
* Clicking two different in-page links creates separate tabs in the help panel.
323+
* After clicking Learn and then API links, both tabs should be visible.
324+
*/
325+
export const Step08_MultipleLinksCreateTabs: Story = {
326+
name: '08 / Multiple Links Create Separate Tabs',
327+
play: async ({ canvasElement }) => {
328+
await waitForPageLoad(canvasElement);
329+
330+
const canvas = within(canvasElement);
331+
332+
// Click the Learn link first
333+
await clickLinkAndAssertTab({
334+
canvasElement,
335+
linkName: /view getting started guide/i,
336+
tabTitle: 'Getting Started Guide',
337+
});
338+
339+
// Click the API link (panel is already open)
340+
const apiLink = await canvas.findByRole('button', {
341+
name: /view api documentation/i,
342+
});
343+
await userEvent.click(apiLink);
344+
await delay(TEST_TIMEOUTS.AFTER_TAB_CHANGE);
345+
346+
// Verify second tab created
347+
await waitFor(
348+
() => {
349+
const apiTabText = canvas.getByText('API Documentation');
350+
expect(apiTabText).toBeInTheDocument();
351+
},
352+
{ timeout: TEST_TIMEOUTS.ELEMENT_WAIT }
353+
);
354+
355+
// Verify the first tab still exists
356+
await waitFor(
357+
() => {
358+
const learnTabText = canvas.getByText('Getting Started Guide');
359+
expect(learnTabText).toBeInTheDocument();
360+
},
361+
{ timeout: TEST_TIMEOUTS.ELEMENT_WAIT }
362+
);
363+
364+
console.log(
365+
'UJ: \u2705 Multiple in-page links created separate tabs in help panel'
366+
);
367+
},
368+
};

0 commit comments

Comments
 (0)