Skip to content

Commit

Permalink
test: Enable accessibleDescription in cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Jun 9, 2020
1 parent 67bc34f commit 7677758
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
1 change: 1 addition & 0 deletions tests/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
31 changes: 22 additions & 9 deletions tests/cypress/integration/web-platform-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,23 +174,36 @@ context("wpt", () => {
`#steps tr:nth-of-type(2) .api tr:nth-of-type(${2 + usedApiIndex})`
)
.then(($row) => {
const [$apiName, $access, $name, $equality, $expected] = $row.find(
"td"
);
const [
$apiName,
$access,
$property,
$equality,
$expected,
] = $row.find("td");

// these cases are handled
expect($apiName.textContent).to.equal("ATK");
expect($access.textContent).to.equal("property");
expect($property.textContent).to.be.oneOf(["name", "description"]);
expect($equality.textContent).to.equal("is");

return $expected.textContent;
return [$property.textContent, $expected.textContent];
})
.then((expected) => {
.then(([property, expected]) => {
cy.get("#test").then(($element) => {
if (result === "pass") {
expect($element[0]).to.have.accessibleName(expected);
} else if (result === "fail") {
expect($element[0]).not.to.have.accessibleName(expected);
if (property === "name") {
if (result === "pass") {
expect($element[0]).to.have.accessibleName(expected);
} else if (result === "fail") {
expect($element[0]).not.to.have.accessibleName(expected);
}
} else if (property === "description") {
if (result === "pass") {
expect($element[0]).to.have.accessibleDescription(expected);
} else if (result === "fail") {
expect($element[0]).not.to.have.accessibleDescription(expected);
}
}
});
});
Expand Down
22 changes: 20 additions & 2 deletions tests/cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { computeAccessibleName } from "../../../dist";
import {
computeAccessibleName,
computeAccessibleDescription,
} from "../../../dist";

chai.use((_chai, _utils) => {
function assertAccessibleName(expected) {
const element = _utils.flag(this, "object");
console.log(element);
const actual = computeAccessibleName(element);

this.assert(
Expand All @@ -14,4 +16,20 @@ chai.use((_chai, _utils) => {
}

_chai.Assertion.addMethod("accessibleName", assertAccessibleName);

function assertAccessibleDescription(expected) {
const element = _utils.flag(this, "object");
const actual = computeAccessibleDescription(element);

this.assert(
expected === actual,
`expected to have accessible description '${expected}' but got '${actual}'`,
`expected to not have accessible description ${expected}`
);
}

_chai.Assertion.addMethod(
"accessibleDescription",
assertAccessibleDescription
);
});

0 comments on commit 7677758

Please sign in to comment.