11import type { Meta , StoryObj } from '@storybook/react-webpack5' ;
22import { expect , userEvent , waitFor , within } from 'storybook/test' ;
3- import { delay } from 'msw' ;
43import { AppEntryWithRouter } from './_shared/components/AppEntryWithRouter' ;
54import {
65 helpPanelMswHandlers ,
76 navigateToTab ,
87 openHelpPanel ,
98 waitForPageLoad ,
109} from './_shared/helpPanelJourneyHelpers' ;
11- import { TEST_TIMEOUTS } from './_shared/testConstants' ;
10+ import { TEST_TIMEOUTS , delay } from './_shared/testConstants' ;
1211
1312/**
1413 * User Journey: Help Panel - Learn Panel
@@ -95,19 +94,23 @@ export const Step04_ToggleBundleScope: Story = {
9594 await navigateToTab ( canvasElement , 'Learn' ) ;
9695
9796 // Find the "All" toggle button using ID
98- const allToggle = document . getElementById ( 'all-toggle' ) as HTMLElement ;
99- await userEvent . click ( allToggle ) ;
97+ const allToggle = document . getElementById ( 'all-toggle' ) ;
98+ if ( ! allToggle ) {
99+ throw new Error ( 'All toggle button not found' ) ;
100+ }
101+ await userEvent . click ( allToggle as HTMLElement ) ;
100102
101103 // Pause after toggle
102104 await delay ( TEST_TIMEOUTS . AFTER_CLICK ) ;
103105
104106 console . log ( 'UJ: ✅ Toggled to All resources scope' ) ;
105107
106108 // Switch back to bundle using ID
107- const bundleToggle = document . getElementById (
108- 'bundle-toggle'
109- ) as HTMLElement ;
110- await userEvent . click ( bundleToggle ) ;
109+ const bundleToggle = document . getElementById ( 'bundle-toggle' ) ;
110+ if ( ! bundleToggle ) {
111+ throw new Error ( 'Bundle toggle button not found' ) ;
112+ }
113+ await userEvent . click ( bundleToggle as HTMLElement ) ;
111114
112115 // Pause after toggle
113116 await delay ( TEST_TIMEOUTS . AFTER_CLICK ) ;
@@ -127,7 +130,7 @@ export const Step05_FilterAndShowBookmarksOnly: Story = {
127130 await navigateToTab ( canvasElement , 'Learn' ) ;
128131
129132 // Find and click the content type dropdown
130- const contentTypeToggle = canvas . getByRole ( 'button' , {
133+ const contentTypeToggle = await canvas . findByRole ( 'button' , {
131134 name : / c o n t e n t t y p e / i,
132135 } ) ;
133136 await userEvent . click ( contentTypeToggle ) ;
@@ -146,8 +149,11 @@ export const Step05_FilterAndShowBookmarksOnly: Story = {
146149 // Find the checkbox input within the option
147150 const quickstartOption = document . querySelector (
148151 '[data-ouia-component-id="help-panel-content-type-option-quickstart"] input[type="checkbox"]'
149- ) as HTMLElement ;
150- await userEvent . click ( quickstartOption ) ;
152+ ) ;
153+ if ( ! quickstartOption ) {
154+ throw new Error ( 'Quick start checkbox option not found' ) ;
155+ }
156+ await userEvent . click ( quickstartOption as HTMLElement ) ;
151157
152158 // Pause after selecting filter
153159 await delay ( TEST_TIMEOUTS . AFTER_CLICK ) ;
@@ -189,7 +195,7 @@ export const Step06_ClearAllFilters: Story = {
189195 await navigateToTab ( canvasElement , 'Learn' ) ;
190196
191197 // Click content type dropdown
192- const contentTypeToggle = canvas . getByRole ( 'button' , {
198+ const contentTypeToggle = await canvas . findByRole ( 'button' , {
193199 name : / c o n t e n t t y p e / i,
194200 } ) ;
195201 await userEvent . click ( contentTypeToggle ) ;
@@ -207,8 +213,11 @@ export const Step06_ClearAllFilters: Story = {
207213
208214 const docOption = document . querySelector (
209215 '[data-ouia-component-id="help-panel-content-type-option-documentation"] input[type="checkbox"]'
210- ) as HTMLElement ;
211- await userEvent . click ( docOption ) ;
216+ ) ;
217+ if ( ! docOption ) {
218+ throw new Error ( 'Documentation checkbox option not found' ) ;
219+ }
220+ await userEvent . click ( docOption as HTMLElement ) ;
212221
213222 // Pause after selecting filter
214223 await delay ( TEST_TIMEOUTS . AFTER_CLICK ) ;
0 commit comments