@@ -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 { authenticateUser } from '../src/components/Login' ;
5
+ import Login 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' ;
@@ -25,9 +25,9 @@ describe('Login Page Renders', () => {
25
25
</ Provider >
26
26
) ;
27
27
} ) ;
28
- screen . debug ( ) ;
28
+ // screen.debug();
29
29
} ) ;
30
-
30
+
31
31
test ( 'Username accepts input' , async ( ) => {
32
32
const username = document . querySelector ( '#username' ) ;
33
33
await fireEvent . change ( username , { target : { value :'sysadmin' } } ) ;
@@ -40,23 +40,42 @@ describe('Login Page Renders', () => {
40
40
expect ( password . value ) . toBe ( 'belugas' ) ;
41
41
} ) ;
42
42
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' ) ;
46
45
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 :'' } } ) ;
49
51
50
52
// select login button
51
53
const loginButton2 = screen . getByRole ( 'login' ) ;
52
54
// fire event to click login button
53
55
await act ( ( ) => {
54
56
fireEvent . click ( loginButton2 ) ;
55
57
} ) ;
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
+
60
79
} ) ;
61
80
62
81
test ( 'Register Button navigates to Sign Up Page' , async ( ) => {
0 commit comments