11import React from 'react' ;
22import { configure , shallow } from 'enzyme' ;
33import Adapter from 'enzyme-adapter-react-16' ;
4- import { diff , formatters } from 'jsondiffpatch' ;
5- import ReactHtmlParser from 'react-html-parser' ;
64import Diff from '../components/Diff.jsx' ;
75
86import { useStoreContext } from '../store' ;
@@ -13,51 +11,32 @@ jest.mock('../store');
1311
1412describe ( 'Unit testing for Diff.jsx' , ( ) => {
1513 let wrapper ;
16- // const props = {
17- // show: false,
18- // snapshot: [{
19- // children: [{
20- // state: { total: 12, next: 5, operation: null },
21- // }],
14+ const props = {
15+ show : false ,
16+ snapshot : [ {
17+ children : [ {
18+ state : { total : 12 , next : 5 , operation : null } ,
19+ } ] ,
2220
23- // }],
24- // }
21+ } ] ,
22+ }
2523
2624 const state = {
2725 currentTab : 100 ,
28- tabs : { 100 : { snapshots : [ 1 , 2 , 3 , 4 ] , viewIndex : 1 , sliderIndex : 1 } } ,
26+ tabs : { 100 : { snapshots : [ 1 , 2 , 3 , 4 ] , viewIndex : 1 , sliderIndex : 1 } } ,
2927 } ;
3028
31- const currentTab = state . tabs [ state . currentTab ] ;
3229
33- jest . mock ( '../store' ) ;
3430 useStoreContext . mockImplementation ( ( ) => [ state ] ) ;
3531
3632 const delta = { children : { } } ; // expect delta to be an obj
3733 const html = 'html' ; // expect html to be a string
3834 const previous = { state : 'string' , children : { } } ; // expect previous to be an obj
3935
4036 beforeEach ( ( ) => {
41- wrapper = shallow ( < Diff /> ) ;
42- useStoreContext . mockClear ( ) ;
43- // console.log('Diff component wrapper', wrapper);
37+ wrapper = shallow ( < Diff { ...props } /> ) ;
4438 } ) ;
4539
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-
6140 describe ( 'delta' , ( ) => {
6241 it ( 'delta variable should be an object, with a property children' , ( ) => {
6342 expect ( typeof delta ) . toBe ( 'object' ) ;
@@ -79,27 +58,17 @@ describe('Unit testing for Diff.jsx', () => {
7958 } ) ;
8059 } ) ;
8160
82- // the diff component should be a diff
83- // it should detect no state change when state is undefined
8461 describe ( 'Diff Component' , ( ) => {
8562 it ( 'Check if Diff component is a div' , ( ) => {
8663 expect ( wrapper . type ( ) ) . toEqual ( 'div' ) ;
8764 } ) ;
88- it ( 'Check if Diff component inner text states no chages made' , ( ) => {
89- expect ( wrapper . text ( ) ) . toEqual ( 'string' ) ;
65+ it ( 'Check if Diff component inner text value is a string' , ( ) => {
66+ expect ( typeof wrapper . text ( ) ) . toEqual ( 'string' ) ;
67+ } ) ;
68+ xit ( 'Check if Diff component div has a className noState ' , ( ) => {
69+ console . log ( wrapper . props ( ) ) ;
70+ expect ( wrapper . props ( ) . className ) . toEqual ( 'noState' ) ;
9071 } ) ;
9172 } ) ;
9273
9374} ) ;
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