Skip to content

Commit a9a4525

Browse files
syadupathi-sfunandyala
authored andcommitted
W-21190081 Add spinner during OTP verification (#3643)
1 parent 07a6c5a commit a9a4525

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

packages/template-retail-react-app/app/components/otp-auth/index.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff 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">

packages/template-retail-react-app/app/components/otp-auth/index.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff 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', () => {

0 commit comments

Comments
 (0)