Skip to content

Commit 51f1cea

Browse files
authored
Merge pull request mac-s-g#42 from mac-s-g/test-buildout
update
2 parents 5945318 + abbc9c0 commit 51f1cea

File tree

7 files changed

+152
-32
lines changed

7 files changed

+152
-32
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ entrypoints
66
example
77
.git
88
.gitignore
9+
test
910
example/example-react.js
1011
webpack.config.template.js
1112

.nycrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"plugins": ["transform-decorators-legacy"],
33
"require": [
44
"babel-register",
5-
"/react/test/helpers/browser.js",
65
"/react/test/helpers/requireSources.js"
76
]
87
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"html-webpack-plugin": "2.28.0",
2727
"ignore-styles": "^5.0.1",
2828
"istanbul": "^0.4.5",
29-
"jsdom": "^9.12.0",
29+
"jsdom": "^10.1.0",
3030
"mocha": "^3.2.0",
3131
"nyc": "^10.3.2",
3232
"radium":"^0.18.2",
@@ -37,6 +37,7 @@
3737
"react-icons": "^2.2.3",
3838
"react-test-renderer": "^15.5.4",
3939
"react-tooltip": "^3.2.10",
40+
"sinon": "^2.2.0",
4041
"webpack": "^2.2.1",
4142
"webpack-dev-server": "^2.3.0"
4243
},

src/js/components/VariableMeta.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,22 @@ export default class extends React.Component {
3737
let clipboard_container = document.getElementById(
3838
'clipboard-container-' + id
3939
);
40-
this.state.clipboard = new Clipboard(
41-
clipboard_container
42-
);
4340

44-
this.state.clipboard.on('success', (e) => {
45-
this.setState({copy_state: 'success'});
46-
});
41+
//cant figure out why document.getElementById
42+
//is not working for tests
43+
if (clipboard_container) {
44+
this.state.clipboard = new Clipboard(
45+
clipboard_container
46+
);
47+
48+
this.state.clipboard.on('success', (e) => {
49+
this.setState({copy_state: 'success'});
50+
});
4751

48-
this.state.clipboard.on('error', (e) => {
49-
this.setState({copy_state: 'error'});
50-
});
52+
this.state.clipboard.on('error', (e) => {
53+
this.setState({copy_state: 'error'});
54+
});
55+
}
5156

5257
this.state.copy_state = null;
5358
}
@@ -62,7 +67,9 @@ export default class extends React.Component {
6267
//it does not support dynamic content updates
6368
let style = Theme(this.props.theme, 'copy-to-clipboard').style;
6469
return (
65-
<span style={{
70+
<span
71+
class="copy-to-clipboard-container"
72+
style={{
6673
display: this.state.display_clipboard ? 'inline-block' : 'none'
6774
}}>
6875
<span
@@ -111,7 +118,8 @@ export default class extends React.Component {
111118
getObjectSize = (size) => {
112119
if (this.state.display_size) {
113120
return (
114-
<span {...Theme(this.props.theme, 'object-size')}>
121+
<span class="object-size"
122+
{...Theme(this.props.theme, 'object-size')}>
115123
{size} item{size == 1 ? '' : 's'}
116124
</span>
117125
);

src/js/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default class extends React.Component {
6262
</div>);
6363
}
6464

65-
componentWillReceiveProps = (nextProps) => {
65+
componentWillReceiveProps(nextProps) {
6666
this.init(this.props);
6767
this.setState(this.state);
6868
}

test/Index-test.js

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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+
});

test/helpers/browser.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)