Skip to content

Commit

Permalink
add table header tests
Browse files Browse the repository at this point in the history
for #1015
  • Loading branch information
gordonwoodhull committed Dec 22, 2015
1 parent 58fe586 commit 9473156
Showing 1 changed file with 110 additions and 72 deletions.
182 changes: 110 additions & 72 deletions spec/data-table-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,75 +35,90 @@ describe('dc.dataTable', function () {
return d.status;
}]
);
chart.render();
});

describe('creation', function () {
it('generates something', function () {
expect(chart).not.toBeNull();
});
it('registers', function () {
expect(dc.hasChart(chart)).toBeTruthy();
});
it('sets size', function () {
expect(chart.size()).toEqual(3);
});
it('sets sortBy', function () {
expect(chart.sortBy()).not.toBeNull();
});
it('sets order', function () {
expect(chart.order()).toBe(d3.descending);
});
it('group should be set', function () {
expect(chart.group()).toEqual(valueGroup);
});
it('group tr should not be undefined', function () {
expect(typeof(chart.selectAll('tr.dc-table-group')[0][0])).not.toBe('undefined');
});
it('sets column span set on group tr', function () {
expect(chart.selectAll('tr.dc-table-group td')[0][0].getAttribute('colspan')).toEqual('2');
});
it('creates id column', function () {
expect(chart.selectAll('td._0')[0][0].innerHTML).toEqual('9');
expect(chart.selectAll('td._0')[0][1].innerHTML).toEqual('8');
expect(chart.selectAll('td._0')[0][2].innerHTML).toEqual('3');
});
it('creates status column', function () {
expect(chart.selectAll('td._1')[0][0].innerHTML).toEqual('T');
expect(chart.selectAll('td._1')[0][1].innerHTML).toEqual('F');
expect(chart.selectAll('td._1')[0][2].innerHTML).toEqual('T');
});
});

describe('slicing entries', function () {
describe('simple table', function () {
beforeEach(function () {
chart.beginSlice(1);
chart.redraw();
chart.render();
});

it('slice beginning', function () {
expect(chart.selectAll('tr.dc-table-row')[0].length).toEqual(2);
describe('creation', function () {
it('generates something', function () {
expect(chart).not.toBeNull();
});
it('registers', function () {
expect(dc.hasChart(chart)).toBeTruthy();
});
it('sets size', function () {
expect(chart.size()).toEqual(3);
});
it('sets sortBy', function () {
expect(chart.sortBy()).not.toBeNull();
});
it('sets order', function () {
expect(chart.order()).toBe(d3.descending);
});
it('group should be set', function () {
expect(chart.group()).toEqual(valueGroup);
});
it('group tr should not be undefined', function () {
expect(typeof(chart.selectAll('tr.dc-table-group')[0][0])).not.toBe('undefined');
});
it('sets column span set on group tr', function () {
expect(chart.selectAll('tr.dc-table-group td')[0][0].getAttribute('colspan')).toEqual('2');
});
it('creates id column', function () {
expect(chart.selectAll('td._0')[0][0].innerHTML).toEqual('9');
expect(chart.selectAll('td._0')[0][1].innerHTML).toEqual('8');
expect(chart.selectAll('td._0')[0][2].innerHTML).toEqual('3');
});
it('creates status column', function () {
expect(chart.selectAll('td._1')[0][0].innerHTML).toEqual('T');
expect(chart.selectAll('td._1')[0][1].innerHTML).toEqual('F');
expect(chart.selectAll('td._1')[0][2].innerHTML).toEqual('T');
});
});

it('slice beginning and end', function () {
chart.endSlice(2);
chart.redraw();
describe('slicing entries', function () {
beforeEach(function () {
chart.beginSlice(1);
chart.redraw();
});

expect(chart.selectAll('tr.dc-table-row')[0].length).toEqual(1);
});
});
it('slice beginning', function () {
expect(chart.selectAll('tr.dc-table-row')[0].length).toEqual(2);
});

describe('external filter', function () {
beforeEach(function () {
countryDimension.filter('CA');
chart.redraw();
it('slice beginning and end', function () {
chart.endSlice(2);
chart.redraw();

expect(chart.selectAll('tr.dc-table-row')[0].length).toEqual(1);
});
});
it('renders only filtered data set', function () {
expect(chart.selectAll('td._0')[0].length).toEqual(2);

describe('external filter', function () {
beforeEach(function () {
countryDimension.filter('CA');
chart.redraw();
});
it('renders only filtered data set', function () {
expect(chart.selectAll('td._0')[0].length).toEqual(2);
});
it('renders the correctly filtered records', function () {
expect(chart.selectAll('td._0')[0][0].innerHTML).toEqual('7');
expect(chart.selectAll('td._0')[0][1].innerHTML).toEqual('5');
});
});
it('renders the correctly filtered records', function () {
expect(chart.selectAll('td._0')[0][0].innerHTML).toEqual('7');
expect(chart.selectAll('td._0')[0][1].innerHTML).toEqual('5');

describe('ascending order', function () {
beforeEach(function () {
chart.order(d3.ascending);
chart.redraw();
});
it('uses dimension.bottom() instead of top()', function () {
expect(chart.selectAll('td._0')[0][0].innerHTML).toEqual('1');
});
});
});

Expand All @@ -128,16 +143,6 @@ describe('dc.dataTable', function () {
});
});

describe('ascending order', function () {
beforeEach(function () {
chart.order(d3.ascending);
chart.redraw();
});
it('uses dimension.bottom() instead of top()', function () {
expect(chart.selectAll('td._0')[0][0].innerHTML).toEqual('1');
});
});

describe('specifying chart columns with label', function () {
beforeEach(function () {
chart.columns(['state']);
Expand Down Expand Up @@ -182,14 +187,47 @@ describe('dc.dataTable', function () {
}]);
chart.render();
});
it('should render result of calling function with field and header for label', function () {
it('should produce correct table header with single column', function () {
var thead = chart.selectAll('thead');
expect(thead.length).toBe(1);
var tr = thead.selectAll('tr');
expect(tr.length).toBe(1);
var colheader = tr.selectAll('th.dc-table-head')[0].map(function (d) {return d.textContent;});
expect(colheader.length).toEqual(1);
expect(colheader[0]).toEqual('Test ID');
});

it('should render correct values in rows', function () {
var cols = chart.selectAll('td.dc-table-column')[0].map(function (d) {return d.textContent;});
var expected = ['test9', 'test8', 'test3'];
expect(cols.length).toEqual(expected.length);
expected.forEach(function (d) {
expect(cols).toContain(d);
expected.forEach(function (d, i) {
expect(cols[i]).toEqual(d);
});
var colheader = chart.selectAll('th.dc-table-head')[0].map(function (d) {return d.textContent;});
});
});

describe('with existing table header', function () {
beforeEach(function () {
// add some garbage for table to replace
d3.select('#data-table')
.selectAll('thead').data([0]).enter().append('thead')
.selectAll('tr').data([1,2]).enter().append('tr')
.selectAll('th').data([1,2,3]).enter().append('th');
chart.columns([{
label: 'Test ID',
format: function (d) {
return 'test' + d.id;
}
}]);
chart.render();
});
it('should produce correct table header with single column', function () {
var thead = chart.selectAll('thead');
expect(thead.length).toBe(1);
var tr = thead.selectAll('tr');
expect(tr.length).toBe(1);
var colheader = tr.selectAll('th.dc-table-head')[0].map(function (d) {return d.textContent;});
expect(colheader.length).toEqual(1);
expect(colheader[0]).toEqual('Test ID');
});
Expand Down

0 comments on commit 9473156

Please sign in to comment.