1+ import React from 'react' ;
2+ import { shallow , render } from 'enzyme' ;
3+ import { expect } from 'chai' ;
4+
5+ import JsonObject from './../../../src/js/components/DataTypes/Object' ;
6+ import ConfigStore from './../../../src/js/stores/ConfigStore' ;
7+ import AttributeStore from './../../../src/js/stores/ObjectAttributes' ;
8+
9+ describe ( '<JsonObject />' , function ( ) {
10+ const rjvId = 1 ;
11+ ConfigStore . set ( rjvId , 'displayDataTypes' , true ) ;
12+
13+
14+ it ( 'Object component should have a data type label' , function ( ) {
15+ ConfigStore . set ( rjvId , 'displayDataTypes' , true ) ;
16+ let src = {
17+ test : true
18+ }
19+ const wrapper = shallow (
20+ < JsonObject
21+ src = { src }
22+ namespace = { [ 'root' ] }
23+ rjvId = { rjvId }
24+ theme = 'rjv-default'
25+ indentWidth = { 1 }
26+ depth = { 1 }
27+ type = 'object' />
28+ ) ;
29+ expect (
30+ wrapper . find ( '.object-key-val' )
31+ ) . to . have . length ( 1 ) ;
32+ } ) ;
33+
34+
35+ it ( 'Object mount' , function ( ) {
36+ ConfigStore . set ( rjvId , 'displayDataTypes' , true ) ;
37+ let src = {
38+ bool : true , //should have label
39+ int : 5 , //should have label
40+ str : 'test' , //should have label
41+ nan : NaN ,
42+ null : null ,
43+ func : function ( ) { } , //should have label
44+ arr : [
45+ 1 , //should have label
46+ 2 //should have label
47+ ] ,
48+ obj : {
49+ test : true //should have label
50+ }
51+ }
52+ const wrapper = render (
53+ < JsonObject
54+ src = { src }
55+ namespace = { [ 'root' ] }
56+ rjvId = { rjvId }
57+ theme = 'rjv-default'
58+ indentWidth = { 1 }
59+ depth = { 1 }
60+ type = 'object' />
61+ ) ;
62+ expect (
63+ wrapper . find ( '.data-type-label' )
64+ ) . to . have . length ( 7 ) ;
65+ } ) ;
66+
67+
68+ it ( 'Object mount' , function ( ) {
69+ ConfigStore . set ( rjvId , 'displayDataTypes' , true ) ;
70+ let src = {
71+ bool : true , //should have label
72+ int : 5 , //should have label
73+ str : 'test' , //should have label
74+ nan : NaN ,
75+ null : null ,
76+ func : function ( ) { } , //should have label
77+ arr : [
78+ 1 , //should have label
79+ 2 //should have label
80+ ] ,
81+ obj : {
82+ test : true //should have label
83+ }
84+ }
85+ const wrapper = render (
86+ < JsonObject
87+ src = { src }
88+ namespace = { [ 'root' ] }
89+ rjvId = { rjvId }
90+ theme = 'rjv-default'
91+ indentWidth = { 1 }
92+ depth = { 1 }
93+ type = 'object' />
94+ ) ;
95+ expect (
96+ wrapper . find ( '.data-type-label.hidden' )
97+ ) . to . have . length ( 0 ) ;
98+ } ) ;
99+
100+
101+ it ( 'Array mount expanded' , function ( ) {
102+ let src = {
103+ 'arr1' : [
104+ 'arr2' : [
105+ 'test'
106+ ]
107+ ]
108+ }
109+ const wrapper = render (
110+ < JsonObject
111+ src = { src }
112+ namespace = { [ 'arr_test' ] }
113+ name = 'test'
114+ rjvId = { rjvId }
115+ theme = 'rjv-default'
116+ indentWidth = { 1 }
117+ collapsed = { false }
118+ depth = { 1 }
119+ type = 'array' />
120+ ) ;
121+ expect (
122+ wrapper . find ( '.expanded-icon' )
123+ ) . to . have . length ( 2 ) ;
124+ expect (
125+ wrapper . find ( '.collapsed-icon' )
126+ ) . to . have . length ( 0 ) ;
127+ } ) ;
128+
129+
130+ it ( 'Array mount collapsed' , function ( ) {
131+ AttributeStore . set ( rjvId , 'arr_test' , 'expanded' , false ) ;
132+ let src = {
133+ 'arr1' : [
134+ 'arr2' : [
135+ 'test'
136+ ]
137+ ]
138+ }
139+ const wrapper = render (
140+ < JsonObject
141+ src = { src }
142+ namespace = { [ 'arr_test' ] }
143+ name = 'test'
144+ rjvId = { rjvId }
145+ theme = 'rjv-default'
146+ collapsed = { true }
147+ indentWidth = { 1 }
148+ depth = { 1 }
149+ type = 'array' />
150+ ) ;
151+ expect (
152+ wrapper . find ( '.expanded-icon' )
153+ ) . to . have . length ( 0 ) ;
154+ expect (
155+ wrapper . find ( '.collapsed-icon' )
156+ ) . to . have . length ( 1 ) ;
157+ } ) ;
158+
159+ } ) ;
0 commit comments