Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIA R12: Add Test #800

Merged
merged 5 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions packages/alfa-rules/test/sia-r12/rule.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { test } from "@siteimprove/alfa-test";

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

import R12, { Outcomes } from "../../src/sia-r12/rule";

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

test(`evaluates() passes a <button> with accessible name `, async (t) => {
const target = <button>My button</button>;

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

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

test(`evaluates() passes a submit button element with an accessible name given by the value attribute `, async (t) => {
const input = <input type="submit" value="Submit" />;

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

t.deepEqual(await evaluate(R12, { document }), [
passed(R12, input, {
1: Outcomes.HasName,
}),
]);
});

test(`evaluates() passes a <button> with a name given by the \`aria-label\` attribute`, async (t) => {
const target = <button aria-label="My button"></button>;

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

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

test(`evaluates() fails a button with no accessible name`, async (t) => {
const target = <button></button>;

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

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

test(`evaluates() fails an element with \`button\` role without an accessible name`, async (t) => {
const target = <span role="button"></span>;

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

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

test(`evaluate() is inapplicable to image buttons`, async (t) => {
const target = <input type="image" value="download" alt="Download" />;

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

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

test(`evaluate() is inapplicabile to element with no button role`, async (t) => {
const target = <div>Press Here</div>;

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

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

test(`evaluate() is inapplicabile to button element with none role`, async (t) => {
const target = <button role="none" disabled></button>;

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

t.deepEqual(await evaluate(R12, { document }), [inapplicable(R12)]);
});
1 change: 1 addition & 0 deletions packages/alfa-rules/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
"test/sia-r9/rule.spec.tsx",
"test/sia-r10/rule.spec.tsx",
"test/sia-r11/rule.spec.tsx",
"test/sia-r12/rule.spec.tsx",
"test/sia-r13/rule.spec.tsx",
"test/sia-r14/rule.spec.tsx",
"test/sia-r15/rule.spec.tsx",
Expand Down