@@ -2,7 +2,7 @@ import '@testing-library/jest-dom';
2
2
import React from 'react' ;
3
3
import { render , fireEvent , screen } from '@testing-library/react' ;
4
4
import App from '../src/renderer/App' ;
5
- import Login from '../src/components/login/login ' ;
5
+ import { authenticateUser } from '../src/components/Login ' ;
6
6
import { MemoryRouter } from 'react-router-dom' ;
7
7
import { Provider } from 'react-redux' ;
8
8
import store from '../src/renderer/store' ;
@@ -11,11 +11,6 @@ import fetchMock from 'jest-fetch-mock';
11
11
import { act } from 'react-test-renderer' ;
12
12
import Docketeer from '../assets/docketeer-title.png' ;
13
13
14
- const mockedUsedNavigate = jest . fn ( ) ;
15
- // jest.mock('react-router-dom', () => ({
16
- // useNavigate: () => mockedUsedNavigate,
17
- // }));
18
-
19
14
fetchMock . enableMocks ( ) ;
20
15
21
16
describe ( 'Login Page Renders' , ( ) => {
@@ -46,13 +41,39 @@ describe('Login Page Renders', () => {
46
41
} ) ;
47
42
48
43
test ( 'Login button' , async ( ) => {
49
- fetch . mockResponseOnce ( JSON . stringify ( { username : 'sysadmin ' , password : 'belugas ' } ) ) ;
44
+ fetch . mockResponseOnce ( JSON . stringify ( { username : 'csgroup ' , password : 'csgroup ' } ) ) ;
50
45
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
52
53
await act ( ( ) => {
53
- fireEvent . click ( loginButton ) ;
54
+ fireEvent . click ( loginButton2 ) ;
54
55
} ) ;
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 ) . 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' ) ;
56
77
} ) ;
57
78
58
79
test ( 'Docketeer Image' , async ( ) => {
0 commit comments