Skip to content

Commit 93ede64

Browse files
committed
Fixes: #6 - Write test cases
1 parent 58628cb commit 93ede64

File tree

4 files changed

+46
-14
lines changed

4 files changed

+46
-14
lines changed

nwb.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,11 @@ module.exports = {
88
react: 'React'
99
}
1010
}
11+
},
12+
webpack: {
13+
compat: {
14+
enzyme: true,
15+
sinon: true
16+
}
1117
}
1218
}

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323
"react": "15.x"
2424
},
2525
"devDependencies": {
26+
"enzyme": "^2.9.1",
2627
"nwb": "0.18.x",
2728
"react": "^15.6.1",
28-
"react-dom": "^15.6.1"
29+
"react-addons-test-utils": "^15.6.0",
30+
"react-dom": "^15.6.1",
31+
"react-test-renderer": "^15.6.1"
2932
},
3033
"author": "",
3134
"homepage": "",

src/index.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { Component } from 'react'
22
import './style.css';
33

44

5-
export default class extends Component {
5+
export default class ReactPagination extends Component {
66
limit = 20;
77
total = 0;
88
pageCount = 0;
@@ -128,8 +128,6 @@ export default class extends Component {
128128
}
129129
this.generatePagination();
130130
this.setState(state);
131-
132-
// this.onSelectPage.emit(page);
133131
}
134132
goPrev() {
135133
if (this.current > 0) {
@@ -147,7 +145,6 @@ export default class extends Component {
147145
let buttonColor='#fff';
148146

149147
let first = this.state.pagination.first.map((n, i) => {
150-
console.log('selected page', this.state.current);
151148
let btnStyle={backgroundColor:buttonColor};
152149
if (this.state.current === n) {
153150
btnStyle.backgroundColor = activeButtonColor
@@ -164,7 +161,6 @@ export default class extends Component {
164161
)
165162
})
166163
let second = this.state.pagination.second.map((n, i) => {
167-
console.log('selected second page', this.state.current);
168164

169165
let btnStyle={backgroundColor:buttonColor};
170166
if (this.state.current === n) {
@@ -182,7 +178,6 @@ export default class extends Component {
182178
)
183179
})
184180
let third = this.state.pagination.third.map((n, i) => {
185-
console.log('selected third page', this.state.current);
186181

187182
let btnStyle={backgroundColor:buttonColor};
188183
if (this.state.current === n) {

tests/index-test.js

+35-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,51 @@
11
import expect from 'expect'
22
import React from 'react'
3-
import {render, unmountComponentAtNode} from 'react-dom'
4-
3+
import { render, ReactDOM, unmountComponentAtNode } from 'react-dom'
4+
import { mount } from "enzyme";
55
import Component from 'src/'
66

77
describe('Component', () => {
88
let node
9+
let props;
10+
let mountedReactPagination;
11+
const ractPagination = () => {
12+
if (!mountedReactPagination) {
13+
mountedReactPagination = mount(
14+
<Component {...props} />
15+
);
16+
}
17+
return mountedReactPagination;
18+
}
919

1020
beforeEach(() => {
1121
node = document.createElement('div')
22+
23+
props = {
24+
total: undefined,
25+
limit: undefined,
26+
};
27+
mountedReactPagination = undefined;
1228
})
1329

1430
afterEach(() => {
1531
unmountComponentAtNode(node)
1632
})
33+
it("always renders a div", () => {
34+
const divs = ractPagination().find("div");
35+
expect(divs.length).toBeGreaterThan(0);
36+
});
37+
38+
it('check pagination controllers', () => {
39+
render(<Component />, node, () => {
40+
expect(node.innerHTML).toContain('Prev');
41+
expect(node.innerHTML).toContain('Next');
1742

18-
it('sample test case', () => {
19-
render(<Component/>, node, () => {
20-
expect(node.innerHTML).toContain('Prev')
2143
})
22-
})
23-
})
44+
});
45+
46+
it("contains everything else that gets rendered", () => {
47+
const divs = ractPagination().find("div");
48+
const wrappingDiv = divs.first();
49+
expect(wrappingDiv.children()).toEqual(ractPagination().children());
50+
});
51+
});

0 commit comments

Comments
 (0)