Skip to content

Commit 50194da

Browse files
committed
basic editor container tests
1 parent c805ecb commit 50194da

File tree

6 files changed

+103
-33
lines changed

6 files changed

+103
-33
lines changed

Diff for: src/addons/__tests__/Grid.spec.js

+28-22
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,59 @@
11
'use strict';
2-
var React = require('react');
3-
var rewire = require('rewire');
4-
var Grid = rewire('../grids/ReactDataGrid.js');
5-
var TestUtils = require('react/lib/ReactTestUtils');
2+
var React = require('react');
3+
var rewire = require('rewire');
4+
var Grid = rewire('../grids/ReactDataGrid.js');
5+
var TestUtils = require('react/lib/ReactTestUtils');
66
var rewireModule = require("../../../test/rewireModule");
7+
var StubComonent = require("../../../test/StubComponent");
78

89
var columns = [
910
{
10-
key: 'id',
11-
name: 'ID',
12-
width: '20%'
11+
key : 'id',
12+
name : 'ID',
13+
width : 100
1314
},
1415
{
1516
key: 'title',
16-
name: 'Title'
17+
name: 'Title',
18+
width : 100
1719
},
1820
{
1921
key: 'count',
2022
name: 'Count',
21-
width: '20%'
23+
width : 100
2224
},
2325
]
2426

