Skip to content

Commit e88b7ad

Browse files
committed
Add precondition assertion that header and footer table rows have varying heights in tests
1 parent 63b5b51 commit e88b7ad

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

tests/unit/-private/table-sticky-polyfill-test.js

+28-4
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,23 @@ function verifyFooter(assert) {
114114
* @param assert
115115
*/
116116
function verifyMultiLineHeader(assert) {
117+
let firstTableCellOfEachHeaderRow = findAll('thead > tr > th:first-child');
118+
let tableHeaderCellHeights = firstTableCellOfEachHeaderRow.map(
119+
cell => cell.getBoundingClientRect().height
120+
);
121+
let isAllHeaderCellsIdenticalHeights = tableHeaderCellHeights.every(function(cell, i, array) {
122+
return i === 0 || cell === array[i - 1];
123+
});
117124
let firstCellRect = find('thead tr:first-child th:first-child').getBoundingClientRect();
118125
let expectedOffset = firstCellRect.top;
119126

120-
findAll('thead > tr').forEach(row => {
121-
let firstCellRect = row.firstElementChild.getBoundingClientRect();
127+
assert.notOk(
128+
isAllHeaderCellsIdenticalHeights,
129+
'precond - header table rows have varying heights'
130+
);
131+
132+
firstTableCellOfEachHeaderRow.forEach(cell => {
133+
let firstCellRect = cell.getBoundingClientRect();
122134
expectedOffset += firstCellRect.height;
123135
assert.equal(expectedOffset, firstCellRect.bottom);
124136
});
@@ -129,11 +141,23 @@ function verifyMultiLineHeader(assert) {
129141
* @param assert
130142
*/
131143
function verifyMultiLineFooter(assert) {
144+
let firstTableCellOfEachFooterRow = findAll('tfoot > tr > td:first-child');
145+
let tableFooterCellHeights = firstTableCellOfEachFooterRow.map(
146+
cell => cell.getBoundingClientRect().height
147+
);
148+
let isAllFooterCellsIdenticalHeights = tableFooterCellHeights.every(function(cell, i, array) {
149+
return i === 0 || cell === array[i - 1];
150+
});
132151
let firstCellRect = find('tfoot tr:first-child td:first-child').getBoundingClientRect();
133152
let expectedOffset = firstCellRect.top;
134153

135-
findAll('tfoot > tr').forEach(row => {
136-
let firstCellRect = row.firstElementChild.getBoundingClientRect();
154+
assert.notOk(
155+
isAllFooterCellsIdenticalHeights,
156+
'precond - footer table rows have varying heights'
157+
);
158+
159+
firstTableCellOfEachFooterRow.forEach(cell => {
160+
let firstCellRect = cell.getBoundingClientRect();
137161
expectedOffset += firstCellRect.height;
138162
assert.equal(expectedOffset, firstCellRect.bottom);
139163
});

0 commit comments

Comments
 (0)