Skip to content

Commit 857d803

Browse files
Justinlkirkastholdenwilliamowen65jessllee
committed
Filling out the rest of the chart tests
Co-authored-by: Alexander Holden <[email protected]> Co-authored-by: William Owen <[email protected]> Co-authored-by: Jessica Lee <[email protected]>
1 parent bedc06a commit 857d803

File tree

5 files changed

+63
-31
lines changed

5 files changed

+63
-31
lines changed

__tests__/charts/MemoryChart.test.tsx

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import MemoryChart from '../../app/charts/MemoryChart';
4+
import { HealthContext } from '../../app/context/HealthContext';
5+
import mockData from '../mock_data.json';
6+
import '@testing-library/jest-dom';
7+
8+
jest.mock('electron', () => ({
9+
ipcRenderer: {
10+
send: () => jest.fn(),
11+
on: () => mockData,
12+
},
13+
}));
14+
15+
describe('Speed Chart', () => {
16+
const props = {
17+
healthData: mockData,
18+
setHealthData: jest.fn(),
19+
fetchHealthData: jest.fn(),
20+
parseHealthData: jest.fn(),
21+
services: jest.fn(),
22+
};
23+
beforeEach(() => {
24+
render(
25+
<HealthContext.Provider value={props}>
26+
<MemoryChart sizing="solo" colourGenerator={jest.fn()} />
27+
</HealthContext.Provider>
28+
);
29+
});
30+
31+
it('Should render', () => {
32+
expect(screen).toBeTruthy();
33+
});
34+
35+
it('Should render graph', () => {
36+
expect(screen.getByTestId('Speed Chart').firstChild).toBeTruthy();
37+
});
38+
39+
it('Should render graph', () => {
40+
expect(screen.getByTestId('Speed Chart').firstChild).toBeTruthy();
41+
});
42+
});

__tests__/charts/SpeedChart.test.tsx

+15-18
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ jest.mock('electron', () => ({
1111
on: () => mockData,
1212
},
1313
}));
14-
1514
describe('Speed Chart', () => {
1615
const props = {
1716
healthData: mockData,
@@ -20,39 +19,37 @@ describe('Speed Chart', () => {
2019
parseHealthData: jest.fn(),
2120
services: jest.fn(),
2221
};
22+
let graph;
2323
beforeEach(() => {
2424
render(
2525
<HealthContext.Provider value={props}>
2626
<SpeedChart sizing="solo" colourGenerator={jest.fn()} />
2727
</HealthContext.Provider>
2828
);
29+
graph = screen.getByTestId('Speed Chart').firstChild;
2930
});
3031

3132
it('Should render', () => {
3233
expect(screen).toBeTruthy();
3334
});
3435

3536
it('Should render graph', () => {
36-
expect(screen.getByTestId('Speed Chart').firstChild).toBeTruthy();
37+
expect(graph).toBeTruthy();
3738
});
3839

39-
it('Should render graph', () => {
40-
expect(screen.getByTestId('Speed Chart').firstChild).toBeTruthy();
40+
it('Should be alone', () => {
41+
expect(graph.previousSibling).toBe(null);
42+
expect(graph.nextSibling).toBe(null);
4143
});
4244

43-
/**
44-
* expect 'Speed Chart' to be on screen
45-
*/
46-
47-
// it('Should have three p tags', () => {
48-
// expect(element.querySelectorAll('p').length).toBe(3);
49-
// });
50-
51-
// it('Should have three h3 tags', () => {
52-
// expect(element.querySelectorAll('h3').length).toBe(3);
53-
// });
45+
it('Should not scroll', () => {
46+
expect(graph.scrollWidth).toBe(0);
47+
expect(graph.scrollHeight).toBe(0);
48+
expect(graph.scrollLeft).toBe(0);
49+
expect(graph.scrollTop).toBe(0);
50+
});
5451

55-
// it('Should have one div', () => {
56-
// expect(element.querySelectorAll('div').length).toBe(1);
57-
// });
52+
it('Should render graph', () => {
53+
console.log(graph.outerHTML);
54+
});
5855
});

__tests__/components/CreateAdmin.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ describe('Create Admin Page', () => {
2828
expect(element.querySelectorAll('input').length).toBe(3);
2929
});
3030

31-
xit('Create Account button should submit email, username, and password to addUser', () => {
31+
it('Create Account button should submit email, username, and password to addUser', () => {
3232
const element = screen.getByTestId('CreateAdmin');
3333
const inputs = element.querySelectorAll('input');
3434
inputs[0].value = 'me';
3535
inputs[1].value = '[email protected]';
3636
inputs[2].value = 'me123';
37-
fireEvent.click(screen.getByText('Create Accp[ount'));
37+
fireEvent.click(screen.getByText('Create Account'));
3838
expect(ipcRenderer.sendSync).toHaveBeenCalledWith('addUser', {
3939
4040
username: 'me',

jest_setup/windowMock.js

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
/* istanbul ignore file */
2-
/**
3-
* Mock window environment
4-
*/
1+
// Mock window environment
52
window.require = require;
63

7-
/**
8-
* Mock import statements for Plotly
9-
*/
4+
// Mock import statements for Plotly
105
window.URL.createObjectURL = () => {};
116

12-
/**
13-
* Mock getContext
14-
*/
7+
// Mock get context
158
HTMLCanvasElement.prototype.getContext = () => {};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"electronTest": "cross-env NODE_ENV=development electron .",
1313
"electron:wsl": "electron . --no-sandbox",
1414
"test": "jest",
15-
"test:watch": "jest ./*",
15+
"test:watch": "jest --watch",
1616
"test:electron": "jest --detectOpenHandles ./__tests__/electron/*",
1717
"test:app": "jest ./__tests__/app/*",
1818
"both": "npm run start & sleep 5 && npm run electronTest",

0 commit comments

Comments
 (0)