25-
var getRows = function(start, end) {
26-
var result = []
27-
for (var i = start; i < end; i++) {
28-
result.push({
29-
id: i,
30-
title: 'Title ' + i,
31-
count: i * 1000
32-
});
33-
}
34-
return result;
27+
28+
var _rows = [];
29+
for (var i = 0; i < 1000; i++) {
30+
_rows.push({
31+
id: i,
32+
title: 'Title ' + i,
33+
count: i * 1000
34+
});
35+
}
36+
37+
var rowGetter = function(i){
38+
return _rows[i];
3539
}
3640

3741
describe('Grid', () => {
3842
var component;
3943
var ExcelCell = React.createFactory('div');
4044
// Configure local variable replacements for the module.
4145
rewireModule(Grid, {
42-
ExcelCell: ExcelCell
46+
ExcelCell: ExcelCell,
47+
BaseGrid : StubComonent('BaseGrid')
4348
});
4449

4550
beforeEach(() => {
4651
var rowsCount = 1000;
4752
component = TestUtils.renderIntoDocument(<Grid
4853
columns={columns}
49-
rowGetter={getRows(0, rowsCount)}
50-
rowsCount={rowsCount}/>);
54+
rowGetter={rowGetter}
55+
rowsCount={_rows.length}
56+
width={300}/>);
5157
});
5258

5359
it('should create a new instance of Grid', () => {

Diff for: src/addons/editors/EditorContainer.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,16 @@ var EditorContainer = React.createClass({
1919
mixins : [keyboardHandlerMixin],
2020

2121
propTypes : {
22-
cellMetaData : React.PropTypes.func.isRequired,
23-
column : React.PropTypes.object.isRequired
22+
rowData :React.PropTypes.object.isRequired,
23+
value: React.PropTypes.oneOfType([React.PropTypes.string,React.PropTypes.number, React.PropTypes.object, React.PropTypes.bool]).isRequired,
24+
cellMetaData: React.PropTypes.shape({
25+
selected: React.PropTypes.object.isRequired,
26+
copied: React.PropTypes.object,
27+
dragged: React.PropTypes.object,
28+
onCellClick: React.PropTypes.func
29+
}).isRequired,
30+
column : React.PropTypes.object.isRequired,
31+
height : React.PropTypes.number.isRequired
2432
},
2533

2634
getInitialState(){
@@ -232,6 +240,7 @@ var EditorContainer = React.createClass({
232240
if(!this.isKeyPrintable(keyCode)){
233241
this.getInputNode().focus();
234242
this.setCaretAtEndOfInput();
243+
this.getInputNode().select();
235244
}else{
236245
this.getInputNode().select();
237246
}

Diff for: src/addons/editors/SimpleTextEditor.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ var ExcelColumn = require('../grids/ExcelColumn');
1313
var SimpleTextEditor = React.createClass({
1414

1515
propTypes : {
16-
onKeyDown : React.PropTypes.func.isRequired,
1716
value : React.PropTypes.any.isRequired,
1817
onBlur : React.PropTypes.func.isRequired,
1918
column : React.PropTypes.shape(ExcelColumn).isRequired
@@ -30,7 +29,7 @@ var SimpleTextEditor = React.createClass({
3029
},
3130

3231
render(): ?ReactElement {
33-
return (<input ref="input" type="text" onBlur={this.props.onBlur} className="form-control" defaultValue={this.props.value} onKeyDown={this.props.onKeyDown} />);
32+
return (<input ref="input" type="text" onBlur={this.props.onBlur} className="form-control" defaultValue={this.props.value}/>);
3433
}
3534

3635
});

Diff for: src/addons/editors/__tests__/EditorContainer.spec.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict';
2+
var React = require('react');
3+
var rewire = require('rewire');
4+
var EditorContainer = rewire('../EditorContainer.js');
5+
var TestUtils = require('react/lib/ReactTestUtils');
6+
var SimpleTextEditor = require('../SimpleTextEditor');
7+
8+
describe('Editor Container Tests', () => {
9+
var component;
10+
beforeEach(() => {
11+
12+
var fakeColumn = {
13+
name : 'col1',
14+
key : 'col1',
15+
width : 100
16+
};
17+
var cellMetaData = {
18+
selected : {
19+
idx : 0,
20+
rowIdx :0
21+
}
22+
}
23+
var rowData={
24+
col1 : 'I',
25+
col2 : 'love',
26+
col3 : 'Testing'
27+
}
28+
29+
component = TestUtils.renderIntoDocument(<EditorContainer
30+
rowData={rowData}
31+
value={'Adwolf'}
32+
cellMetaData={cellMetaData}
33+
column={fakeColumn}
34+
height={50}/>);
35+
});
36+
37+
it('should create a new EditorContainer instance', () => {
38+
expect(component).toBeDefined();
39+
});
40+
41+
it('should render a simpleTextEditor if no column.editor property', () => {
42+
var Editor = TestUtils.findRenderedComponentWithType(component, SimpleTextEditor)
43+
expect(Editor).toBeDefined();
44+
});
45+
46+
47+
48+
});

Diff for: test/StubComponent.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var React = require('react');
2+
3+
module.exports = function(mockTagName: string){
4+
return React.createClass({
5+
render: function() {
6+
var mockTagName = mockTagName || "div";
7+
return React.DOM[mockTagName](null, this.props.children);
8+
}
9+
});
10+
};

Diff for: test/coverage/test-results.xml

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
<?xml version="1.0"?>
22
<testsuites>
3-
<testsuite name="PhantomJS 1.9.8 (Windows 7)" package="" timestamp="2015-04-13T15:56:22" id="0" hostname="CHELSEA" tests="1" errors="0" failures="0" time="0.143">
3+
<testsuite name="PhantomJS 1.9.8 (Windows 7)" package="" timestamp="2015-04-13T17:13:27" id="0" hostname="CHELSEA" tests="3" errors="0" failures="0" time="0.025">
44
<properties>
55
<property name="browser.fullName" value="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.8 Safari/534.34"/>
66
</properties>
7-
<testcase name="should create a new instance of Grid" time="0.143" classname="PhantomJS 1.9.8 (Windows 7).Grid"/>
8-
<system-out><![CDATA[PhantomJS 1.9.8 (Windows 7) WARN: 'Warning: Invalid prop `rowGetter` of type `array` supplied to `ReactDataGrid`, expected `function`.'
9-
,PhantomJS 1.9.8 (Windows 7) WARN: 'Warning: Invalid prop `width` of type `string` supplied to `ReactDataGrid`, expected `number`.'
10-
,PhantomJS 1.9.8 (Windows 7) WARN: 'Warning: Invalid prop `width` of type `string` supplied to `Grid`, expected `number`. Check the render method of `ReactDataGrid`.'
11-
,PhantomJS 1.9.8 (Windows 7) WARN: 'Warning: Required prop `totalWidth` was not specified in `Viewport`. Check the render method of `Grid`.'
12-
7+
<testcase name="should create a new instance of Grid" time="0.011" classname="PhantomJS 1.9.8 (Windows 7).Grid"/>
8+
<testcase name="should create a new EditorContainer instance" time="0.012" classname="PhantomJS 1.9.8 (Windows 7).Editor Container Tests"/>
9+
<testcase name="should render a simpleTextEditor if no column.editor property" time="0.002" classname="PhantomJS 1.9.8 (Windows 7).Editor Container Tests"/>
10+
<system-out><![CDATA[
1311
]]></system-out>
1412
<system-err/>
1513
</testsuite>

0 commit comments

Comments
 (0)