forked from nishp1/react-datagrid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added string and function dataSource tests
- Loading branch information
1 parent
9409b38
commit ec57c96
Showing
2 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
'use strict'; | ||
|
||
//ensure DOM environment | ||
require('../testdom')() | ||
|
||
var React = require('react/addons') | ||
var TestUtils = React.addons.TestUtils | ||
var DataGrid = require('../DataGrid') | ||
|
||
var TABLE_CLASS = 'z-table' | ||
var ROW_CLASS = 'z-row' | ||
var REMOTE_DATA = 'http://5.101.99.47:8090/10' | ||
var REMOTE_DATA_OPTIONS = '?pageSize=20&page=1&skip=0' | ||
|
||
var testUtils = require('../utils') | ||
|
||
var render = testUtils.render | ||
var findWithClass = testUtils.findWithClass | ||
var tryWithClass = testUtils.tryWithClass | ||
|
||
describe('DataGrid Test Suite - DataSource', function(){ | ||
|
||
it('check dataSource supported format : array',function(done) { | ||
|
||
var data = [{ id: 0, index: 1, firstName: 'John', city: 'London', email: '[email protected]'}]; | ||
var columns = [ | ||
{ name: 'index', title: '#', width: 50 }, | ||
{ name: 'firstName'}, | ||
{ name: 'lastName' }, | ||
{ name: 'city' }, | ||
{ name: 'email' } | ||
]; | ||
|
||
// table with column menu | ||
var table = render( | ||
DataGrid({ | ||
idProperty: 'id', | ||
dataSource: data, | ||
columns : columns | ||
}) | ||
) | ||
|
||
var rows = tryWithClass(table,ROW_CLASS); | ||
rows.length.should.equal(1); | ||
|
||
done() | ||
|
||
}) | ||
|
||
it('check dataSource supported format : string',function(done) { | ||
|
||
// create mock fetchData | ||
|
||
var fetchData = function(url) { | ||
url.should.be.equal(REMOTE_DATA + REMOTE_DATA_OPTIONS); | ||
var data = { | ||
data : [ | ||
{ id: 0, index: 1, firstName: 'John', city: 'London', email: '[email protected]'} | ||
], | ||
count:1 | ||
}; | ||
var promise = new Promise(function(resolve,reject) { | ||
resolve(data); | ||
}) | ||
return promise; | ||
} | ||
|
||
var columns = [ | ||
{ name: 'index', title: '#', width: 50 }, | ||
{ name: 'firstName'}, | ||
{ name: 'lastName' }, | ||
{ name: 'city' }, | ||
{ name: 'email' } | ||
]; | ||
|
||
// table with column menu | ||
var table = render( | ||
DataGrid({ | ||
idProperty: 'id', | ||
dataSource: REMOTE_DATA, | ||
columns : columns, | ||
style : {height:200}, | ||
fetch : fetchData | ||
}) | ||
); | ||
|
||
// set time to resolve promise and render table | ||
setTimeout(function() { | ||
var rows = tryWithClass(table,ROW_CLASS); | ||
rows.length.should.equal(1); | ||
done(); | ||
},0) | ||
|
||
}) | ||
|
||
it('check dataSource supported format : function',function(done) { | ||
|
||
// create mock dataSource function | ||
|
||
var dataSource = function() { | ||
var data = { | ||
data : [ | ||
{ id: 0, index: 1, firstName: 'John', city: 'London', email: '[email protected]'} | ||
], | ||
count:1 | ||
}; | ||
var promise = new Promise(function(resolve,reject) { | ||
resolve(data); | ||
}) | ||
return promise; | ||
} | ||
|
||
var columns = [ | ||
{ name: 'index', title: '#', width: 50 }, | ||
{ name: 'firstName'}, | ||
{ name: 'lastName' }, | ||
{ name: 'city' }, | ||
{ name: 'email' } | ||
]; | ||
|
||
// table with column menu | ||
var table = render( | ||
DataGrid({ | ||
idProperty: 'id', | ||
dataSource: dataSource, | ||
columns : columns, | ||
style : {height:200} | ||
}) | ||
); | ||
|
||
// set time to resolve promise and render table | ||
setTimeout(function() { | ||
var rows = tryWithClass(table,ROW_CLASS); | ||
rows.length.should.equal(1); | ||
done(); | ||
},0) | ||
}) | ||
|
||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters