|
| 1 | +import React from 'react'; |
| 2 | +import { configure, mount } from 'enzyme'; |
| 3 | +// import { act } from 'react-dom/test-utils'; |
| 4 | +import Adapter from 'enzyme-adapter-react-16'; |
| 5 | +import PerfView from '../components/PerfView'; |
| 6 | +// import { iterator } from 'core-js/fn/symbol'; |
| 7 | + |
| 8 | +// Unit test cases for PerfView |
| 9 | +configure({ adapter: new Adapter() }); |
| 10 | + |
| 11 | +// Test props and basic rendering |
| 12 | +describe('PerfView Component ', () => { |
| 13 | + const snapshot0 = { |
| 14 | + name: 'root', |
| 15 | + state: 'root', |
| 16 | + componentData: {}, |
| 17 | + children: |
| 18 | + [ |
| 19 | + { |
| 20 | + name: 'App', |
| 21 | + state: { num: 0 }, |
| 22 | + componentData: { actualDuration: 10000 }, |
| 23 | + children: |
| 24 | + [ |
| 25 | + { |
| 26 | + name: 'DisplayPanel', state: 'stateless', componentData: { actualDuration: 5000 }, children: [], |
| 27 | + }, |
| 28 | + { |
| 29 | + name: 'AltDisplay', state: 'stateless', componentData: { actualDuration: 4000 }, children: [], |
| 30 | + }, |
| 31 | + { |
| 32 | + name: 'Button Panel', |
| 33 | + state: 'stateless', |
| 34 | + componentData: { actualDuration: 3000 }, |
| 35 | + children: |
| 36 | + [ |
| 37 | + { |
| 38 | + name: 'Button', state: { num: 0 }, componentData: { actualDuration: 2000 }, children: [], |
| 39 | + }, |
| 40 | + { |
| 41 | + name: 'Button', state: { num: 0 }, componentData: { actualDuration: 1000 }, children: [], |
| 42 | + }, |
| 43 | + ], |
| 44 | + }, |
| 45 | + { |
| 46 | + name: 'MarketSContainer', state: 'stateless', componentData: { actualDuration: 500 }, children: [], |
| 47 | + }, |
| 48 | + { |
| 49 | + name: 'MainSlider', state: 'stateless', componentData: { actualDuration: 100 }, children: [], |
| 50 | + }, |
| 51 | + ], |
| 52 | + }, |
| 53 | + ], |
| 54 | + }; |
| 55 | + |
| 56 | + const snapshot1 = { |
| 57 | + name: 'root', |
| 58 | + state: 'root', |
| 59 | + componentData: {}, |
| 60 | + children: |
| 61 | + [ |
| 62 | + { |
| 63 | + name: 'App', |
| 64 | + state: { num: 1 }, |
| 65 | + componentData: { actualDuration: 10 }, |
| 66 | + children: |
| 67 | + [ |
| 68 | + { |
| 69 | + name: 'DisplayPanel', state: 'stateless', componentData: { actualDuration: 50 }, children: [], |
| 70 | + }, |
| 71 | + { |
| 72 | + name: 'AltDisplay', state: 'stateless', componentData: { actualDuration: 40 }, children: [], |
| 73 | + }, |
| 74 | + { |
| 75 | + name: 'Button Panel', |
| 76 | + state: 'stateless', |
| 77 | + componentData: { actualDuration: 30 }, |
| 78 | + children: |
| 79 | + [ |
| 80 | + { |
| 81 | + name: 'Button', state: { num: 2 }, componentData: { actualDuration: 20 }, children: [], |
| 82 | + }, |
| 83 | + { |
| 84 | + name: 'Button', state: { num: 3 }, componentData: { actualDuration: 10 }, children: [], |
| 85 | + }, |
| 86 | + ], |
| 87 | + }, |
| 88 | + { |
| 89 | + name: 'MarketSContainer', state: 'stateless', componentData: { actualDuration: 5 }, children: [], |
| 90 | + }, |
| 91 | + { |
| 92 | + name: 'MainSlider', state: 'stateless', componentData: { actualDuration: 1 }, children: [], |
| 93 | + }, |
| 94 | + ], |
| 95 | + }, |
| 96 | + ], |
| 97 | + }; |
| 98 | + |
| 99 | + let wrapper; |
| 100 | + const snapshots = []; |
| 101 | + snapshots.push(snapshot0); |
| 102 | + snapshots.push(snapshot1); |
| 103 | + |
| 104 | + beforeEach(() => { |
| 105 | + wrapper = mount(<PerfView viewIndex={-1} snapshots={snapshots} width={600} height={600} />); |
| 106 | + }); |
| 107 | + |
| 108 | + it('allows us to set viewIndex prop', () => { |
| 109 | + expect(wrapper.props().viewIndex).toEqual(-1); |
| 110 | + |
| 111 | + wrapper.setProps({ viewIndex: 0 }); |
| 112 | + expect(wrapper.props().viewIndex).toEqual(0); |
| 113 | + |
| 114 | + // wrapper.setProps({ viewIndex: 1000 }); |
| 115 | + }); |
| 116 | + |
| 117 | + it('renders a single svg element', () => { |
| 118 | + expect(wrapper.find('svg')).toHaveLength(1); |
| 119 | + }); |
| 120 | +}); |
0 commit comments