Skip to content

Commit

Permalink
SIA R17: add test (#791)
Browse files Browse the repository at this point in the history
* Create rule.spec.tsx

* sia-r17 added test

* Apply suggestions from code review

Co-authored-by: Jean-Yves Moyen <[email protected]>

Co-authored-by: Jean-Yves Moyen <[email protected]>
  • Loading branch information
elenamongelli and Jym77 authored May 7, 2021
1 parent 8b586a4 commit 62d1132
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 0 deletions.
131 changes: 131 additions & 0 deletions packages/alfa-rules/test/sia-r17/rule.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { test } from "@siteimprove/alfa-test";

import { Document } from "@siteimprove/alfa-dom";

import R17, { Outcomes } from "../../src/sia-r17/rule";

import { evaluate } from "../common/evaluate";
import { passed, failed, inapplicable } from "../common/outcome";

test(`evaluate() passes an element which is not focusable by default`, async (t) => {
const target = <p aria-hidden="true">Some text</p>;

const document = Document.of([target]);

t.deepEqual(await evaluate(R17, { document }), [
passed(R17, target, {
1: Outcomes.IsNotTabbable,
}),
]);
});

test(`evaluate() passes an element which content is hidden`, async (t) => {
const target = <div aria-hidden="true">
<a href="/" style={{display:"none"}}>Link</a>
</div>;

const document = Document.of([target]);

t.deepEqual(await evaluate(R17, { document }), [
passed(R17, target, {
1: Outcomes.IsNotTabbable,
}),
]);
});

test(`evaluate() passes an element whose content is taken out of sequential focus order using tabindex`,
async (t) => {
const target = <div aria-hidden="true">
<button tabindex="-1">Some button</button>
</div>;

const document = Document.of([target]);

t.deepEqual(await evaluate(R17, { document }), [
passed(R17, target, {
1: Outcomes.IsNotTabbable,
}),
]);
});

test(`evaluate() passes an element which is disabled`, async (t) => {
const target = <input disabled aria-hidden="true" />;

const document = Document.of([target]);

t.deepEqual(await evaluate(R17, { document }), [
passed(R17, target, {
1: Outcomes.IsNotTabbable,
}),
]);
});

test(`evaluate() fails an element with focusable content`, async (t) => {
const target = <div aria-hidden="true">
<a href="/">Link</a>
</div>;

const document = Document.of([target]);

t.deepEqual(await evaluate(R17, { document }), [
failed(R17, target, {
1: Outcomes.IsTabbable,
}),
]);
});

test(`evaluate() fails an element with an \`aria-hidden\` ancestor`, async (t) => {
const target =<div aria-hidden="true">
<div aria-hidden="false">
<button>Some button</button>
</div>
</div>;

const document = Document.of([target]);

t.deepEqual(await evaluate(R17, { document }), [
failed(R17, target, {
1: Outcomes.IsTabbable,
}),
]);
});

test(`evaluate() fails an element with focusable content through tabindex`, async (t) => {
const target =<p tabindex="0" aria-hidden="true">Some text</p>;

const document = Document.of([target]);

t.deepEqual(await evaluate(R17, { document }), [
failed(R17, target, {
1: Outcomes.IsTabbable,
}),
]);
});

test(`evaluate() fails a focusable summary element`, async (t) => {
const target = <details aria-hidden="true">
<summary>Some button</summary>
<p>Some details</p>
</details>;

const document = Document.of([target]);

t.deepEqual(await evaluate(R17, { document }), [
failed(R17, target, {
1: Outcomes.IsTabbable,
}),
]);
});

test(`evaluate() is inapplicable when aria-hidden has incorrect value`, async (t) => {
const target = <div aria-hidden="yes">
<p>Some text</p>
</div>;

const document = Document.of([target]);

t.deepEqual(await evaluate(R17, { document }), [inapplicable(R17)]);
});



1 change: 1 addition & 0 deletions packages/alfa-rules/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
"test/sia-r14/rule.spec.tsx",
"test/sia-r15/rule.spec.tsx",
"test/sia-r16/rule.spec.tsx",
"test/sia-r17/rule.spec.tsx",
"test/sia-r21/rule.spec.tsx",
"test/sia-r24/rule.spec.tsx",
"test/sia-r38/rule.spec.tsx",
Expand Down

0 comments on commit 62d1132

Please sign in to comment.