From c7489aba9a1498e389d003d30700aaa024d90fc1 Mon Sep 17 00:00:00 2001 From: Steven Lambert Date: Mon, 8 Jul 2019 08:51:09 -0600 Subject: [PATCH] fix(th-has-data-cells): empty cells will now pass (#1659) * fix(th-has-data-cells): empty cells will now pass * filter headers * fix test * find instead of filter * move test to passes --- lib/checks/tables/th-has-data-cells.js | 14 ++++---------- test/checks/tables/th-has-data-cells.js | 4 ++-- .../full/incomplete/th-has-data-cells.html | 11 ----------- .../full/incomplete/th-has-data-cells.js | 2 +- .../rules/th-has-data-cells/th-has-data-cells.html | 11 +++++++++++ .../rules/th-has-data-cells/th-has-data-cells.json | 3 ++- 6 files changed, 20 insertions(+), 25 deletions(-) diff --git a/lib/checks/tables/th-has-data-cells.js b/lib/checks/tables/th-has-data-cells.js index 2bab2164c1..9b46be722f 100644 --- a/lib/checks/tables/th-has-data-cells.js +++ b/lib/checks/tables/th-has-data-cells.js @@ -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 diff --git a/test/checks/tables/th-has-data-cells.js b/test/checks/tables/th-has-data-cells.js index 3507734a16..850705fed7 100644 --- a/test/checks/tables/th-has-data-cells.js +++ b/test/checks/tables/th-has-data-cells.js @@ -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 = '' + ' ' + @@ -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) ); }); diff --git a/test/integration/full/incomplete/th-has-data-cells.html b/test/integration/full/incomplete/th-has-data-cells.html index 4aec27f427..187d4ad934 100644 --- a/test/integration/full/incomplete/th-has-data-cells.html +++ b/test/integration/full/incomplete/th-has-data-cells.html @@ -30,17 +30,6 @@
hi
- - - - - - - - - -
hi
hi
- diff --git a/test/integration/full/incomplete/th-has-data-cells.js b/test/integration/full/incomplete/th-has-data-cells.js index 82b165df24..5f26a53293 100644 --- a/test/integration/full/incomplete/th-has-data-cells.js +++ b/test/integration/full/incomplete/th-has-data-cells.js @@ -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'); }); diff --git a/test/integration/rules/th-has-data-cells/th-has-data-cells.html b/test/integration/rules/th-has-data-cells/th-has-data-cells.html index ba04856ee5..43a44421fd 100644 --- a/test/integration/rules/th-has-data-cells/th-has-data-cells.html +++ b/test/integration/rules/th-has-data-cells/th-has-data-cells.html @@ -61,6 +61,17 @@
axe
+ + + + + + + + + +
hi
hi
+ diff --git a/test/integration/rules/th-has-data-cells/th-has-data-cells.json b/test/integration/rules/th-has-data-cells/th-has-data-cells.json index 2fe908052f..6bec1f1b27 100644 --- a/test/integration/rules/th-has-data-cells/th-has-data-cells.json +++ b/test/integration/rules/th-has-data-cells/th-has-data-cells.json @@ -14,6 +14,7 @@ ["#pass4"], ["#pass5"], ["#pass6"], - ["#pass7"] + ["#pass7"], + ["#pass8"] ] }
axe