Skip to content

Commit 3569bc2

Browse files
committed
Added required props, enzyme test suite and config, some initial tests.
1 parent 22de1d0 commit 3569bc2

File tree

4 files changed

+44
-18
lines changed

4 files changed

+44
-18
lines changed

nwb.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ module.exports = {
2020
// and a webpack loader to precompile them. The sequence-viewer component
2121
// uses inline Handlebars.js templates currently.
2222
webpack: {
23+
compat: {
24+
enzyme: true
25+
},
2326
aliases: {
2427
'handlebars': path.resolve("node_modules/handlebars/dist/handlebars.min.js"),
2528
'jQuery': path.resolve("node_modules/jquery/dist/jquery.min.js")

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727
"react": "15.x"
2828
},
2929
"devDependencies": {
30+
"enzyme": "^2.4.1",
3031
"nwb": "0.12.x",
3132
"react": "^15.3.1",
33+
"react-addons-test-utils": "^15.3.1",
3234
"react-dom": "^15.3.1"
3335
},
3436
"author": "Josh Goodman",

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ export default class ReactSequenceViewer extends Component {
7575
}
7676

7777
ReactSequenceViewer.propTypes = {
78+
id: PropTypes.string.isRequired,
79+
sequence: PropTypes.string.isRequired,
7880
coverage: PropTypes.arrayOf(
7981
PropTypes.shape({
8082
start: PropTypes.number.isRequired,
@@ -102,4 +104,5 @@ ReactSequenceViewer.defaultProps = {
102104
seqLenClass: "CPLChoice",
103105
onMouseSelection: (elem) => {},
104106
onSubpartSelected: (elem) => {},
107+
className: '',
105108
}

tests/index-test.js

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,41 @@
1-
import expect from 'expect'
2-
import React from 'react'
3-
import {render, unmountComponentAtNode} from 'react-dom'
1+
import React from 'react';
2+
import expect, {spyOn, createSpy} from 'expect';
3+
import { mount, shallow } from 'enzyme';
44

5-
import Component from 'src/'
5+
import Component from 'src/';
66

7-
describe('Component', () => {
8-
let node
7+
describe('<Component />', () => {
8+
const sequence = 'ctcgatgctagtcgatgctagtcgtagcta';
99

10-
beforeEach(() => {
11-
node = document.createElement('div')
12-
})
10+
let parent = document.createElement('div');
11+
parent.id = 'test';
1312

14-
afterEach(() => {
15-
unmountComponentAtNode(node)
16-
})
13+
beforeEach(() => {
14+
document.body.appendChild(parent);
15+
});
16+
17+
afterEach(() => {
18+
document.body.removeChild(parent);
19+
});
20+
21+
it('calls componentDidMount', () => {
22+
const spy = spyOn(Component.prototype, 'componentDidMount');
23+
const wrapper = mount(<Component id="test" sequence="cgtagtcgatca" />);
24+
expect(spy).toHaveBeenCalled();
25+
});
26+
27+
it('checking required props', () => {
28+
const wrapper = mount(<Component id="test" sequence={sequence} />);
29+
expect(wrapper.props().sequence).toEqual(sequence);
30+
expect(wrapper.props().id).toEqual("test");
31+
});
32+
33+
/*it('charsPerLine onClick handler fired', () => {
34+
const spy = createSpy();
35+
const wrapper = mount(<Component id="test" sequence={sequence} toolbar={true} handleChange={spy} />);
36+
console.debug(wrapper.find('.sequenceToolbar'));
37+
wrapper.find('option[value="100"]').simulate('click');
38+
expect(spy).toHaveBeenCalled();
39+
});*/
40+
});
1741

18-
it('displays a welcome message', () => {
19-
render(<Component/>, node, () => {
20-
expect(node.innerHTML).toContain('Welcome to React components')
21-
})
22-
})
23-
})

0 commit comments

Comments
 (0)