-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
8b586a4
commit 62d1132
Showing
2 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)]); | ||
}); | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters