forked from Billing-360/Billing-360-Dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempCodeRunnerFile.javascript
More file actions
45 lines (35 loc) · 1.63 KB
/
Copy pathtempCodeRunnerFile.javascript
File metadata and controls
45 lines (35 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import React from 'react';
import { render, fireEvent, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import Verification from './Verification';
test('renders email input field', () => {
const { getByPlaceholderText } = render(<Verification />);
const emailInput = getByPlaceholderText('Email address');
expect(emailInput).toBeInTheDocument();
});
test('submits form with valid email', async () => {
const { getByPlaceholderText, getByText } = render(<Verification />);
const emailInput = getByPlaceholderText('Email address');
const sendOtpButton = getByText('Send OTP');
fireEvent.change(emailInput, { target: { value: 'test@example.com' } });
fireEvent.click(sendOtpButton);
await waitFor(() => {
expect(alert).toHaveBeenCalledWith('OTP has been sent to E-mail.');
// You may need to adjust the assertion based on your implementation
expect(window.location.pathname).toEqual('/otp');
});
});
test('does not submit form with empty email', () => {
const { getByText } = render(<Verification />);
const sendOtpButton = getByText('Send OTP');
fireEvent.click(sendOtpButton);
expect(alert).toHaveBeenCalledWith('Please enter your email.');
});
test('does not submit form with invalid email format', () => {
const { getByPlaceholderText, getByText } = render(<Verification />);
const emailInput = getByPlaceholderText('Email address');
const sendOtpButton = getByText('Send OTP');
fireEvent.change(emailInput, { target: { value: 'invalidemail' } });
fireEvent.click(sendOtpButton);
expect(alert).toHaveBeenCalledWith('Please enter a valid email address.');
});