Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(th-has-data-cells): fail when data cell points to a different header #2094

Merged
merged 1 commit into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions lib/checks/tables/th-has-data-cells.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,29 @@ headers.forEach(header => {

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

// ensure column header has at least 1 non-header cell
// ensure column header has at least 1 non-header cell and that the cell is
// not pointing to a different header
let hasCell = false;
if (tableUtils.isColumnHeader(header)) {
hasCell = tableUtils
.traverse('down', pos, tableGrid)
.find(cell => !tableUtils.isColumnHeader(cell));
.find(
cell =>
!tableUtils.isColumnHeader(cell) &&
tableUtils.getHeaders(cell, tableGrid).includes(header)
);
}

// ensure row header has at least 1 non-header cell
// ensure row header has at least 1 non-header cell and that the cell is not
// pointing to a different header
if (!hasCell && tableUtils.isRowHeader(header)) {
hasCell = tableUtils
.traverse('right', pos, tableGrid)
.find(cell => !tableUtils.isRowHeader(cell));
.find(
cell =>
!tableUtils.isRowHeader(cell) &&
tableUtils.getHeaders(cell, tableGrid).includes(header)
);
}

// report the node as having failed
Expand Down
20 changes: 20 additions & 0 deletions test/checks/tables/th-has-data-cells.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,26 @@ describe('th-has-data-cells', function() {
);
});

it('should return undefined if table cell points to a different header', function() {
fixture.innerHTML =
'<table>' +
'<tr>' +
'<th id="col1">Column 1</th>' +
'<th id="Column2">Column 2</th>' +
'</tr>' +
'<tr>' +
'<td></td>' +
'<td headers="col1"></td>' +
'</tr>' +
'</table>';

axe.testUtils.flatTreeSetup(fixture);
var node = fixture.querySelector('table');
assert.isUndefined(
checks['th-has-data-cells'].evaluate.call(checkContext, node)
);
});

(shadowSupport ? it : xit)('recognizes shadow tree content', function() {
fixture.innerHTML = '<div id="shadow"> <b>data</b> </div>';
var shadow = fixture
Expand Down