Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
basic editor container tests
Browse files Browse the repository at this point in the history
  • Loading branch information
malonecj committed Apr 13, 2015
1 parent c805ecb commit 50194da
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 33 deletions.
50 changes: 28 additions & 22 deletions src/addons/__tests__/Grid.spec.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,59 @@
'use strict';
var React = require('react');
var rewire = require('rewire');
var Grid = rewire('../grids/ReactDataGrid.js');
var TestUtils = require('react/lib/ReactTestUtils');
var React = require('react');
var rewire = require('rewire');
var Grid = rewire('../grids/ReactDataGrid.js');
var TestUtils = require('react/lib/ReactTestUtils');
var rewireModule = require("../../../test/rewireModule");
var StubComonent = require("../../../test/StubComponent");

var columns = [
{
key: 'id',
name: 'ID',
width: '20%'
key : 'id',
name : 'ID',
width : 100
},
{
key: 'title',
name: 'Title'
name: 'Title',
width : 100
},
{
key: 'count',
name: 'Count',
width: '20%'
width : 100
},
]

var getRows = function(start, end) {
var result = []
for (var i = start; i < end; i++) {
result.push({
id: i,
title: 'Title ' + i,
count: i * 1000
});
}
return result;

var _rows = [];
for (var i = 0; i < 1000; i++) {
_rows.push({
id: i,
title: 'Title ' + i,
count: i * 1000
});
}

var rowGetter = function(i){
return _rows[i];
}

describe('Grid', () => {
var component;
var ExcelCell = React.createFactory('div');
// Configure local variable replacements for the module.
rewireModule(Grid, {
ExcelCell: ExcelCell
ExcelCell: ExcelCell,
BaseGrid : StubComonent('BaseGrid')
});

beforeEach(() => {
var rowsCount = 1000;
component = TestUtils.renderIntoDocument(<Grid
columns={columns}
rowGetter={getRows(0, rowsCount)}
rowsCount={rowsCount}/>);
rowGetter={rowGetter}
rowsCount={_rows.length}
width={300}/>);
});

it('should create a new instance of Grid', () => {
Expand Down
13 changes: 11 additions & 2 deletions src/addons/editors/EditorContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@ var EditorContainer = React.createClass({
mixins : [keyboardHandlerMixin],

propTypes : {
cellMetaData : React.PropTypes.func.isRequired,
column : React.PropTypes.object.isRequired
rowData :React.PropTypes.object.isRequired,
value: React.PropTypes.oneOfType([React.PropTypes.string,React.PropTypes.number, React.PropTypes.object, React.PropTypes.bool]).isRequired,
cellMetaData: React.PropTypes.shape({
selected: React.PropTypes.object.isRequired,
copied: React.PropTypes.object,
dragged: React.PropTypes.object,
onCellClick: React.PropTypes.func
}).isRequired,
column : React.PropTypes.object.isRequired,
height : React.PropTypes.number.isRequired
},

getInitialState(){
Expand Down Expand Up @@ -232,6 +240,7 @@ var EditorContainer = React.createClass({
if(!this.isKeyPrintable(keyCode)){
this.getInputNode().focus();
this.setCaretAtEndOfInput();
this.getInputNode().select();
}else{
this.getInputNode().select();
}
Expand Down
3 changes: 1 addition & 2 deletions src/addons/editors/SimpleTextEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ var ExcelColumn = require('../grids/ExcelColumn');
var SimpleTextEditor = React.createClass({

propTypes : {
onKeyDown : React.PropTypes.func.isRequired,
value : React.PropTypes.any.isRequired,
onBlur : React.PropTypes.func.isRequired,
column : React.PropTypes.shape(ExcelColumn).isRequired
Expand All @@ -30,7 +29,7 @@ var SimpleTextEditor = React.createClass({
},

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

});
Expand Down
48 changes: 48 additions & 0 deletions src/addons/editors/__tests__/EditorContainer.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict';
var React = require('react');
var rewire = require('rewire');
var EditorContainer = rewire('../EditorContainer.js');
var TestUtils = require('react/lib/ReactTestUtils');
var SimpleTextEditor = require('../SimpleTextEditor');

describe('Editor Container Tests', () => {
var component;
beforeEach(() => {

var fakeColumn = {
name : 'col1',
key : 'col1',
width : 100
};
var cellMetaData = {
selected : {
idx : 0,
rowIdx :0
}
}
var rowData={
col1 : 'I',
col2 : 'love',
col3 : 'Testing'
}

component = TestUtils.renderIntoDocument(<EditorContainer
rowData={rowData}
value={'Adwolf'}
cellMetaData={cellMetaData}
column={fakeColumn}
height={50}/>);
});

it('should create a new EditorContainer instance', () => {
expect(component).toBeDefined();
});

it('should render a simpleTextEditor if no column.editor property', () => {
var Editor = TestUtils.findRenderedComponentWithType(component, SimpleTextEditor)
expect(Editor).toBeDefined();
});



});
10 changes: 10 additions & 0 deletions test/StubComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var React = require('react');

module.exports = function(mockTagName: string){
return React.createClass({
render: function() {
var mockTagName = mockTagName || "div";
return React.DOM[mockTagName](null, this.props.children);
}
});
};
12 changes: 5 additions & 7 deletions test/coverage/test-results.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<?xml version="1.0"?>
<testsuites>
<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">
<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">
<properties>
<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"/>
</properties>
<testcase name="should create a new instance of Grid" time="0.143" classname="PhantomJS 1.9.8 (Windows 7).Grid"/>
<system-out><![CDATA[PhantomJS 1.9.8 (Windows 7) WARN: 'Warning: Invalid prop `rowGetter` of type `array` supplied to `ReactDataGrid`, expected `function`.'
,PhantomJS 1.9.8 (Windows 7) WARN: 'Warning: Invalid prop `width` of type `string` supplied to `ReactDataGrid`, expected `number`.'
,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`.'
,PhantomJS 1.9.8 (Windows 7) WARN: 'Warning: Required prop `totalWidth` was not specified in `Viewport`. Check the render method of `Grid`.'
<testcase name="should create a new instance of Grid" time="0.011" classname="PhantomJS 1.9.8 (Windows 7).Grid"/>
<testcase name="should create a new EditorContainer instance" time="0.012" classname="PhantomJS 1.9.8 (Windows 7).Editor Container Tests"/>
<testcase name="should render a simpleTextEditor if no column.editor property" time="0.002" classname="PhantomJS 1.9.8 (Windows 7).Editor Container Tests"/>
<system-out><![CDATA[
]]></system-out>
<system-err/>
</testsuite>
Expand Down

0 comments on commit 50194da

Please sign in to comment.