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 styling checks as per test plan
- Loading branch information
1 parent
de3e937
commit 75cd50c
Showing
1 changed file
with
122 additions
and
0 deletions.
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,122 @@ | ||
'use strict'; | ||
|
||
var DataGrid = require('../DataGrid') | ||
var React = require('react/addons') | ||
var TestUtils = React.addons.TestUtils | ||
|
||
var TABLE_CLASS = 'z-table' | ||
var ROW_CLASS = 'z-row' | ||
var CELL_CLASS = 'z-cell' | ||
var CELL_TEXT_CLASS = 'z-text' | ||
|
||
var testUtils = require('../utils') | ||
|
||
var render = testUtils.render | ||
var findWithClass = testUtils.findWithClass | ||
var tryWithClass = testUtils.tryWithClass | ||
var generateMockData = testUtils.generateMockData | ||
|
||
var columns = [ | ||
{ name: 'index', title: '#', width: 50 }, | ||
{ name: 'firstName'}, | ||
{ name: 'lastName' }, | ||
{ name: 'city' }, | ||
{ name: 'email' } | ||
]; | ||
|
||
describe('DataGrid Test Suite - Row Style',function() { | ||
|
||
it('check rowStyle as object works',function() { | ||
|
||
var ROW_COLOR = 'blue' | ||
var data = generateMockData({type : 'local', len : 3}) | ||
|
||
var rowStyle = {color : ROW_COLOR} | ||
|
||
// table | ||
var table = render( | ||
DataGrid({ | ||
idProperty: 'id', | ||
dataSource: data, | ||
columns : columns, | ||
style : {height:400}, | ||
rowStyle : rowStyle | ||
}) | ||
); | ||
|
||
var rows = tryWithClass(table,ROW_CLASS) | ||
rows.forEach(function(row) { | ||
window.getComputedStyle(row.getDOMNode()).getPropertyValue('color').should.equal(ROW_COLOR) | ||
}) | ||
|
||
}) | ||
|
||
it('check rowStyle as function works',function() { | ||
|
||
var ROW_COLOR = 'blue' | ||
var ROW_COLOR_INDEX = 4 | ||
var data = generateMockData({type : 'local', len : 10}) | ||
|
||
var rowStyle = function(data, props){ | ||
var style = {} | ||
if (props.index % ROW_COLOR_INDEX == 0){ | ||
style.color = ROW_COLOR | ||
} | ||
return style | ||
} | ||
|
||
// table | ||
var table = render( | ||
DataGrid({ | ||
idProperty: 'id', | ||
dataSource: data, | ||
columns : columns, | ||
style : {height:400}, | ||
rowStyle : rowStyle | ||
}) | ||
); | ||
|
||
var rows = tryWithClass(table,ROW_CLASS) | ||
rows.forEach(function(row,index) { | ||
if(index % ROW_COLOR_INDEX == 0) | ||
window.getComputedStyle(row.getDOMNode()).getPropertyValue('color').should.equal(ROW_COLOR) | ||
}) | ||
|
||
}) | ||
|
||
it('check column style works',function() { | ||
|
||
var COL_COLOR = 'blue' | ||
var COL_COLOR_INDEX = 4 | ||
var data = generateMockData({type : 'local', len : 10}) | ||
|
||
columns = [ | ||
{ name: 'index', title: '#', width: 50 }, | ||
{ name: 'firstName'}, | ||
{ name: 'lastName' }, | ||
{ name: 'city' }, | ||
{ name: 'email', style : { color : COL_COLOR } } | ||
] | ||
|
||
// table | ||
var table = render( | ||
DataGrid({ | ||
idProperty: 'id', | ||
dataSource: data, | ||
columns : columns, | ||
style : {height:400} | ||
}) | ||
); | ||
|
||
var rows = tryWithClass(table,ROW_CLASS) | ||
rows.forEach(function(row) { | ||
var cells = tryWithClass(row,CELL_CLASS) | ||
cells.forEach(function(cell,index) { | ||
if(index == COL_COLOR_INDEX) | ||
window.getComputedStyle(cell.getDOMNode()).getPropertyValue('color').should.equal(COL_COLOR) | ||
}) | ||
}) | ||
|
||
}) | ||
|
||
}) |