Skip to content

Commit 0bf0ff4

Browse files
committed
added new unittests
1 parent 1a475bd commit 0bf0ff4

1 file changed

Lines changed: 105 additions & 0 deletions

File tree

‎tests/rowOverEvents.spec.js‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/* eslint-disable no-console,func-names,react/no-multi-comp */
2+
const expect = require('expect.js');
3+
const Table = require('../');
4+
const React = require('react');
5+
const ReactDOM = require('react-dom');
6+
const $ = require('jquery');
7+
const { Simulate } = require('react-addons-test-utils');
8+
9+
describe('mouse event in table row', () => {
10+
const div = document.createElement('div');
11+
document.body.appendChild(div);
12+
let node;
13+
14+
const columns = [{
15+
title: 'Name',
16+
dataIndex: 'name',
17+
key: 'name',
18+
width: 400,
19+
}, {
20+
title: 'Age',
21+
dataIndex: 'age',
22+
key: 'age',
23+
width: 100,
24+
render: (text) => (
25+
<a href="#">
26+
Alert: {text}, click will pop to row click
27+
</a>
28+
),
29+
}, {
30+
title: 'Address',
31+
dataIndex: 'address',
32+
key: 'address',
33+
width: 200,
34+
}];
35+
const data = [{
36+
key: 1,
37+
name: 'a',
38+
age: 32,
39+
address: 'I am a',
40+
}];
41+
42+
const spy = {
43+
callCount: 0,
44+
callArgs: null,
45+
};
46+
47+
const onRowMouseOver = (...args) => {
48+
spy.callArgs = args;
49+
spy.callCount += 1;
50+
};
51+
52+
const onRowMouseOut = (...args) => {
53+
spy.callArgs = args;
54+
spy.callCount += 1;
55+
};
56+
57+
const onRowMouseUp = (...args) => {
58+
spy.callArgs = args;
59+
spy.callCount += 1;
60+
};
61+
62+
beforeEach(() => {
63+
ReactDOM.render(
64+
<Table
65+
columns={columns}
66+
data={data}
67+
onRowMouseUp={onRowMouseUp}
68+
onRowMouseOver={onRowMouseOver}
69+
onRowMouseOut={onRowMouseOut}
70+
/>,
71+
div
72+
);
73+
node = $(div);
74+
});
75+
76+
afterEach(() => {
77+
ReactDOM.unmountComponentAtNode(div);
78+
spy.callArgs = null;
79+
spy.callCount = 0;
80+
});
81+
82+
it('mouseOver', () => {
83+
Simulate.mouseOver(node.find('tbody tr:first')[0]);
84+
expect(spy.callCount).to.be(1);
85+
expect(spy.callArgs[0]).to.be(data[0]);
86+
expect(spy.callArgs[1]).to.be(0);
87+
expect(spy.callArgs[2].type).to.be('mouseover');
88+
});
89+
90+
it('mouseUp', () => {
91+
Simulate.mouseUp(node.find('tbody tr:first')[0]);
92+
expect(spy.callCount).to.be(1);
93+
expect(spy.callArgs[0]).to.be(data[0]);
94+
expect(spy.callArgs[1]).to.be(0);
95+
expect(spy.callArgs[2].type).to.be('mouseup');
96+
});
97+
98+
it('mouseOut', () => {
99+
Simulate.mouseOut(node.find('tbody tr:first')[0]);
100+
expect(spy.callCount).to.be(1);
101+
expect(spy.callArgs[0]).to.be(data[0]);
102+
expect(spy.callArgs[1]).to.be(0);
103+
expect(spy.callArgs[2].type).to.be('mouseout');
104+
});
105+
});

0 commit comments

Comments
 (0)