Skip to content
This repository has been archived by the owner on Jun 15, 2019. It is now read-only.

Commit

Permalink
reformat some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamestalmage committed Dec 19, 2014
1 parent b311dfa commit 19f9805
Showing 1 changed file with 46 additions and 62 deletions.
108 changes: 46 additions & 62 deletions test/table-layout-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,19 +244,18 @@ describe('tableLayout', function () {
});

describe('computeWidths',function() {
function mc(desiredWidth, colSpan) {
return {desiredWidth: desiredWidth, colSpan: colSpan};
function mc(y,x,desiredWidth, colSpan) {
return {x:x,y:y,desiredWidth:desiredWidth,colSpan:colSpan};
}

it('finds the maximum desired width of each column', function () {
var widths = [];
var cells = [
[mc(7), mc(3), mc(5)],
[mc(8), mc(5), mc(2)],
[mc(6), mc(9), mc(1)]
[mc(0,0,7), mc(0,1,3), mc(0,2,5)],
[mc(1,0,8), mc(1,1,5), mc(1,2,2)],
[mc(2,0,6), mc(2,1,9), mc(2,2,1)]
];

layoutTable(cells);
computeWidths(widths, cells);

expect(widths).to.eql([8, 9, 5]);
Expand All @@ -265,110 +264,101 @@ describe('tableLayout', function () {
it('won\'t touch hard coded values', function () {
var widths = [null, 3];
var cells = [
[mc(7), mc(3), mc(5)],
[mc(8), mc(5), mc(2)],
[mc(6), mc(9), mc(1)]
[mc(0,0,7), mc(0,1,3), mc(0,2,5)],
[mc(1,0,8), mc(1,1,5), mc(1,2,2)],
[mc(2,0,6), mc(2,1,9), mc(2,2,1)]
];

layoutTable(cells);
computeWidths(widths, cells);

expect(widths).to.eql([8, 3, 5]);
});

it('assumes undefined desiredWidth is 0', function () {
var widths = [];
var cells = [[{}], [{}], [{}]];
layoutTable(cells);
var cells = [[{x:0,y:0}], [{x:0,y:1}], [{x:0,y:2}]];
computeWidths(widths, cells);
expect(widths).to.eql([0])
});

it('takes into account colSpan and wont over expand', function () {
var widths = [];
var cells = [
[mc(10, 2), mc(5)],
[mc(5), mc(5), mc(2)],
[mc(4), mc(2), mc(1)]
[mc(0,0,10, 2), mc(0,2,5)],
[mc(1,0,5), mc(1,1,5), mc(1,2,2)],
[mc(2,0,4), mc(2,1,2), mc(2,2,1)]
];
layoutTable(cells);
computeWidths(widths, cells);
expect(widths).to.eql([5, 5, 5]);
});

it('will expand rows involved in colSpan in a balanced way', function () {
var widths = [];
var cells = [
[mc(13, 2), mc(5)],
[mc(5), mc(5), mc(2)],
[mc(4), mc(2), mc(1)]
[mc(0,0,13,2), mc(0,2,5)],
[mc(1,0,5), mc(1,1,5), mc(1,2,2)],
[mc(2,0,4), mc(2,1,2), mc(2,2,1)]
];
layoutTable(cells);
computeWidths(widths, cells);
expect(widths).to.eql([6, 6, 5]);
});

it('expands across 3 cols', function () {
var widths = [];
var cells = [
[mc(25, 3)],
[mc(5), mc(5), mc(2)],
[mc(4), mc(2), mc(1)]
[mc(0,0,25,3) ],
[mc(1,0,5), mc(1,1,5), mc(1,2,2) ],
[mc(2,0,4), mc(2,1,2), mc(2,2,1) ]
];
layoutTable(cells);
computeWidths(widths, cells);
expect(widths).to.eql([9, 9, 5]);
});

it('multiple spans in same table', function () {
var widths = [];
var cells = [
[mc(25, 3)],
[mc(30, 3)],
[mc(4), mc(2), mc(1)]
[mc(0,0,25,3) ],
[mc(1,0,30,3) ],
[mc(2,0,4), mc(2,1,2), mc(2,2,1) ]
];
layoutTable(cells);
computeWidths(widths, cells);
expect(widths).to.eql([11, 9, 8]);
});

it('spans will only edit uneditable tables',function(){
var widths = [null, 3];
var cells = [
[mc(20,3)],
[mc(4),mc(20),mc(5)]
[mc(0,0,20,3) ],
[mc(1,0,4), mc(1,1,20), mc(1,2,5) ]
];
layoutTable(cells);
computeWidths(widths, cells);
expect(widths).to.eql([7,3,8])
});

it('spans will only edit uneditable tables - first column uneditable',function(){
var widths = [3];
var cells = [
[mc(20,3)],
[mc(4), mc(3), mc(5)]
[mc(0,0,20,3) ],
[mc(1,0,4), mc(1,1,3), mc(1,2,5) ]
];
layoutTable(cells);
computeWidths(widths, cells);
expect(widths).to.eql([3,7,8])
});
});

describe('computeHeights',function(){
function mc(desiredHeight,colSpan){
return {desiredHeight:desiredHeight,rowSpan:colSpan};
function mc(y,x,desiredHeight,colSpan){
return {x:x,y:y,desiredHeight:desiredHeight,rowSpan:colSpan};
}

it('finds the maximum desired height of each row',function(){
var heights = [];
var cells = [
[mc(7), mc(3), mc(5)],
[mc(8), mc(5), mc(2)],
[mc(6), mc(9), mc(1)]
[mc(0,0,7), mc(0,1,3), mc(0,2,5) ],
[mc(1,0,8), mc(1,1,5), mc(1,2,2) ],
[mc(2,0,6), mc(2,1,9), mc(2,2,1) ]
];

layoutTable(cells);
computeHeights(heights,cells);

expect(heights).to.eql([7,8,9]);
Expand All @@ -377,69 +367,63 @@ describe('tableLayout', function () {
it('won\'t touch hard coded values',function(){
var heights = [null,3];
var cells = [
[mc(7), mc(3), mc(5)],
[mc(8), mc(5), mc(2)],
[mc(6), mc(9), mc(1)]
[mc(0,0,7), mc(0,1,3), mc(0,2,5)],
[mc(1,0,8), mc(1,1,5), mc(1,2,2)],
[mc(2,0,6), mc(2,1,9), mc(2,2,1)]
];

layoutTable(cells);
computeHeights(heights,cells);

expect(heights).to.eql([7,3,9]);
});

it('assumes undefined desiredHeight is 1',function(){
var heights = [];
var cells = [[{},{},{}]];
layoutTable(cells);
var cells = [[{x:0,y:0},{x:1,y:0},{x:2,y:0}]];
computeHeights(heights,cells);
expect(heights).to.eql([1])
});

it('takes into account rowSpan and wont over expand',function(){
var heights = [];
var cells = [
[mc(10,2), mc(5)],
[mc(5), mc(3), mc(2)],
[mc(4), mc(2), mc(1)]
[mc(0,0,10,2), mc(0,1,5), mc(0,2,2)],
[ mc(1,1,5), mc(1,2,2)],
[mc(2,0,4), mc(2,1,2), mc(2,2,1)]
];
layoutTable(cells);
computeHeights(heights,cells);
expect(heights).to.eql([5,5,4]);
});

it('will expand rows involved in rowSpan in a balanced way',function(){
var heights = [];
var cells = [
[mc(13,2), mc(5), mc(5)],
[ mc(5), mc(2)],
[mc(4), mc(2), mc(1)]
[mc(0,0,13,2), mc(0,1,5), mc(0,2,5)],
[ mc(1,1,5), mc(1,2,2)],
[mc(2,0,4), mc(2,1,2), mc(2,2,1)]
];
layoutTable(cells);
computeHeights(heights,cells);
expect(heights).to.eql([6,6,4]);
});

it('expands across 3 rows',function(){
var heights = [];
var cells = [
[mc(25,3), mc(5), mc(4)],
[ mc(5), mc(2)],
[ mc(2), mc(1)]
[mc(0,0,25,3), mc(0,1,5), mc(0,2,4)],
[ mc(1,1,5), mc(1,2,2)],
[ mc(2,1,2), mc(2,2,1)]
];
layoutTable(cells);
computeHeights(heights,cells);
expect(heights).to.eql([9,9,5]);
});

it('multiple spans in same table',function(){
var heights = [];
var cells = [
[mc(25,3), mc(30,3), mc(4)],
[ mc(2)],
[ mc(1)]
[mc(0,0,25,3), mc(0,1,30,3), mc(0,2,4)],
[ mc(1,2,2)],
[ mc(2,2,1)]
];
layoutTable(cells);
computeHeights(heights,cells);
expect(heights).to.eql([11,9,8]);
});
Expand Down

0 comments on commit 19f9805

Please sign in to comment.