|
| 1 | +import React from 'react'; |
| 2 | +import { shallow } from 'enzyme'; |
| 3 | +import TableFilterSelection from './index'; |
| 4 | +import Button from '../Button'; |
| 5 | + |
| 6 | +const mockProps = { |
| 7 | + onFilterTable: jest.fn(), |
| 8 | + filters: { |
| 9 | + benchmark_name: ['uperf'], |
| 10 | + benchmark_version: ['1.0.0'], |
| 11 | + instances: [1, 8], |
| 12 | + message_size_bytes: [64, 256, 1024, 8192], |
| 13 | + primary_metric: ['Gb_sec', 'trans_sec'], |
| 14 | + protocol: ['tcp'], |
| 15 | + test_type: ['stream', 'maerts', 'bidirec', 'rr'], |
| 16 | + }, |
| 17 | + ports: ['client_hostname:1', 'client_hostname:2', 'client_hostname:all'], |
| 18 | +}; |
| 19 | + |
| 20 | +const mockDispatch = jest.fn(); |
| 21 | +const wrapper = shallow(<TableFilterSelection dispatch={mockDispatch} {...mockProps} />, { |
| 22 | + lifecycleExperimental: true, |
| 23 | +}); |
| 24 | + |
| 25 | +describe('test rendering of TableFilterSelection page component', () => { |
| 26 | + it('render with empty props', () => { |
| 27 | + expect(wrapper).toMatchSnapshot(); |
| 28 | + }); |
| 29 | + it('check rendering', () => { |
| 30 | + expect(wrapper.find('Select').length).toEqual(8); |
| 31 | + expect(wrapper.find('Form')).toHaveLength(1); |
| 32 | + expect(wrapper.find('Row')).toHaveLength(3); |
| 33 | + expect(wrapper.find('Button')).toHaveLength(2); |
| 34 | + }); |
| 35 | +}); |
| 36 | + |
| 37 | +describe('test interaction of TableFilterSelection page component', () => { |
| 38 | + it('Check click event to call onFilterTable', () => { |
| 39 | + const spy = jest.spyOn(wrapper.instance(), 'onFilterTable'); |
| 40 | + wrapper.instance().forceUpdate(); |
| 41 | + wrapper |
| 42 | + .find(Button) |
| 43 | + .first() |
| 44 | + .props() |
| 45 | + .onClick(); |
| 46 | + expect(spy).toHaveBeenCalledTimes(1); |
| 47 | + }); |
| 48 | + it('Check click event to call onClearFilters', () => { |
| 49 | + const spy = jest.spyOn(wrapper.instance(), 'onClearFilters'); |
| 50 | + wrapper.instance().forceUpdate(); |
| 51 | + wrapper |
| 52 | + .find(Button) |
| 53 | + .last() |
| 54 | + .props() |
| 55 | + .onClick(); |
| 56 | + expect(spy).toHaveBeenCalledTimes(1); |
| 57 | + }); |
| 58 | + it('Check change of Filter', () => { |
| 59 | + const state = []; |
| 60 | + state.benchmark_version = { value: 'abc', category: 'letters' }; |
| 61 | + wrapper |
| 62 | + .find('Select') |
| 63 | + .at(1) |
| 64 | + .simulate('change', { value: 'abc', category: 'letters' }); |
| 65 | + expect(wrapper.state('selectedFilters')).toEqual(state); |
| 66 | + }); |
| 67 | + it('Check change of Filter with null value', () => { |
| 68 | + const state = []; |
| 69 | + wrapper |
| 70 | + .find('Select') |
| 71 | + .at(1) |
| 72 | + .simulate('change'); |
| 73 | + expect(wrapper.state('selectedFilters')).toEqual(state); |
| 74 | + }); |
| 75 | + it('Check change of Port', () => { |
| 76 | + wrapper |
| 77 | + .find('Select') |
| 78 | + .last() |
| 79 | + .simulate('change', 'client_hostname:3'); |
| 80 | + expect(wrapper.state('selectedPorts')).toEqual('client_hostname:3'); |
| 81 | + }); |
| 82 | +}); |
| 83 | + |
| 84 | +describe('test life cycle method update', () => { |
| 85 | + it('should call filterDefaultPort when componentDidUpdate method is invoked', () => { |
| 86 | + const spy = jest.spyOn(wrapper.instance(), 'filterDefaultPort'); |
| 87 | + wrapper.instance().forceUpdate(); |
| 88 | + wrapper.setProps({ ports: ['client_hostname:3'] }); |
| 89 | + expect(spy).toHaveBeenCalledTimes(1); |
| 90 | + }); |
| 91 | +}); |
0 commit comments