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