Skip to content

Commit dcfe6bb

Browse files
committed
modified LoginPage test for more unit coverage
1 parent d2ae7d8 commit dcfe6bb

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

__tests__/loginPage.test.js

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import '@testing-library/jest-dom';
22
import React from 'react';
33
import {render, fireEvent, screen} from '@testing-library/react';
44
import App from '../src/renderer/App';
5-
import {authenticateUser} from '../src/components/Login';
5+
import Login from '../src/components/Login';
66
import { MemoryRouter } from 'react-router-dom';
77
import { Provider } from 'react-redux';
88
import store from '../src/renderer/store';
@@ -25,9 +25,9 @@ describe('Login Page Renders', () => {
2525
</Provider>
2626
);
2727
});
28-
screen.debug();
28+
// screen.debug();
2929
});
30-
30+
3131
test('Username accepts input', async () => {
3232
const username = document.querySelector('#username');
3333
await fireEvent.change(username, {target: {value:'sysadmin'}});
@@ -40,23 +40,42 @@ describe('Login Page Renders', () => {
4040
expect(password.value).toBe('belugas');
4141
});
4242

43-
test('Login button', async () => {
44-
fetch.mockResponseOnce(JSON.stringify({ username: 'csgroup', password: 'csgroup' }));
45-
const alert = window.alert = jest.fn();
43+
test('Login button is clicked, throwing error', async () => {
44+
const spy = jest.spyOn(console, 'log');
4645

47-
// mock the login module as a whole, accessing the imported authenticateUser function property
48-
jest.mock('../src/components/Login');
46+
const username = document.querySelector('#username');
47+
await fireEvent.change(username, { target: { value: '' } });
48+
49+
const password = document.querySelector('#password');
50+
await fireEvent.change(password, {target: {value:''}});
4951

5052
// select login button
5153
const loginButton2 = screen.getByRole('login');
5254
// fire event to click login button
5355
await act(()=>{
5456
fireEvent.click(loginButton2);
5557
});
56-
// should ensure the login button has been clicked
57-
expect(loginButton2).toBeCalled;
58-
// should ensure that the authenticate user function invoked by button click is called
59-
expect(authenticateUser).toHaveBeenCalled;
58+
59+
// assert the console logs for errors were throw
60+
expect(spy).toHaveBeenCalled();
61+
});
62+
63+
test('Login button is clicked, logging in', async () => {
64+
// test to submit a valid login, and redirect to a new page
65+
66+
fireEvent.change(document.querySelector('#username'), { target: { value: 'test2' } });
67+
68+
fireEvent.change(document.querySelector('#password'), { target: { value: 'codesmith123' } });
69+
70+
const loginButton = screen.getByRole('login');
71+
await act(()=>{
72+
fireEvent.click(screen.getByRole('login'));
73+
});
74+
75+
expect(loginButton).toBeCalled;
76+
77+
// Needs Completion Docketeam 10.0
78+
6079
});
6180

6281
test('Register Button navigates to Sign Up Page', async () => {

0 commit comments

Comments
 (0)