Skip to content

Commit a110ee8

Browse files
Merge pull request #32 from oslabs-beta/Eshaan
Pull request to update testing files
2 parents c41b51d + ba434b2 commit a110ee8

File tree

5 files changed

+53
-27
lines changed

5 files changed

+53
-27
lines changed

__tests__/ImageTab.test.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import * as helper from '../src/components/helper/commands';
23
import { describe, beforeEach, expect, test, jest } from '@jest/globals';
34
import Images from '../src/components/tabs/Images';
45
import {
@@ -57,14 +58,15 @@ describe('Images', () => {
5758
});
5859

5960
// currently gets stuck at window.runExec method --> reads undefined
60-
// describe('pull button on click', () => {
61-
// test('fires pull button functionality', () => {
62-
// const { container } = render(<Images {...props} />);
63-
// const pullButton = screen.getByRole('button', { name: 'Pull' });
64-
// fireEvent.click(pullButton);
65-
// expect(pullButton).toBeCalled;
66-
// });
67-
// });
61+
describe('pull button on click', () => {
62+
test('fires pull button functionality', () => {
63+
// const { container } = render(<Images {...props} />);
64+
const pullButton = screen.getByRole('button', { name: 'PULL' });
65+
fireEvent.click(pullButton);
66+
expect(pullButton).toBeCalled;
67+
expect(Images.handleClick).toBeCalled;
68+
});
69+
});
6870

6971
describe('Images', () => {
7072
test('Renders an image if one is found', () => {

__tests__/ProcessLogHelper.test.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@ import {
99
import {describe, beforeEach,afterEach, expect, test} from '@jest/globals';
1010

1111
describe('makeArrayOfObjects', () => {
12-
test('returns an array', () => {
13-
const string = `HelloZ from Docker!
14-
15-
This message shows that your installation appears to be working correctly.
16-
12+
test('returns a result array with appropriately constructed object elements', () => {
13+
const string2 = `2022-12-22T19:36:44.564948926Z 2022/12/22 19:36:44 [notice] 1#1: start worker process 22\n2022-12-22T20:12:01.081323805Z 2022/12/22 20:12:01 [notice] 22#22: gracefully shutting down
1714
`;
18-
const result = makeArrayOfObjects(string);
15+
16+
const result = makeArrayOfObjects(string2);
17+
console.log(result);
1918
expect(result).toBeInstanceOf(Array);
2019
expect(result.length).toEqual(2);
2120
expect(result.containerName).toBe(undefined);
22-
expect(result[0].logMsg).toEqual('HelloZ from Docker!');
23-
expect(result[0].timeStamp).toBeUndefined();
21+
expect(result[0].logMsg).toEqual('1#1: start worker process 22');
22+
expect(result[0].timeStamp).toBe('12/22/2022, 1:36:44 PM');
23+
expect(result[1].logMsg).toEqual('22#22: gracefully shutting down');
24+
expect(result[1].timeStamp).toBe('12/22/2022, 2:12:01 PM');
2425
});
2526

2627
// Can be addressed through TS

__tests__/loginPage.test.js

Lines changed: 31 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,39 @@ 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).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');
5677
});
5778

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

src/components/Login.tsx

Lines changed: 2 additions & 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={{
@@ -117,6 +118,7 @@ const Login = () => {
117118
<Button
118119
variant='contained'
119120
size='small'
121+
role='register'
120122
className='register login-buttons'
121123
onClick={() => navigate('/userSignup')}
122124
sx={{

src/components/tabs/Images.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ const Images = (props: ImagesProps) => {
126126
setRepo(e.target.value);
127127
}}
128128
></input>
129-
<button className="etc-btn" onClick={() => handleClick()}>
129+
<button className="etc-btn" name='pull' onClick={() => handleClick()}>
130130
PULL
131131
</button>
132132
</span>

0 commit comments

Comments
 (0)