Skip to content

Commit e4995fc

Browse files
committed
Fixing login button test to assert user Auth
1 parent 61b4442 commit e4995fc

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

__tests__/loginPage.test.js

Lines changed: 14 additions & 10 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 Login from '../src/components/login/login';
5+
import {authenticateUser} from '../src/components/Login';
66
import { MemoryRouter } from 'react-router-dom';
77
import { Provider } from 'react-redux';
88
import store from '../src/renderer/store';
@@ -11,11 +11,6 @@ import fetchMock from 'jest-fetch-mock';
1111
import { act } from 'react-test-renderer';
1212
import Docketeer from '../assets/docketeer-title.png';
1313

14-
const mockedUsedNavigate = jest.fn();
15-
// jest.mock('react-router-dom', () => ({
16-
// useNavigate: () => mockedUsedNavigate,
17-
// }));
18-
1914
fetchMock.enableMocks();
2015

2116
describe('Login Page Renders', () => {
@@ -46,13 +41,22 @@ describe('Login Page Renders', () => {
4641
});
4742

4843
test('Login button', async () => {
49-
fetch.mockResponseOnce(JSON.stringify({ username: 'sysadmin', password: 'belugas' }));
44+
fetch.mockResponseOnce(JSON.stringify({ username: 'csgroup', password: 'csgroup' }));
5045
const alert = window.alert = jest.fn();
51-
const loginButton = screen.getByRole('button');
46+
47+
// mock the login module as a whole, accessing the imported authenticateUser function property
48+
jest.mock('../src/components/Login');
49+
50+
// select login button
51+
const loginButton2 = screen.getByRole('login');
52+
// fire event to click login button
5253
await act(()=>{
53-
fireEvent.click(loginButton);
54+
fireEvent.click(loginButton2);
5455
});
55-
// need to fix issue of localhost/4000 not rendering anything after you login
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).toBeCalled;
5660
});
5761

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

src/components/Login.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ const Login = () => {
104104
color='primary'
105105
type='submit'
106106
size='medium'
107+
role='login'
107108
className='login-buttons'
108109
onClick={() => handleLogin}
109110
sx={{

0 commit comments

Comments
 (0)