Skip to content

Commit 5945318

Browse files
authored
Merge pull request mac-s-g#41 from mac-s-g/test-buildout
added more tests
2 parents d932449 + 33e6b02 commit 5945318

File tree

8 files changed

+298
-3
lines changed

8 files changed

+298
-3
lines changed

src/js/components/DataTypes/Object.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,26 @@ class rjvObject extends React.Component {
102102
let expanded_icon, object_padding_left = 0;
103103

104104
if (expanded) {
105-
expanded_icon = <CircleMinus {...Theme(theme, 'expanded-icon')} />
105+
expanded_icon = <CircleMinus
106+
{...Theme(theme, 'expanded-icon')}
107+
class="expanded-icon"
108+
/>
106109
} else {
107-
expanded_icon = <CirclePlus {...Theme(theme, 'collapsed-icon')} />
110+
expanded_icon = <CirclePlus
111+
{...Theme(theme, 'collapsed-icon')}
112+
class="collapsed-icon"
113+
/>
108114
}
109115

110116
if (!jsvRoot) {
111117
object_padding_left = this.props.indentWidth * SINGLE_INDENT;
112118
}
113119

114120

115-
return (<div {...Theme(theme, jsvRoot ? 'jsv-root' : 'objectKeyVal', object_padding_left)}>
121+
return (<div class='object-key-val'
122+
{...Theme(
123+
theme, jsvRoot ? 'jsv-root' : 'objectKeyVal', object_padding_left
124+
)}>
116125
<span>
117126
<span onClick={this.toggleCollapsed} {...Theme(theme, 'brace-row')}>
118127
<span class="icon-container">{expanded_icon}</span>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
import {expect} from 'chai';
4+
5+
import DataTypeLabel from './../../../src/js/components/DataTypes/DataTypeLabel';
6+
import ConfigStore from './../../../src/js/stores/ConfigStore';
7+
8+
describe('<DataTypeLabel />', function () {
9+
const rjvId = 1;
10+
11+
it('DataTypeLabel should exist when displayDataTypes is true', function () {
12+
ConfigStore.set(rjvId, 'displayDataTypes', true);
13+
const wrapper = shallow(
14+
<DataTypeLabel type_name='test' rjvId={rjvId} theme='rjv-default'/>
15+
);
16+
expect(wrapper.find('.data-type-label.hidden')).to.have.length(0);
17+
});
18+
19+
it('DataTypeLabel should not exist when displayDataTypes is false', function () {
20+
ConfigStore.set(rjvId, 'displayDataTypes', false);
21+
const wrapper = shallow(
22+
<DataTypeLabel type_name='test' rjvId={rjvId} theme='rjv-default'/>
23+
);
24+
expect(wrapper.find('.data-type-label.hidden')).to.have.length(1);
25+
});
26+
27+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
import {expect} from 'chai';
4+
5+
import JsonFloat from './../../../src/js/components/DataTypes/Float';
6+
import DataTypeLabel from './../../../src/js/components/DataTypes/DataTypeLabel';
7+
import ConfigStore from './../../../src/js/stores/ConfigStore';
8+
9+
describe('<JsonFloat />', function () {
10+
const rjvId = 1;
11+
ConfigStore.set(rjvId, 'displayDataTypes', true);
12+
13+
it('float component should have a data type label', function () {
14+
const wrapper = shallow(
15+
<JsonFloat value={1.25} rjvId={rjvId} theme='rjv-default'/>
16+
);
17+
expect(wrapper.find(DataTypeLabel)).to.have.length(1);
18+
});
19+
20+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
import {expect} from 'chai';
4+
5+
import JsonFunction from './../../../src/js/components/DataTypes/Function';
6+
import DataTypeLabel from './../../../src/js/components/DataTypes/DataTypeLabel';
7+
import ConfigStore from './../../../src/js/stores/ConfigStore';
8+
9+
describe('<JsonFunction />', function () {
10+
const rjvId = 1;
11+
ConfigStore.set(rjvId, 'displayDataTypes', true);
12+
13+
it('function component should have a data type label', function () {
14+
const wrapper = shallow(
15+
<JsonFunction value={function(){}} rjvId={rjvId} theme='rjv-default'/>
16+
);
17+
expect(wrapper.find(DataTypeLabel)).to.have.length(1);
18+
});
19+
20+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
import {expect} from 'chai';
4+
5+
import JsonInteger from './../../../src/js/components/DataTypes/Integer';
6+
import DataTypeLabel from './../../../src/js/components/DataTypes/DataTypeLabel';
7+
import ConfigStore from './../../../src/js/stores/ConfigStore';
8+
9+
describe('<JsonInteger />', function () {
10+
const rjvId = 1;
11+
ConfigStore.set(rjvId, 'displayDataTypes', true);
12+
13+
it('integer component should have a data type label', function () {
14+
const wrapper = shallow(
15+
<JsonInteger value={1} rjvId={rjvId} theme='rjv-default'/>
16+
);
17+
expect(wrapper.find(DataTypeLabel)).to.have.length(1);
18+
});
19+
20+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
import {expect} from 'chai';
4+
5+
import JsonNan from './../../../src/js/components/DataTypes/Nan';
6+
import DataTypeLabel from './../../../src/js/components/DataTypes/DataTypeLabel';
7+
import ConfigStore from './../../../src/js/stores/ConfigStore';
8+
9+
describe('<JsonNan />', function () {
10+
const rjvId = 1;
11+
ConfigStore.set(rjvId, 'displayDataTypes', true);
12+
13+
it('Nan component should no data type label', function () {
14+
const wrapper = shallow(
15+
<JsonNan rjvId={rjvId} theme='rjv-default'/>
16+
);
17+
expect(wrapper.find(DataTypeLabel)).to.have.length(0);
18+
});
19+
20+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
import {expect} from 'chai';
4+
5+
import JsonNull from './../../../src/js/components/DataTypes/Null';
6+
import DataTypeLabel from './../../../src/js/components/DataTypes/DataTypeLabel';
7+
import ConfigStore from './../../../src/js/stores/ConfigStore';
8+
9+
describe('<JsonNull />', function () {
10+
const rjvId = 1;
11+
ConfigStore.set(rjvId, 'displayDataTypes', true);
12+
13+
it('Null component should no data type label', function () {
14+
const wrapper = shallow(
15+
<JsonNull rjvId={rjvId} theme='rjv-default'/>
16+
);
17+
expect(wrapper.find(DataTypeLabel)).to.have.length(0);
18+
});
19+
20+
});
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
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

Comments
 (0)