|
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 | + }); |
3 | 83 | }); |
0 commit comments