|
| 1 | +import React from 'react'; |
| 2 | +import { configure, shallow } from 'enzyme'; |
| 3 | +import Adapter from 'enzyme-adapter-react-16'; |
| 4 | +import { diff, formatters } from 'jsondiffpatch'; |
| 5 | +import ReactHtmlParser from 'react-html-parser'; |
| 6 | +import Diff from '../components/Diff.jsx'; |
| 7 | + |
| 8 | +import { useStoreContext } from '../store'; |
| 9 | + |
| 10 | +configure({ adapter: new Adapter() }); |
| 11 | + |
| 12 | +jest.mock('../store'); |
| 13 | + |
| 14 | +describe('Unit testing for Diff.jsx', () => { |
| 15 | + let wrapper; |
| 16 | + // const props = { |
| 17 | + // show: false, |
| 18 | + // snapshot: [{ |
| 19 | + // children: [{ |
| 20 | + // state: { total: 12, next: 5, operation: null }, |
| 21 | + // }], |
| 22 | + |
| 23 | + // }], |
| 24 | + // } |
| 25 | + |
| 26 | + const state = { |
| 27 | + currentTab: 100, |
| 28 | + tabs: { 100: { snapshots: [1, 2 ,3 ,4 ], viewIndex: 1, sliderIndex: 1 } }, |
| 29 | + }; |
| 30 | + |
| 31 | + const currentTab = state.tabs[state.currentTab]; |
| 32 | + |
| 33 | + jest.mock('../store'); |
| 34 | + useStoreContext.mockImplementation(() => [state]); |
| 35 | + |
| 36 | + const delta = { children: {} }; // expect delta to be an obj |
| 37 | + const html = 'html'; // expect html to be a string |
| 38 | + const previous = { state: 'string', children: {} }; // expect previous to be an obj |
| 39 | + |
| 40 | + beforeEach(() => { |
| 41 | + wrapper = shallow(<Diff />); |
| 42 | + useStoreContext.mockClear(); |
| 43 | + // console.log('Diff component wrapper', wrapper); |
| 44 | + }); |
| 45 | + |
| 46 | + |
| 47 | + // // const state = { |
| 48 | + // // currentTab: 1, |
| 49 | + // // tabs: [], |
| 50 | + // // }; |
| 51 | + |
| 52 | + // const delta = { children: {} }; // expect delta to be an obj |
| 53 | + // const html = 'html'; // expect html to be a string |
| 54 | + // const previous = { state: 'string', children: {} }; // expect previous to be an obj |
| 55 | + |
| 56 | + // beforeEach(() => { |
| 57 | + // wrapper = shallow(<Diff snapshot={props.snapshot} show={props.show} />); |
| 58 | + // // console.log('Diff component wrapper', wrapper); |
| 59 | + // }); |
| 60 | + |
| 61 | + describe('delta', () => { |
| 62 | + it('delta variable should be an object, with a property children', () => { |
| 63 | + expect(typeof delta).toBe('object'); |
| 64 | + expect(delta).toHaveProperty('children'); |
| 65 | + }); |
| 66 | + }); |
| 67 | + |
| 68 | + describe('html', () => { |
| 69 | + it('html variable should be a string', () => { |
| 70 | + expect(typeof html).toBe('string'); |
| 71 | + }); |
| 72 | + }); |
| 73 | + |
| 74 | + describe('previous', () => { |
| 75 | + it('previous variable should be a object', () => { |
| 76 | + expect(previous).toHaveProperty('state'); |
| 77 | + expect(previous).toHaveProperty('children'); |
| 78 | + expect(typeof previous).toBe('object'); |
| 79 | + }); |
| 80 | + }); |
| 81 | + |
| 82 | + // the diff component should be a diff |
| 83 | + // it should detect no state change when state is undefined |
| 84 | + describe('Diff Component', () => { |
| 85 | + it('Check if Diff component is a div', () => { |
| 86 | + expect(wrapper.type()).toEqual('div'); |
| 87 | + }); |
| 88 | + it('Check if Diff component inner text states no chages made', () => { |
| 89 | + expect(wrapper.text()).toEqual('string'); |
| 90 | + }); |
| 91 | + }); |
| 92 | + |
| 93 | +}); |
| 94 | +// JSX INNER TEXT TEST |
| 95 | +// const wrapper = shallow(<div><b>important</b></div>); |
| 96 | +// expect(wrapper.text()).to.equal('important'); |
| 97 | + |
| 98 | +// need to test that if there is no state change detected, we expect a div to be returned with a className="noState" |
| 99 | + |
| 100 | +// If there is a stateChange we expect a div with the appropriate state changes as an html react element obj that is parsed |
| 101 | + |
| 102 | +// test delta; its initially an array with an obj; as soon as you change state from the initial state change, delta becomes an object |
| 103 | + |
| 104 | + |
| 105 | +// check for className=noState |
0 commit comments