|
| 1 | +import React from 'react'; |
| 2 | +import { render, mount } from 'enzyme'; |
| 3 | +import sinon from 'sinon'; |
| 4 | +import { expect } from 'chai'; |
| 5 | +import { JSDOM } from 'jsdom'; |
| 6 | + |
| 7 | +import Index from './../src/js/index'; |
| 8 | + |
| 9 | +const { window } = (new JSDOM()); |
| 10 | +global.window = window; |
| 11 | +global.document = window.document; |
| 12 | + |
| 13 | +describe('<Index />', function () { |
| 14 | + |
| 15 | + const rjvId = 1; |
| 16 | + |
| 17 | + |
| 18 | + it('check data type labels from index', function () { |
| 19 | + const wrapper = render( |
| 20 | + <Index |
| 21 | + src={{ |
| 22 | + bool: true, |
| 23 | + str: 'test', |
| 24 | + int: 5, |
| 25 | + nan: NaN, |
| 26 | + null: null, |
| 27 | + func: (test) => {}, |
| 28 | + obj:{ |
| 29 | + arrChild: [ |
| 30 | + 1, 2, 'three' |
| 31 | + ], |
| 32 | + objChild: { |
| 33 | + one: 1, |
| 34 | + two: 'two' |
| 35 | + } |
| 36 | + }, |
| 37 | + arr: [ |
| 38 | + [1, 'two'], {one: 'one', two: 2} |
| 39 | + ] |
| 40 | + }} |
| 41 | + /> |
| 42 | + ); |
| 43 | + expect( |
| 44 | + wrapper.find('.data-type-label') |
| 45 | + ).to.have.length(13); |
| 46 | + expect( |
| 47 | + wrapper.find('.data-type-label') |
| 48 | + ).to.have.length(13); |
| 49 | + }); |
| 50 | + |
| 51 | + // i need to fix attribute mgmt to get this working |
| 52 | + // it('check object-size labels from index', function () { |
| 53 | + // const wrapper = mount( |
| 54 | + // <Index |
| 55 | + // src={{ |
| 56 | + // bool: true, |
| 57 | + // str: 'test', |
| 58 | + // int: 5, |
| 59 | + // nan: NaN, |
| 60 | + // null: null, |
| 61 | + // func: (test) => {}, |
| 62 | + // obj:{ |
| 63 | + // arrChild: [ |
| 64 | + // 1, 2, 'three' |
| 65 | + // ], |
| 66 | + // objChild: { |
| 67 | + // one: 1, |
| 68 | + // two: 'two' |
| 69 | + // } |
| 70 | + // }, |
| 71 | + // arr: [ |
| 72 | + // [1, 'two'], {one: 'one', two: 2} |
| 73 | + // ] |
| 74 | + // }} |
| 75 | + // displayObjectSize={true} |
| 76 | + // displayDataTypes={true} |
| 77 | + // enableClipboard={false} |
| 78 | + // /> |
| 79 | + // ); |
| 80 | + // expect( |
| 81 | + // wrapper.find('.object-size') |
| 82 | + // ).to.have.length(7); |
| 83 | + |
| 84 | + // wrapper.setProps({displayObjectSize: false}); |
| 85 | + // expect( |
| 86 | + // wrapper.find('.object-size') |
| 87 | + // ).to.have.length(0); |
| 88 | + // }); |
| 89 | + |
| 90 | + |
| 91 | + it('src replaced with error message', function () { |
| 92 | + const wrapper = render( |
| 93 | + <Index src={'{jsonEncodedString:true, createError:true}'} /> |
| 94 | + ); |
| 95 | + expect( |
| 96 | + wrapper.find('.data-type-label') |
| 97 | + ).to.have.length(1); |
| 98 | + }); |
| 99 | + |
| 100 | + |
| 101 | + it( |
| 102 | + 'make sure copy to clipboard is displayed for objects and arrays', |
| 103 | + function () { |
| 104 | + const wrapper = render( |
| 105 | + <Index src={{ |
| 106 | + test: true, passing: 'hopefully', arr: [], obj: {} |
| 107 | + }} /> |
| 108 | + ); |
| 109 | + expect( |
| 110 | + wrapper.find('.copy-to-clipboard-container') |
| 111 | + ).to.have.length(3); |
| 112 | + }); |
| 113 | + |
| 114 | + |
| 115 | + it('index test componentWillReceiveProps', function () { |
| 116 | + sinon.spy(Index.prototype, 'componentWillReceiveProps'); |
| 117 | + const wrapper = mount( |
| 118 | + <Index src={{test: true}} /> |
| 119 | + ); |
| 120 | + expect( |
| 121 | + wrapper.find('.data-type-label') |
| 122 | + ).to.have.length(1); |
| 123 | + wrapper.setProps({src:{test1:true, test2:false}}); |
| 124 | + expect( |
| 125 | + Index.prototype.componentWillReceiveProps.calledOnce |
| 126 | + ).to.equal(true); |
| 127 | + }); |
| 128 | + |
| 129 | +}); |
0 commit comments