Skip to content

Commit 20b7d8d

Browse files
Merge branch 'additionalTests' of https://github.com/gregpalace/Chronos into staging-master
2 parents 182a411 + d071833 commit 20b7d8d

7 files changed

Lines changed: 244 additions & 8 deletions

File tree

__tests__/app/App.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import ReactDOM from 'react-dom';
23
import { shallow, mount } from 'enzyme';
34
import App from '../../app/App';
45
describe('<App />', () => {
@@ -10,6 +11,11 @@ describe('<App />', () => {
1011
it('should render <Splash /> on the first visit', () => {
1112
expect(wrapper).toBeDefined();
1213
});
14+
it('renders without crashing', () => {
15+
const div = document.createElement('div');
16+
ReactDOM.render(<App />, div);
17+
ReactDOM.unmountComponentAtNode(div);
18+
});
1319
it('should render <DashboardContainer /> if not on the first visit', () => {
1420
jest.useFakeTimers();
1521
wrapper = mount(<App />);
Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,83 @@
1-
xdescribe('<DockerChart />', () => {
2-
it('should');
1+
import React, { useState, useContext } from 'react';
2+
import { mount, shallow } from 'enzyme';
3+
const { ipcRenderer } = require('electron');
4+
5+
import DockerContextProvider, { DockerContext } from '../../../app/context/DockerContext';
6+
7+
// Setup electron mock
8+
jest.mock('electron', () => ({ ipcRenderer: { on: jest.fn(), send: jest.fn() } }));
9+
10+
describe('React unit tests', () => {
11+
describe('<DockerChart />', () => {
12+
let wrapper: any;
13+
let shallow: any;
14+
15+
beforeEach(() => {
16+
const TestComponent = () => {
17+
const { dockerData } = useContext(DockerContext);
18+
const [mockData, setMockData] = useState([
19+
{
20+
containerid: 'f57f5815cb0',
21+
containername: 'chronos-mon-2',
22+
cpupercent: 0.3,
23+
memorylimit: 16665812992,
24+
memorypercent: 0.3,
25+
memoryusage: 48480256,
26+
networkreceived: 6562749,
27+
networksent: 0,
28+
platform: 'Linux',
29+
processcount: 35,
30+
restartcount: 0,
31+
starttime: 'Thu Jul 02 2020 16:18:50 GMT-0700 ',
32+
id: '5efe95ded17eaf0020a80c80',
33+
},
34+
]);
35+
const dataPoint = mockData[0];
36+
return (
37+
<>
38+
<div id="docker-stats-chart">
39+
<header id="docker-stats-chart-header">Docker Container Stats</header>
40+
<span>Container Name: {dataPoint.containername}</span>
41+
<span>Container ID: {dataPoint.containerid}</span>
42+
<span>Platform: {dataPoint.platform}</span>
43+
<span>Start time: {dataPoint.starttime}</span>
44+
<span>Memory Usage: {(dataPoint.memoryusage / 1000000).toFixed(2)}</span>
45+
<span>Memory Limit: {(dataPoint.memorylimit / 1000000).toFixed(2)}</span>
46+
<span>Memory Percent: {dataPoint.memorypercent.toFixed(2)}%</span>
47+
<span>CPU percent: {dataPoint.cpupercent.toFixed(2)}%</span>
48+
<span>Network I/O - Received (Kb): {dataPoint.networkreceived / 1000}</span>
49+
<span>Network I/O - Sent (Kb): {dataPoint.networksent / 1000}</span>
50+
<span>Process Count: {dataPoint.processcount}</span>
51+
<span>Restart Count: {dataPoint.restartcount}</span>
52+
</div>
53+
</>
54+
);
55+
};
56+
wrapper = mount(
57+
<DockerContextProvider>
58+
<TestComponent />
59+
</DockerContextProvider>
60+
);
61+
});
62+
63+
it('should render', () => {
64+
expect(wrapper).toMatchSnapshot();
65+
});
66+
67+
it('should display all tags with docker information', () => {
68+
expect(wrapper.find('span')).toHaveLength(12);
69+
});
70+
71+
it('should display <header> tag with docker stats', () => {
72+
expect(wrapper.find('header').text()).toEqual('Docker Container Stats');
73+
});
74+
75+
it('should display container name, id, platform, and memory usage', () => {
76+
expect(wrapper.find('div').find('span').at(0).text()).toContain('chronos-mon-2');
77+
expect(wrapper.find('div').find('span').at(1).text()).toContain('f57f5815cb0');
78+
expect(wrapper.find('div').find('span').at(2).text()).toContain('Linux');
79+
expect(wrapper.find('div').find('span').at(4).text()).toContain('48.48');
80+
expect(wrapper.find('div').find('span').at(5).text()).toContain('16665.81');
81+
});
82+
});
383
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
describe('tests for latency chart', () => {
2+
xit('should render plot with latency values', () => {});
3+
});
Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,73 @@
1-
xdescribe('<CommsContext />', () => {
2-
xit('should');
1+
import React, { useContext, useState } from 'react';
2+
import { mount, shallow } from 'enzyme';
3+
const { ipcRenderer } = require('electron');
4+
5+
import CommsContextProvider, { CommsContext } from '../../../app/context/CommsContext';
6+
7+
// Setup electron mock
8+
jest.mock('electron', () => ({ ipcRenderer: { on: jest.fn(), send: jest.fn() } }));
9+
10+
describe('React unit tests', () => {
11+
describe('<CommsContext />', () => {
12+
let wrapper: any;
13+
let shallow: any;
14+
15+
beforeEach(() => {
16+
const TestComponent = () => {
17+
const { commsData, setCommsData, fetchCommsData } = useContext(CommsContext);
18+
const [mockData, setMockData] = useState([
19+
{
20+
correlatingid: '7bdad8c0',
21+
endpoint: '/customers/createcustomer',
22+
microservice: 'customers',
23+
request: 'GET',
24+
responsemessage: 'OK',
25+
responsestatus: 200,
26+
time: '2020-06-27T05:30:43.567Z',
27+
id: 36,
28+
},
29+
]);
30+
return (
31+
<>
32+
<div id="commsData">{JSON.stringify(commsData)}</div>
33+
<div id="parsedData">{JSON.stringify(mockData)}</div>
34+
<button id="fetchCommsData" onClick={() => fetchCommsData('customers')}>
35+
Test fetchCommsData
36+
</button>
37+
<button id="setCommsData" onClick={() => setCommsData({ foo: 'bar' })}>
38+
Test setCommsData
39+
</button>
40+
</>
41+
);
42+
};
43+
wrapper = mount(
44+
<CommsContextProvider>
45+
<TestComponent />
46+
</CommsContextProvider>
47+
);
48+
});
49+
50+
it('should render correctly', () => {
51+
expect(wrapper).toMatchSnapshot();
52+
});
53+
54+
it("should emit the 'commsRequest' event and listen on 'commsResponse' when invoking fetchCommsData", () => {
55+
const button = wrapper.find('#fetchCommsData');
56+
button.simulate('click');
57+
expect(ipcRenderer.send).toHaveBeenCalledWith('commsRequest', 'customers');
58+
expect(ipcRenderer.on).toHaveBeenCalledWith('commsResponse', expect.any(Function));
59+
});
60+
61+
it('should update dockerData when setCommsData is invoked with new data', () => {
62+
const button = wrapper.find('#setCommsData');
63+
button.simulate('click');
64+
expect(wrapper.find('#commsData').text()).toEqual(JSON.stringify({ foo: 'bar' }));
65+
});
66+
67+
it('should display status code information', () => {
68+
console.log(wrapper.debug());
69+
expect(wrapper.find('#parsedData').text()).toMatch('GET');
70+
expect(wrapper.find('#parsedData').text()).toMatch('OK');
71+
});
72+
});
373
});
Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,82 @@
1-
xdescribe('<DockerContext />', () => {
2-
xit('should');
1+
import React, { useContext, useState } from 'react';
2+
import { mount, shallow } from 'enzyme';
3+
const { ipcRenderer } = require('electron');
4+
5+
import DockerContextProvider, { DockerContext } from '../../../app/context/DockerContext';
6+
7+
// Setup electron mock
8+
jest.mock('electron', () => ({ ipcRenderer: { on: jest.fn(), send: jest.fn() } }));
9+
10+
describe('React unit tests', () => {
11+
describe('<DockerContext />', () => {
12+
let wrapper: any;
13+
let shallow: any;
14+
15+
beforeEach(() => {
16+
const TestComponent = () => {
17+
const { dockerData, setDockerData, fetchDockerData } = useContext(DockerContext);
18+
const [mockData, setMockData] = useState([
19+
{
20+
containerid: 'f57f5815cb0',
21+
containername: 'chronos-mon-2',
22+
cpupercent: 0.3,
23+
memorylimit: 16665812992,
24+
memorypercent: 0.3,
25+
memoryusage: 48480256,
26+
networkreceived: 6562749,
27+
networksent: 0,
28+
platform: 'Linux',
29+
processcount: 35,
30+
restartcount: 0,
31+
starttime: 'Thu Jul 02 2020 16:18:50 GMT-0700 ',
32+
id: '5efe95ded17eaf0020a80c80',
33+
},
34+
]);
35+
return (
36+
<>
37+
<div id="dockerData">{JSON.stringify(dockerData)}</div>
38+
<div id="parsedData">{JSON.stringify(mockData)}</div>
39+
<button id="fetchDockerData" onClick={() => fetchDockerData('chronos-mon-3')}>
40+
Test fetchDockerData
41+
</button>
42+
<button id="setDockerData" onClick={() => setDockerData({ foo: 'bar' })}>
43+
Test setDockerData
44+
</button>
45+
</>
46+
);
47+
};
48+
wrapper = mount(
49+
<DockerContextProvider>
50+
<TestComponent />
51+
</DockerContextProvider>
52+
);
53+
});
54+
55+
it('should render', () => {
56+
expect(wrapper).toMatchSnapshot();
57+
});
58+
59+
it('should display a given container name', () => {
60+
const containerName = wrapper.find('#parsedData');
61+
expect(containerName.text()).toMatch('chronos-mon-2');
62+
});
63+
64+
it("should emit the 'dockerRequest' event and listen on 'dockerResponse' when invoking fetchDockerData", () => {
65+
const button = wrapper.find('#fetchDockerData');
66+
button.simulate('click');
67+
expect(ipcRenderer.send).toHaveBeenCalledWith('dockerRequest', 'chronos-mon-3');
68+
expect(ipcRenderer.on).toHaveBeenCalledWith('dockerResponse', expect.any(Function));
69+
});
70+
71+
it('should update dockerData when setDockerData is invoked with new data', () => {
72+
const button = wrapper.find('#setDockerData');
73+
button.simulate('click');
74+
expect(wrapper.find('#dockerData').text()).toEqual(JSON.stringify({ foo: 'bar' }));
75+
});
76+
77+
it('should note which platform is being used', () => {
78+
const parsedData = wrapper.find('#parsedData');
79+
expect(parsedData.text()).toMatch('Linux');
80+
});
81+
});
382
});

app/context/DockerContext.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const DockerContextProvider: React.FC = ({ children }) => {
3232
// Parse result
3333
const result: IContainer[] = JSON.parse(data);
3434
console.log('Number of data points (docker):', result.length);
35-
3635
// Display single data point
3736
const newDockerData = result[0] || {};
3837
setDockerData(newDockerData);

app/context/HealthContext.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ const HealthContextProvider: React.FC = ({ children }) => {
4545
// Parse result
4646
const result = JSON.parse(data);
4747
console.log('Number of data points (health):', result.length);
48-
4948
// Update context local state
5049
setHealthData(parseHealthData(result));
5150
});

0 commit comments

Comments
 (0)