Skip to content

Commit

Permalink
update the rule and test results #1472
Browse files Browse the repository at this point in the history
  • Loading branch information
shunguoy committed Aug 29, 2023
1 parent 7036380 commit 89823ae
Show file tree
Hide file tree
Showing 10 changed files with 261 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ export class RPTUtil {

// Return true if a table cell is hidden or contain no data: <td></td>
public static isTableCellEmpty(cell) {
if (!cell || !VisUtil.isNodeVisible(cell) || cell.innerHTML.trim().length === 0)
if (!cell || !VisUtil.isNodeVisible(cell) || cell.innerHTML.replace(/&nbsp;/g,' ').trim().length === 0)
return true;

return false;
Expand Down Expand Up @@ -1156,7 +1156,7 @@ export class RPTUtil {
// Check if the cells with data in the first data row are all TH's
passed = true;
for (let r=0; passed && r < firstRow.cells.length; r++) {
let cell = firstRow.cells[r];
let cell = firstRow.cells[r];
passed = RPTUtil.isTableCellEmpty(cell) || cell.nodeName.toLowerCase() === 'th';
}

Expand All @@ -1182,15 +1182,15 @@ export class RPTUtil {

//case 3: all td data cells have headers attributes that point to the id of a th element in the same table.
// https://html.spec.whatwg.org/multipage/tables.html#attributes-common-to-td-and-th-elements
passed = true;
passed = true;
let thIds = [];
let tdHeaders = [];
for (let r=0; passed && r < rows.length; r++) {
let row = rows[r];
let row = rows[r];
// Check if the cells with data in the last data row are all TH's
for (let c=0; c < row.cells.length; c++) {
let cell = row.cells[c];
if (RPTUtil.isTableCellEmpty(cell)) continue;
if (RPTUtil.isTableCellEmpty(cell)) continue;
if (cell.nodeName.toLowerCase() === 'td') {
if (!cell.getAttribute('headers') || cell.getAttribute('headers').trim().length === 0)
passed = false;
Expand All @@ -1200,12 +1200,12 @@ export class RPTUtil {
RPTUtil.concatUniqueArrayItem(cell.getAttribute('id').trim(), thIds);
}
}

if (passed) { // all td elements have headers, to exam if the headers point to a th id
if (thIds.length > 0 && tdHeaders.some(header => thIds.includes(header)))
return true;
if (thIds.length > 0 && tdHeaders.every(header => thIds.includes(header)))
return true;
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@
UnitTest = {
ruleIds: ["table_headers_exists"],
results: [
{
{
"ruleId": "table_headers_exists",
"value": [
"INFORMATION",
"PASS"
"FAIL"
],
"path": {
"dom": "/html[1]/body[1]/table[1]",
"aria": "/document[1]/table[1]"
},
"reasonId": "Pass_0",
"message": "Rule Passed",
"reasonId": "Fail_1",
"message": "Table has no headers identified",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,18 @@
UnitTest = {
ruleIds: ["table_headers_exists"],
results: [
{
{
"ruleId": "table_headers_exists",
"value": [
"INFORMATION",
"PASS"
"FAIL"
],
"path": {
"dom": "/html[1]/body[1]/table[1]",
"aria": "/document[1]/table[1]"
},
"reasonId": "Pass_0",
"message": "Rule Passed",
"reasonId": "Fail_1",
"message": "Table has no headers identified",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,25 @@
<table id="vertical-1">
<caption>Column Headers in first cells</caption>
<tr>
<td>data</td>
<th>row Header 1</th>
<td headers="">data</td>
<th id="1">row Header 1</th>
<td>data</td>
<td>data</td>
</tr>
<tr>

<td>data</td>
<th>row Header 2</th>
<th id="2">row Header 2</th>
<td>data</td>
<td>data</td>
</tr>
<tr>

<td>data</td>
<th>row Header 3</th>
<th id="3">row Header 3</th>
<td>data</td>
<td>data</td>
</tr>
<tfoot>
<tr>
<td colspan="3">Footer</td>
</tr>
</tfoot>
</table>
<script>
UnitTest = {
Expand All @@ -63,14 +58,14 @@
"ruleId": "table_headers_exists",
"value": [
"INFORMATION",
"PASS"
"FAIL"
],
"path": {
"dom": "/html[1]/body[1]/table[1]",
"aria": "/document[1]/table[1]"
},
"reasonId": "Pass_0",
"message": "Rule Passed",
"reasonId": "Fail_1",
"message": "Table has no headers identified",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@
"ruleId": "table_headers_exists",
"value": [
"INFORMATION",
"PASS"
"FAIL"
],
"path": {
"dom": "/html[1]/body[1]/table[1]",
"aria": "/document[1]/table[1]"
},
"reasonId": "Pass_0",
"message": "Rule Passed",
"reasonId": "Fail_1",
"message": "Table has no headers identified",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
<!--
/******************************************************************************
Copyright:: 2020- IBM, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*****************************************************************************/
-->

<head>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">
#vertical-1 thead,#vertical-1 tbody, th, td, tfoot {
border: 1px solid black;
}
</style>
</head>
<body>
<table id="vertical-1">
<caption>Column Headers in first cells</caption>
<tr>
<td headers="row1">data</td>
<td headers="row1">data</td>
<th id="row1">Header 1</th>
<td headers="row1">data</td>
</tr>
<tr>
<td headers="row2">data</td>
<td headers="row2">data</td>
<th id="row2">Header 2</th>
<td headers="row2">data</td>
</tr>
<tr>
<td headers="row3">data</td>
<td headers="row3">data</td>
<th id="row3">Header 2</th>
<td headers="row3">data</td>
</tr>
</table>
<script>
UnitTest = {
ruleIds: ["table_headers_exists"],
results: [
{
"ruleId": "table_headers_exists",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/table[1]",
"aria": "/document[1]/table[1]"
},
"reasonId": "Pass_0",
"message": "Rule Passed",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
}
]
};
</script>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
<!--
/******************************************************************************
Copyright:: 2020- IBM, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*****************************************************************************/
-->

<head>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">
#vertical-1 thead,#vertical-1 tbody, th, td, tfoot {
border: 1px solid black;
}
</style>
</head>
<body>
<table id="vertical-1">
<caption>Column Headers in first cells</caption>
<tr>
<td>data</td>
<td headers="row1">data</td>
<th id="row1">Header 1</th>
<td headers="row1">data</td>
</tr>
<tr>
<td headers="row2">data</td>
<td headers="row2">data</td>
<th id="row2">Header 2</th>
<td headers="row2">data</td>
</tr>
<tr>
<td headers="row3">data</td>
<td headers="row3">data</td>
<th id="row3">Header 2</th>
<td headers="row3">data</td>
</tr>
</table>
<script>
UnitTest = {
ruleIds: ["table_headers_exists"],
results: [
{
"ruleId": "table_headers_exists",
"value": [
"INFORMATION",
"FAIL"
],
"path": {
"dom": "/html[1]/body[1]/table[1]",
"aria": "/document[1]/table[1]"
},
"reasonId": "Fail_1",
"message": "Table has no headers identified",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
}
]
};
</script>

</body>
</html>
Loading

0 comments on commit 89823ae

Please sign in to comment.