Skip to content

Commit

Permalink
update rules and test cases #1472
Browse files Browse the repository at this point in the history
  • Loading branch information
shunguoy committed Aug 23, 2023
1 parent 29cd611 commit 4f75e87
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ export class RPTUtil {
// note that table.rows return all all the rows in the table,
// including the rows contained within <thead>, <tfoot>, and <tbody> elements.

//case 1: header is in the very first row with data
//case 1: headers are in the very first row with data in tbody or thead
//get the first row with data, ignoring the rows with no data
let passed = true;
let firstRow = rows[0];
Expand All @@ -1164,7 +1164,7 @@ export class RPTUtil {
if (passed)
return true;

//case 2: header is in the very last/bottom row with data
//case 2: headers are in the very last/bottom row with data in tbody or thead
//get the last row with data
passed = true;
let lastRow = rows[rows.length-1];
Expand All @@ -1188,8 +1188,32 @@ export class RPTUtil {

if (passed)
return true;

// Case 3: header is in the first columns with data

//case 3: headers are in a row with data in tfoot
let footer = ruleContext.getElementsByTagName("tfoot");
if (footer && footer.length > 0) {
let frows = footer[0].getElementsByTagName("tr");
if (frows && frows.length > 0) {
let frow = frows[0];
for (let r=0; r < frows.length; r++) {
frow = frows[r];
passed = RPTUtil.isTableRowEmpty(frow);
if (passed) continue;
// Check if the cells with data in the last data row are all TH's
passed = true;
for (let r=0; passed && r < frow.cells.length; r++) {
let cell = frow.cells[r];
passed = RPTUtil.isTableCellEmpty(cell) || cell.nodeName.toLowerCase() === 'th';
}

if (passed)
return true;

}
}
}

// Case 4: headers are in the first columns with data
// Assume that the first column has all TH's or a TD without data in the first column.
passed = true;
for (let i = 0; passed && i < rows.length; ++i) {
Expand All @@ -1206,7 +1230,7 @@ export class RPTUtil {
if (passed)
return true;

// Special case - both first row and first column are headers, but they did not use
// Case 5: Special case - both first row and first column are headers, but they did not use
// a th for the upper-left cell
passed = true;
for (let i = 1; passed && i < firstRow.cells.length; ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ <h3>Table Tests</h3>
passedXpaths: [
],
failedXpaths: [
"/html[1]/body[1]/table[1]"
]
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,26 @@
</tbody>
<tfoot>
<tr>
<td colspan="4">Footer</td>
<td colspan="4">Footer content</td>
</tr>
</tfoot>
</table>
<script>
UnitTest = {
ruleIds: ["table_headers_exists"],
results: [
{
{
"ruleId": "table_headers_exists",
"value": [
"INFORMATION",
"FAIL"
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/table[1]",
"aria": "/document[1]/table[1]"
},
"reasonId": "Fail_1",
"message": "Table has no headers identified",
"reasonId": "Pass_0",
"message": "Rule Passed",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,36 @@
<td>data</td>
<td>data</td>
</tr>
<tr>
<th>Header 1</th>
<th >Header 2</th>
<th>Header 3</th>
</tr>

</tbody>
<tfoot>
<tfoot>
<tr></tr>
<tr>
<td colspan="4">Footer</td>
</tr>
<tr>
<th>Header 1</th>
<th >Header 2</th>
<th>Header 3</th>
</tr>
</tfoot>
</table>
<script>
UnitTest = {
ruleIds: ["table_headers_exists"],
results: [
{
{
"ruleId": "table_headers_exists",
"value": [
"INFORMATION",
"FAIL"
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/table[1]",
"aria": "/document[1]/table[1]"
},
"reasonId": "Fail_1",
"message": "Table has no headers identified",
"reasonId": "Pass_0",
"message": "Rule Passed",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
</caption>
<tbody>
<tr>
<td></th>
<td></td>
<td></td>
</tr>
<td>Supplies</th>
<td>8,000</td>
<td>3,000</td>
</tr>
<tr>
<td></th>
<td></td>
<td></td>
<td>Pizza</th>
<td>1,000</td>
<td>500</td>
</tr>
<tr>
<th >Items</th>
Expand All @@ -62,14 +62,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,81 @@
<!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">
<title>Data table</title>
</head>
<body>
<table>
<caption>
Council budget 2018
</caption>
<tbody>
<tr>
<td></th>
<td></td>
<td></td>
</tr>
<tr>
<td></th>
<td></td>
<td></td>
</tr>
<tr>
<th >Items</th>
<th >Expenditure</th>
<th >Other</th>
</tr>
<tr>
<td>Donuts</th>
<td>3,000</td>
<td>2,000</td>
</tr>
<tr>
<td>Stationery</th>
<td>18,000</td>
<td>8,000</td>
</tr>
</tbody>
</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>

0 comments on commit 4f75e87

Please sign in to comment.