Skip to content

Commit

Permalink
Added string and function dataSource tests
Browse files Browse the repository at this point in the history
  • Loading branch information
koustuvsinha committed May 6, 2015
1 parent 9409b38 commit ec57c96
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 1 deletion.
140 changes: 140 additions & 0 deletions test/dataSource/DataGridDataSourceTest.js
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)
})

});

2 changes: 1 addition & 1 deletion test/rendering/DataGridRenderingTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var render = testUtils.render
var findWithClass = testUtils.findWithClass
var tryWithClass = testUtils.tryWithClass

describe('DataGrid Test Suite - Rendering & DataSource', function(){
describe('DataGrid Test Suite - Rendering', function(){

it('Check loading controlled prop works as expected',function(done) {

Expand Down

0 comments on commit ec57c96

Please sign in to comment.