|
| 1 | +import React from 'react'; |
| 2 | +import { shallow, mount } from 'enzyme'; |
| 3 | +import TimeseriesGraph from './index'; |
| 4 | + |
| 5 | +const mockProps = { |
| 6 | + dataSeriesNames: ['name1', 'time', 'name2'], |
| 7 | + data: [[1, 1, 1], [2, 2, 2]], |
| 8 | + graphId: 'GraphId', |
| 9 | + graphName: 'Graph', |
| 10 | + graphOptions: {}, |
| 11 | + xAxisSeries: 'time', |
| 12 | + xAxisTitle: 'xAxix', |
| 13 | + yAxisTitle: 'yAxis', |
| 14 | +}; |
| 15 | + |
| 16 | +const mockDispatch = jest.fn(); |
| 17 | +jest.mock('jschart', () => ({ |
| 18 | + create_jschart: jest.fn(() => { |
| 19 | + return 'true'; |
| 20 | + }), |
| 21 | + chart_reload: jest.fn(() => { |
| 22 | + return 'true'; |
| 23 | + }), |
| 24 | +})); |
| 25 | +const wrapper = shallow(<TimeseriesGraph dispatch={mockDispatch} {...mockProps} />, { |
| 26 | + lifecycleExperimental: true, |
| 27 | +}); |
| 28 | + |
| 29 | +describe('test rendering of TimeseriesGraph page component', () => { |
| 30 | + it('render with empty props', () => { |
| 31 | + expect(wrapper).toMatchSnapshot(); |
| 32 | + }); |
| 33 | + |
| 34 | + it('jschart graph id is same as props', () => { |
| 35 | + expect(wrapper.instance().props.graphId).toBe('GraphId'); |
| 36 | + }); |
| 37 | + |
| 38 | + it('jschart graph division exits', () => { |
| 39 | + expect(wrapper.contains(<div id={mockProps.graphId} />)).toEqual(true); |
| 40 | + }); |
| 41 | +}); |
| 42 | + |
| 43 | +describe('test Creation of graph', () => { |
| 44 | + it('jschart graph is created successfully', () => { |
| 45 | + const division = global.document.createElement('div'); |
| 46 | + division.id = 'GraphId'; |
| 47 | + global.document.body.appendChild(division); |
| 48 | + const container = mount(<TimeseriesGraph {...mockProps} />, { attachTo: division }); |
| 49 | + container.debug(); |
| 50 | + container.detach(); |
| 51 | + }); |
| 52 | +}); |
| 53 | + |
| 54 | +describe('test Creation of graph on update', () => { |
| 55 | + it('component did update with diff data', () => { |
| 56 | + const oldProp = wrapper.instance().props; |
| 57 | + wrapper.setProps({ dataSeriesNames: ['nameA', 'time', 'nameB'], data: [[3, 3, 3], [4, 4, 4]] }); |
| 58 | + const newProp = wrapper.instance().props; |
| 59 | + expect(newProp.data).not.toEqual(oldProp.data); |
| 60 | + }); |
| 61 | + |
| 62 | + it('component did update with same data', () => { |
| 63 | + const oldProp = wrapper.instance().props; |
| 64 | + wrapper.setProps({ dataSeriesNames: ['nameA', 'time', 'nameB'], data: [[3, 3, 3], [4, 4, 4]] }); |
| 65 | + const newProp = wrapper.instance().props; |
| 66 | + expect(newProp.data).toEqual(oldProp.data); |
| 67 | + expect(newProp.dataSeriesNames).toEqual(oldProp.dataSeriesNames); |
| 68 | + }); |
| 69 | +}); |
0 commit comments