Skip to content

Commit d33db55

Browse files
committed
This commit will add tests to LoginPage tests to handle the click of register button and successful navigation to the Sign Up Page
1 parent e4995fc commit d33db55

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

__tests__/loginPage.test.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,24 @@ describe('Login Page Renders', () => {
5656
// should ensure the login button has been clicked
5757
expect(loginButton2).toBeCalled;
5858
// should ensure that the authenticate user function invoked by button click is called
59-
expect(authenticateUser).toBeCalled;
59+
expect(authenticateUser).toHaveBeenCalled;
60+
});
61+
62+
test('Register Button navigates to Sign Up Page', async () => {
63+
// select the register button
64+
const registerButton = screen.getByRole('register');
65+
// fire event to click the button, navigating to new page
66+
await act(() => {
67+
fireEvent.click(registerButton);
68+
});
69+
// assert that the event happened
70+
expect(registerButton).toBeCalled;
71+
72+
// on new page, select the title h1 element -> 'Sign Up'
73+
const title = document.querySelector('h1');
74+
75+
// assert that the title element has the SIgn Up text
76+
expect(title.textContent).toBe('Sign Up');
6077
});
6178

6279
test('Docketeer Image', async () => {

src/components/Login.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ const Login = () => {
118118
<Button
119119
variant='contained'
120120
size='small'
121+
role='register'
121122
className='register login-buttons'
122123
onClick={() => navigate('/userSignup')}
123124
sx={{

0 commit comments

Comments
 (0)