Skip to content

Commit

Permalink
review feedback from @zcorpan; include a permanent and unique test na…
Browse files Browse the repository at this point in the history
…me for dashboard/logs.
  • Loading branch information
cookiecrook committed Mar 21, 2023
1 parent 1fa1780 commit 7416d57
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions wai-aria/role/list-roles.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
</head>
<body>

<div role="list" data-expectedrole="list" class="ex">
<div role="listitem" data-expectedrole="listitem" class="ex">x</div>
<div role="listitem" data-expectedrole="listitem" class="ex">x</div>
<div role="list" data-testname="first simple list" data-expectedrole="list" class="ex">
<div role="listitem" data-testname="first simple listitem" data-expectedrole="listitem" class="ex">x</div>
<div role="listitem" data-testname="last simple listitem" data-expectedrole="listitem" class="ex">x</div>
</div>

<script>
Expand Down
4 changes: 2 additions & 2 deletions wai-aria/role/region-roles.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
<body>

<!-- no label -->
<nav role="region" data-expectedrole="navigation" class="ex">x</form>
<nav role="region" data-testname="region without label" data-expectedrole="navigation" class="ex">x</nav>

<!-- w/ label -->
<nav role="region" data-expectedrole="region" aria-label="x" class="ex">x</nav>
<nav role="region" data-testname="region with label" data-expectedrole="region" aria-label="x" class="ex">x</nav>

<script>
AriaUtils.verifyRolesBySelector(".ex");
Expand Down
16 changes: 9 additions & 7 deletions wai-aria/scripts/aria-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const AriaUtils = {

/*
Tests simple role assignment: <div role="alert">x</div>
Not intended for nest, context-dependent, or other complex roles.
Not intended for nested, context-dependent, or other complex role tests.
*/
assignAndVerifyRolesByRoleNames: function(roleNames) {
for (const role of roleNames) {
Expand All @@ -24,21 +24,23 @@ const AriaUtils = {
Tests computed role of all elements matching selector
against the string value of their data-role attribute.
Ex: <div role="list" data-expectedrole="list" class="ex">
Ex: <div role="list"
data-testname="optional unique test name"
data-expectedrole="list"
class="ex">
AriaUtils.verifyRolesBySelector(".ex")
*/
verifyRolesBySelector: function(selector) {
let testCount = 0;
const els = document.querySelectorAll(selector);

for (const el of els) {
testCount++;
let role = el.getAttribute("data-expectedrole");
let testName = el.getAttribute("data-testname") || role; // data-testname optional if role unique per test file
promise_test(async t => {
const expectedRole = el.getAttribute("data-expectedrole");

// ensure ID uniqueness when testing multiple elements of the same role type
// ensure ID existence and uniqueness for the webdriver callback
if (!el.id) {
let roleCount = 1;
let elID = `${expectedRole}${roleCount}`;
Expand All @@ -51,7 +53,7 @@ const AriaUtils = {

const computedRole = await test_driver.get_computed_role(document.getElementById(el.id));
assert_equals(computedRole, expectedRole, el.outerHTML);
}, `${testCount} ${role}`);
}, `${testName}`);
}
},

Expand Down

0 comments on commit 7416d57

Please sign in to comment.