Skip to content

Commit

Permalink
fix(th-has-data-cells): empty cells will now pass (#1659)
Browse files Browse the repository at this point in the history
* fix(th-has-data-cells): empty cells will now pass

* filter headers

* fix test

* find instead of filter

* move test to passes
  • Loading branch information
straker committed Jul 8, 2019
1 parent c64bd02 commit c7489ab
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 25 deletions.
14 changes: 4 additions & 10 deletions lib/checks/tables/th-has-data-cells.js
Expand Up @@ -40,25 +40,19 @@ headers.forEach(header => {

const pos = tableUtils.getCellPosition(header, tableGrid);

// look for any column cell that has content and is not a column header
// ensure column header has at least 1 non-header cell
let hasCell = false;
if (tableUtils.isColumnHeader(header)) {
hasCell = tableUtils
.traverse('down', pos, tableGrid)
.some(
cell =>
axe.commons.dom.hasContent(cell) && !tableUtils.isColumnHeader(cell)
);
.find(cell => !tableUtils.isColumnHeader(cell));
}

// look for any row cell that has content and is not a row header
// ensure row header has at least 1 non-header cell
if (!hasCell && tableUtils.isRowHeader(header)) {
hasCell = tableUtils
.traverse('right', pos, tableGrid)
.some(
cell =>
axe.commons.dom.hasContent(cell) && !tableUtils.isRowHeader(cell)
);
.find(cell => !tableUtils.isRowHeader(cell));
}

// report the node as having failed
Expand Down
4 changes: 2 additions & 2 deletions test/checks/tables/th-has-data-cells.js
Expand Up @@ -112,7 +112,7 @@ describe('th-has-data-cells', function() {
);
});

it('should return undefined if all data cells are empty', function() {
it('should return true if all data cells are empty', function() {
fixture.innerHTML =
'<table>' +
' <tr> <th>hi</th> <td></td> </tr>' +
Expand All @@ -121,7 +121,7 @@ describe('th-has-data-cells', function() {

axe.testUtils.flatTreeSetup(fixture);
var node = fixture.querySelector('table');
assert.isUndefined(
assert.isTrue(
checks['th-has-data-cells'].evaluate.call(checkContext, node)
);
});
Expand Down
11 changes: 0 additions & 11 deletions test/integration/full/incomplete/th-has-data-cells.html
Expand Up @@ -30,17 +30,6 @@
</tr>
</table>

<table id="table2">
<tr>
<th>hi</th>
<td></td>
</tr>
<tr>
<th>hi</th>
<td></td>
</tr>
</table>

<table id="table3">
<tr>
<td>axe</td>
Expand Down
2 changes: 1 addition & 1 deletion test/integration/full/incomplete/th-has-data-cells.js
Expand Up @@ -29,7 +29,7 @@ describe('th-has-data-cells cantTell test', function() {
describe('incomplete data', function() {
it('should be incomplete for missing or empty data cells', function() {
var resultNodes = results.incomplete[0].nodes;
assert.lengthOf(resultNodes, 3);
assert.lengthOf(resultNodes, 2);
resultNodes[0].any.forEach(function(check) {
assert.match(check.message, 'Table data cells are missing or empty');
});
Expand Down
11 changes: 11 additions & 0 deletions test/integration/rules/th-has-data-cells/th-has-data-cells.html
Expand Up @@ -61,6 +61,17 @@
</tr>
</table>

<table id="pass8">
<tr>
<th>hi</th>
<td></td>
</tr>
<tr>
<th>hi</th>
<td></td>
</tr>
</table>

<table id="canttell1">
<tr>
<td>axe</td>
Expand Down
Expand Up @@ -14,6 +14,7 @@
["#pass4"],
["#pass5"],
["#pass6"],
["#pass7"]
["#pass7"],
["#pass8"]
]
}

0 comments on commit c7489ab

Please sign in to comment.