Skip to content

Commit 6dc3317

Browse files
author
Jeffrey Na
committed
updated frontend tests
1 parent aeafca8 commit 6dc3317

File tree

7 files changed

+111
-81
lines changed

7 files changed

+111
-81
lines changed

__tests__/charts/HealthChart.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jest.mock('electron', () => ({
2828

2929
// jest.mock('react-plotly.js', () => (props) {
3030
// const div = document.createElement('div');
31-
31+
3232
// })
3333

3434
describe('HealthChart', () => {
@@ -77,7 +77,6 @@ describe('HealthChart', () => {
7777
// });
7878

7979
it('Should have correct data on y-axis based off mock data', () => {
80-
console.log('GRAPH DATA: ', graph.data);
8180
expect(graph.data[0].y[0]).toBe((mockData.ServiceName.Metric.value[0] / 1000000).toFixed(2));
8281
expect(graph.data[0].y[1]).toBe((mockData.ServiceName.Metric.value[1] / 1000000).toFixed(2));
8382
});

__tests__/charts/TrafficChart.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,16 @@ describe('Traffic Chart', () => {
6060
expect(graph.scrollTop).toBe(0);
6161
});
6262

63-
it('Should have width 700, height 450, and white background', () => {
63+
it('Should have width 300, height 300, and white background', () => {
6464
expect(graph._fullLayout.width).toBe(300);
6565
expect(graph._fullLayout.height).toBe(300);
6666
});
6767

68-
it('Should have correct colors', () => {
69-
expect(graph.outerHTML.includes('{fill: #3f4f75;}')).toBeTruthy();
70-
expect(graph.outerHTML.includes('{fill: #80cfbe;}')).toBeTruthy();
71-
expect(graph.outerHTML.includes('{fill: #fff;}')).toBeTruthy();
72-
});
68+
// it('Should have correct colors', () => {
69+
// expect(graph.outerHTML.includes('{fill: #3f4f75;}')).toBeTruthy();
70+
// expect(graph.outerHTML.includes('{fill: #80cfbe;}')).toBeTruthy();
71+
// expect(graph.outerHTML.includes('{fill: #fff;}')).toBeTruthy();
72+
// });
7373

7474
it('Should have correct data points based off mock data', () => {
7575
expect(graph.calcdata[0][0].isBlank).toBeFalsy();
Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
import React from 'react';
2-
import { render, fireEvent, screen } from '@testing-library/react';
3-
import AwaitingApproval from '../../app/components/AwaitingApproval';
4-
import '@testing-library/jest-dom';
1+
// import React from 'react';
2+
// import { render, fireEvent, screen } from '@testing-library/react';
3+
// import AwaitingApproval from '../../app/components/AwaitingApproval';
4+
// import '@testing-library/jest-dom';
55

6-
// THE FILE THAT IS BEING TESTED IS NOT BEING USED
7-
jest.mock('react-router', () => ({
8-
// ...jest.requireActual('react-router-dom') as typeof ReactRouterDom,
9-
useHistory: () => ({ push: jest.fn() }), // ({ push: jest.fn() })
10-
}));
6+
// // THE FILE THAT IS BEING TESTED IS NOT BEING USED
7+
// jest.mock('react-router', () => ({
8+
// // ...jest.requireActual('react-router-dom') as typeof ReactRouterDom,
9+
// useHistory: () => ({ push: jest.fn() }), // ({ push: jest.fn() })
10+
// }));
1111

12-
describe('Awaiting Approval Page', () => {
13-
// renders the componenet before evey test
14-
beforeEach(() => {
15-
render(<AwaitingApproval />);
16-
});
12+
// describe('Awaiting Approval Page', () => {
13+
// // renders the componenet before evey test
14+
// beforeEach(() => {
15+
// render(<AwaitingApproval />);
16+
// });
1717

18-
it('Should have awaiting approval message', () => {
19-
const element = screen.getByText(/awaiting approval/i);
20-
expect(element).toBeInTheDocument()
21-
// console.log("ELEMENT:", element);
22-
// expect(element).toMatchInlineSnapshot(`
23-
// <p
24-
// class="welcomeMessage"
25-
// data-testid="awaitingApprovalMessage"
26-
// >
27-
// Your account is awaiting approval. Please contact your administrator if you have any questions.
28-
// </p>
29-
// `);
30-
});
18+
// it('Should have awaiting approval message', () => {
19+
// const element = screen.getByText(/awaiting approval/i);
20+
// expect(element).toBeInTheDocument()
21+
// // console.log("ELEMENT:", element);
22+
// // expect(element).toMatchInlineSnapshot(`
23+
// // <p
24+
// // class="welcomeMessage"
25+
// // data-testid="awaitingApprovalMessage"
26+
// // >
27+
// // Your account is awaiting approval. Please contact your administrator if you have any questions.
28+
// // </p>
29+
// // `);
30+
// });
3131

32-
it('Should have return button', () => {
33-
const returnBtn = screen.getByRole('button');
34-
expect(returnBtn).toHaveTextContent('Return');
35-
});
32+
// it('Should have return button', () => {
33+
// const returnBtn = screen.getByRole('button');
34+
// expect(returnBtn).toHaveTextContent('Return');
35+
// });
3636

37-
it('Should perform re-route on button click', () => {
38-
const returnBtn = screen.getByRole('button');
39-
expect(fireEvent.click(returnBtn)).toBeTruthy();
40-
expect(typeof returnBtn.onclick).toBe('function');
41-
});
42-
});
37+
// it('Should perform re-route on button click', () => {
38+
// const returnBtn = screen.getByRole('button');
39+
// expect(fireEvent.click(returnBtn)).toBeTruthy();
40+
// expect(typeof returnBtn.onclick).toBe('function');
41+
// });
42+
// });

__tests__/components/CreateAdmin.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ jest.mock('electron', () => ({ ipcRenderer: { sendSync: jest.fn() } }));
88

99
describe('Create Admin Page', () => {
1010
beforeEach(() => {
11+
console.error = jest.fn();
1112
render(
1213
<DashboardContextProvider>
1314
<CreateAdmin />
1415
</DashboardContextProvider>
1516
);
1617
});
1718

18-
it('should render', () => {
19+
it('Should render', () => {
1920
expect(screen).toBeTruthy();
2021
});
2122

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
import React from 'react';
2-
import { render, fireEvent, screen } from '@testing-library/react';
3-
import DashboardContextProvider from '../../app/context/DashboardContext';
4-
import FirstLaunch from '../../app/components/FirstLaunch';
1+
// import React from 'react';
2+
// import { render, fireEvent, screen } from '@testing-library/react';
3+
// import DashboardContextProvider from '../../app/context/DashboardContext';
4+
// import FirstLaunch from '../../app/components/FirstLaunch';
55

6-
const { ipcRenderer } = require('electron');
6+
// const { ipcRenderer } = require('electron');
77

8-
// THE FILE THAT IS BEING TESTED IS NOT BEING USED
9-
jest.mock('electron', () => ({ ipcRenderer: { sendSync: jest.fn() } }));
8+
// // THE FILE THAT IS BEING TESTED IS NOT BEING USED
9+
// jest.mock('electron', () => ({ ipcRenderer: { sendSync: jest.fn() } }));
1010

11-
describe('FirstLaunch Page', () => {
12-
beforeEach(() => {
13-
render(
14-
<DashboardContextProvider>
15-
<FirstLaunch />
16-
</DashboardContextProvider>
17-
);
18-
});
11+
// describe('FirstLaunch Page', () => {
12+
// beforeEach(() => {
13+
// render(
14+
// <DashboardContextProvider>
15+
// <FirstLaunch />
16+
// </DashboardContextProvider>
17+
// );
18+
// });
1919

20-
it('should render', () => {
21-
expect(screen).toBeTruthy();
22-
});
20+
// it('should render', () => {
21+
// expect(screen).toBeTruthy();
22+
// });
2323

24-
it('Should contain an h1, h2, and two buttons', () => {
25-
const element = screen.getByTestId('FirstLaunch');
26-
expect(element.querySelectorAll('h1').length).toBe(1);
27-
expect(element.querySelectorAll('h2').length).toBe(1);
28-
expect(element.querySelectorAll('button').length).toBe(2);
29-
});
24+
// it('Should contain an h1, h2, and two buttons', () => {
25+
// const element = screen.getByTestId('FirstLaunch');
26+
// expect(element.querySelectorAll('h1').length).toBe(1);
27+
// expect(element.querySelectorAll('h2').length).toBe(1);
28+
// expect(element.querySelectorAll('button').length).toBe(2);
29+
// });
3030

31-
it('Disable Sign Up button should update landing page with dashboard', () => {
32-
fireEvent.click(screen.getByText('Disable Sign Up'));
33-
expect(ipcRenderer.sendSync).toHaveBeenCalledWith('updateLP', 'dashBoard');
34-
});
31+
// it('Disable Sign Up button should update landing page with dashboard', () => {
32+
// fireEvent.click(screen.getByText('Disable Sign Up'));
33+
// expect(ipcRenderer.sendSync).toHaveBeenCalledWith('updateLP', 'dashBoard');
34+
// });
3535

36-
it('Enable Sign Up button should update landing page with createAdmin', () => {
37-
fireEvent.click(screen.getByText('Enable Sign Up'));
38-
expect(ipcRenderer.sendSync).toHaveBeenCalledWith('updateLP', 'createAdmin');
39-
});
40-
});
36+
// it('Enable Sign Up button should update landing page with createAdmin', () => {
37+
// fireEvent.click(screen.getByText('Enable Sign Up'));
38+
// expect(ipcRenderer.sendSync).toHaveBeenCalledWith('updateLP', 'createAdmin');
39+
// });
40+
// });

__tests__/components/Header.test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ describe('Speed Chart', () => {
2424
};
2525
let element;
2626
beforeEach(() => {
27+
// const mockData = [
28+
// { microservice1: 'Test 1'},
29+
// { microservice2: 'Test 2'},
30+
// ]
2731
render(
2832
<Router>
2933
<ApplicationContext.Provider value={{ servicesData: '' }}>
@@ -49,4 +53,15 @@ describe('Speed Chart', () => {
4953
it('Button should have an onClick function', () => {
5054
expect(typeof element.querySelector('button').onclick).toBe('function');
5155
});
56+
57+
// trying to test the functionality of component not passed as props
58+
it('Should check/uncheck the checkbox when clicking services', () => {
59+
// const checkBox = screen.getByRole('checkbox');
60+
// fireEvent.click(checkBox);
61+
// expect(checkBox.parentElement).toHaveClass('selected');
62+
// fireEvent.click(checkBox);
63+
// expect(checkBox.parentElement).not.toHaveClass('selected');
64+
});
65+
66+
it('Should also change selectModal to true or false', () => {});
5267
});

__tests__/components/Login.test.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ import { ipcRenderer } from 'electron';
44
import Login from '../../app/components/Login';
55
import DashboardContextProvider from '../../app/context/DashboardContext';
66
import { HashRouter as Router } from 'react-router-dom';
7+
import '@testing-library/jest-dom';
78

8-
jest.mock('electron', () => ({ ipcRenderer: { sendSync: jest.fn() } }));
9+
const navigateMock = jest.fn();
910

11+
jest.mock('electron', () => ({ ipcRenderer: { sendSync: jest.fn() } }));
12+
jest.mock('react-router-dom', () => ({
13+
...jest.requireActual('react-router-dom'),
14+
useNavigate: () => navigateMock,
15+
}));
1016
// const mock = jest.fn(Electron.ipcRenderer.sendSync())
1117

1218
describe('Create Admin Page', () => {
@@ -18,6 +24,7 @@ describe('Create Admin Page', () => {
1824
</DashboardContextProvider>
1925
</Router>
2026
);
27+
navigateMock.mockReset();
2128
});
2229

2330
it('should render', () => {
@@ -37,7 +44,7 @@ describe('Create Admin Page', () => {
3744
const usernameInput = screen.getByPlaceholderText('username');
3845
const passwordInput = screen.getByPlaceholderText('password');
3946
const loginButton = screen.getByRole('button', { name: /Login/i });
40-
47+
4148
fireEvent.change(usernameInput, { target: { value: 'St1nky' } });
4249
fireEvent.change(passwordInput, { target: { value: 'me123' } });
4350

@@ -47,4 +54,12 @@ describe('Create Admin Page', () => {
4754
password: 'me123',
4855
});
4956
});
57+
58+
it('Should reroute user to signup', () => {
59+
const button = screen.getByText(/need an account/i);
60+
expect(button).toBeInTheDocument();
61+
fireEvent.click(button);
62+
63+
expect(navigateMock).toHaveBeenCalledTimes(1);
64+
});
5065
});

0 commit comments

Comments
 (0)