File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed
packages/template-retail-react-app/app/components/otp-auth Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import {
1212 Button ,
1313 Input ,
1414 SimpleGrid ,
15+ Spinner ,
1516 Stack ,
1617 Text ,
1718 HStack ,
@@ -271,6 +272,17 @@ const OtpAuth = ({
271272 ) ) }
272273 </ SimpleGrid >
273274
275+ { /* Loading spinner during verification */ }
276+ { isVerifying && (
277+ < Spinner
278+ size = "sm"
279+ color = "blue.500"
280+ role = "status"
281+ aria-live = "polite"
282+ data-testid = "otp-verifying-spinner"
283+ />
284+ ) }
285+
274286 { /* Error message */ }
275287 { error && (
276288 < Text fontSize = "sm" color = "red.500" textAlign = "center" >
Original file line number Diff line number Diff line change @@ -246,6 +246,41 @@ describe('OtpAuth', () => {
246246 await user . type ( otpInputs [ 7 ] , '8' )
247247 expect ( otpInputs [ 7 ] ) . toHaveFocus ( )
248248 } )
249+
250+ test ( 'shows spinner while OTP is being verified' , async ( ) => {
251+ const deferred = { }
252+ const verifyingPromise = new Promise ( ( resolve ) => {
253+ deferred . resolve = resolve
254+ } )
255+ const mockVerify = jest . fn ( ) . mockReturnValue ( verifyingPromise )
256+
257+ const user = userEvent . setup ( )
258+ renderWithProviders (
259+ < OtpAuth
260+ isOpen = { true }
261+ onClose = { mockOnClose }
262+ form = { mockForm }
263+ handleOtpVerification = { mockVerify }
264+ handleSendEmailOtp = { mockHandleSendEmailOtp }
265+ />
266+ )
267+
268+ expect ( screen . queryByTestId ( 'otp-verifying-spinner' ) ) . not . toBeInTheDocument ( )
269+
270+ const otpInputs = screen . getAllByRole ( 'textbox' )
271+ fireEvent . paste ( otpInputs [ 0 ] , {
272+ clipboardData : { getData : ( ) => '12345678' }
273+ } )
274+
275+ await waitFor ( ( ) => {
276+ expect ( screen . getByTestId ( 'otp-verifying-spinner' ) ) . toBeInTheDocument ( )
277+ } )
278+
279+ deferred . resolve ( { success : true } )
280+ await waitFor ( ( ) => {
281+ expect ( screen . queryByTestId ( 'otp-verifying-spinner' ) ) . not . toBeInTheDocument ( )
282+ } )
283+ } )
249284 } )
250285
251286 describe ( 'Keyboard Navigation' , ( ) => {
You can’t perform that action at this time.
0 commit comments