Skip to content

Commit 892486a

Browse files
committed
added script for backend, working frontend and backend tests, currently ignoring mongo.test.js and healthchart.test
1 parent 0a9b648 commit 892486a

File tree

9 files changed

+91
-77
lines changed

9 files changed

+91
-77
lines changed

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
"endOfLine": "auto",
55
"arrowParens": "avoid",
66
"printWidth": 100
7-
}
7+
}

__backend-tests__/jest.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ module.exports = {
2020
// Code coverage settings
2121
collectCoverage: true,
2222
coverageDirectory: 'coverage',
23-
// Specify the test path patterns to ignore (frontend tests)
24-
testPathIgnorePatterns: ['/node_modules/', '/__tests__/'],
23+
// Specify the test path files/patterns to ignore
24+
testPathIgnorePatterns: ['/node_modules/', '/__tests__/', '/__backend-tests__/mongo.test.js'],
2525
};

__backend-tests__/mongo.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//Issues with mongo memory server causing timeout for each test. Change file type from .txt to .js to run
2+
3+
14
const mongoose = require('mongoose');
25
const mongo = require('../chronos_npm_package/controllers/mongo');
36
const ServicesModel = require('../chronos_npm_package/models/ServicesModel');

__tests__/charts/HealthChart.test.tsx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//BELOW test cases are only for instances of REACT Plotly, which is currently on microservices, gRPC and AWS. Change file from .txt to .tsx to run test
2+
3+
import React from 'react';
4+
import HealthChart from '../../app/charts/HealthChart';
5+
import { render, screen } from '@testing-library/react';
6+
7+
// mockData used for testing suite
8+
const mockData = {
9+
ServiceName: {
10+
Metric: {
11+
time: [
12+
'2023-06-09T15:18:25.195Z',
13+
'2023-06-09T15:18:20.194Z',
14+
'2023-06-09T15:18:15.192Z',
15+
'2023-06-09T15:18:10.191Z',
16+
'2023-06-09T15:18:05.190Z',
17+
],
18+
value: [1208074240, 1282670592, 1243414528, 1278115840, 117178368],
19+
},
20+
},
21+
};
22+
23+
jest.mock('electron', () => ({
24+
ipcRenderer: {
25+
send: () => jest.fn(),
26+
on: () => mockData,
27+
},
28+
}));
29+
30+
// test suite for HealthChart.tsx
31+
describe('HealthChart', () => {
32+
const props = {
33+
key: 'testKey',
34+
dataType: 'Memory in Megabytes',
35+
serviceName: 'serviceName',
36+
chartData: mockData,
37+
categoryName: 'Test Name',
38+
sizing: 'all',
39+
colourGenerator: jest.fn(),
40+
};
41+
42+
let graph;
43+
beforeEach(() => {
44+
render(<HealthChart {...props} />);
45+
46+
graph = screen.getByTestId('Health Chart').firstChild;
47+
});
48+
49+
it('Should render', () => {
50+
expect(screen).toBeTruthy();
51+
});
52+
53+
it('Should render graph', () => {
54+
expect(graph).toBeTruthy();
55+
});
56+
57+
it('Should not scroll', () => {
58+
expect(graph.scrollWidth).toBe(0);
59+
expect(graph.scrollHeight).toBe(0);
60+
expect(graph.scrollLeft).toBe(0);
61+
expect(graph.scrollTop).toBe(0);
62+
});
63+
64+
it('Should have correct data on y-axis based off mock data', () => {
65+
expect(graph.data[0].y[0]).toBe((mockData.ServiceName.Metric.value[0] / 1000000).toFixed(2));
66+
expect(graph.data[0].y[1]).toBe((mockData.ServiceName.Metric.value[1] / 1000000).toFixed(2));
67+
});
68+
});

__tests__/charts/HealthChart.test.txt

Lines changed: 0 additions & 68 deletions
This file was deleted.

jest.config.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
import type { Config } from '@jest/types';
22

3-
43
// describes the jest testing configuration for all test files
54
const config: Config.InitialOptions = {
65
verbose: true,
76
setupFilesAfterEnv: ['./jest_setup/windowMock.js'],
8-
testEnvironment: "jsdom",
7+
testEnvironment: 'jsdom',
98
preset: 'ts-jest/presets/js-with-ts',
10-
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
9+
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
1110
moduleNameMapper: {
1211
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
1312
'<rootDir>/jest_setup/fileMock.js',
1413
'\\.(css|less|scss)$': '<rootDir>/jest_setup/styleMock.js',
1514
},
16-
// collectCoverage: true,
15+
//add
16+
testPathIgnorePatterns: [
17+
'/node_modules/',
18+
'/__tests__/charts/HealthChart.test.tsx',
19+
'/__backend-tests__',
20+
],
21+
// Specify the test path files/patterns to ignore
1722
};
1823

1924
export default config;

package-lock.json

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"dev:electron": "tsc && cross-env NODE_ENV=development electron .",
8686
"package": "electron-packager ./dist chronos --overwrite --prune=true --out=release-builds",
8787
"test": "nyc jest",
88+
"backend-test": "npx jest --config __backend-tests__/jest.config.js --verbose",
8889
"start:selenium": "node e2e/seleniumTest.js",
8990
"start:e2e": "nyc npm run dev:electron & npm run start:selenium"
9091
},

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424
"node_modules",
2525
"dist"
2626
],
27-
"include": ["./electron/**/*", "./electron/**/*.json", "jest.config.ts", "./settings.json"]
27+
"include": ["./electron/**/*", "./electron/**/*.json", "__tests__/jest.config.ts", "./settings.json"]
2828
}

0 commit comments

Comments
 (0)