forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPagerItemSpec.js
More file actions
80 lines (69 loc) · 2.85 KB
/
PagerItemSpec.js
File metadata and controls
80 lines (69 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import ReactDOM from 'react-dom';
import Pager from '../src/Pager';
describe('PagerItem', () => {
it('Should output a "list item" as root element, and an "anchor" as a child item', () => {
let instance = ReactTestUtils.renderIntoDocument(
<Pager.Item href="#">Text</Pager.Item>
);
let node = ReactDOM.findDOMNode(instance);
assert.equal(node.nodeName, 'LI');
assert.equal(node.children.length, 1);
assert.equal(node.children[0].nodeName, 'A');
});
it('Should output "disabled" attribute as a class', () => {
let instance = ReactTestUtils.renderIntoDocument(
<Pager.Item disabled href="#">Text</Pager.Item>
);
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'disabled'));
});
it('Should output "next" attribute as a class', () => {
let instance = ReactTestUtils.renderIntoDocument(
<Pager.Item previous href="#">Previous</Pager.Item>
);
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'previous'));
});
it('Should output "previous" attribute as a class', () => {
let instance = ReactTestUtils.renderIntoDocument(
<Pager.Item next href="#">Next</Pager.Item>
);
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'next'));
});
it('Should call "onSelect" when item is clicked', (done) => {
function handleSelect(key) {
assert.equal(key, 1);
done();
}
let instance = ReactTestUtils.renderIntoDocument(
<Pager.Item eventKey={1} onSelect={handleSelect}>Next</Pager.Item>
);
ReactTestUtils.Simulate.click(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a'));
});
it('Should not call "onSelect" when item disabled and is clicked', () => {
function handleSelect() {
throw new Error('onSelect should not be called');
}
let instance = ReactTestUtils.renderIntoDocument(
<Pager.Item disabled onSelect={handleSelect}>Next</Pager.Item>
);
ReactTestUtils.Simulate.click(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a'));
});
it('Should set target attribute on anchor', () => {
let instance = ReactTestUtils.renderIntoDocument(
<Pager.Item next href="#" target="_blank">Next</Pager.Item>
);
let anchor = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a');
assert.equal(anchor.getAttribute('target'), '_blank');
});
it('Should call "onSelect" with target attribute', (done) => {
function handleSelect(key, e) {
assert.equal(e.target.target, '_blank');
done();
}
let instance = ReactTestUtils.renderIntoDocument(
<Pager.Item eventKey={1} onSelect={handleSelect} target="_blank">Next</Pager.Item>
);
ReactTestUtils.Simulate.click(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a'));
});
});