Skip to content

Commit

Permalink
Add diagnostics to can't tell outcomes (#1529)
Browse files Browse the repository at this point in the history
* Add diagnostics to can't tell outcome

* Add changeset
  • Loading branch information
rcj-siteimprove authored Dec 12, 2023
1 parent a4a5985 commit 874f0e6
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-maps-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@siteimprove/alfa-rules": minor
---

**Fixed:** Accessible name is now also recorded as in #1502 in can't tell outcomes for rules R15, R39, R41 and R81
10 changes: 8 additions & 2 deletions packages/alfa-rules/src/sia-r15/rule.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Rule } from "@siteimprove/alfa-act";
import { DOM, Node } from "@siteimprove/alfa-aria";
import { Element, Namespace, Query } from "@siteimprove/alfa-dom";
import { Iterable } from "@siteimprove/alfa-iterable";
import { Predicate } from "@siteimprove/alfa-predicate";
import { Err, Ok } from "@siteimprove/alfa-result";
import { Criterion } from "@siteimprove/alfa-wcag";
import { Page } from "@siteimprove/alfa-web";
import { Iterable } from "@siteimprove/alfa-iterable";

import * as dom from "@siteimprove/alfa-dom";

Expand All @@ -16,8 +16,8 @@ import { Question } from "../common/act/question";
import { referenceSameResource } from "../common/predicate";
import { Scope, Stability } from "../tags";

import { normalize } from "../common/normalize";
import { WithAccessibleName } from "../common/diagnostic";
import { normalize } from "../common/normalize";

const { hasNonEmptyAccessibleName, isIncludedInTheAccessibilityTree } = DOM;
const { hasName, hasNamespace } = Element;
Expand Down Expand Up @@ -72,6 +72,12 @@ export default Rule.Atomic.of<Page, Group<Element>, Question.Metadata>({
"reference-equivalent-resources",
target,
"Do the <iframe> elements embed equivalent resources?",
{
diagnostic: WithAccessibleName.of(
"Do the <iframe> elements embed equivalent resources?",
name,
),
},
).map((embedEquivalentResources) =>
expectation(
embedEquivalentResources,
Expand Down
8 changes: 7 additions & 1 deletion packages/alfa-rules/src/sia-r39/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { Page } from "@siteimprove/alfa-web";
import { expectation } from "../common/act/expectation";
import { Question } from "../common/act/question";

import { Scope, Stability } from "../tags";
import { WithAccessibleName } from "../common/diagnostic";
import { Scope, Stability } from "../tags";

const { hasAccessibleName, isIncludedInTheAccessibilityTree } = DOM;
const { hasInputType, hasName, hasNamespace } = Element;
Expand Down Expand Up @@ -62,6 +62,12 @@ export default Rule.Atomic.of<Page, Element, Question.Metadata>({
"name-describes-purpose",
target,
`Does the accessible name of the \`<${target.name}>\` element describe its purpose?`,
{
diagnostic: WithAccessibleName.of(
`Does the accessible name of the \`<${target.name}>\` element describe its purpose?`,
accName,
),
},
).map((nameDescribesPurpose) =>
expectation(
nameDescribesPurpose,
Expand Down
10 changes: 8 additions & 2 deletions packages/alfa-rules/src/sia-r41/rule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Rule } from "@siteimprove/alfa-act";
import { DOM, Node } from "@siteimprove/alfa-aria";
import { Element, Namespace, Query } from "@siteimprove/alfa-dom";
import { Iterable } from "@siteimprove/alfa-iterable";
import { Predicate } from "@siteimprove/alfa-predicate";
import { Err, Ok } from "@siteimprove/alfa-result";
import { Criterion } from "@siteimprove/alfa-wcag";
Expand All @@ -16,9 +17,8 @@ import { referenceSameResource } from "../common/predicate";

import { normalize } from "../common/normalize";

import { Scope, Stability } from "../tags";
import { WithAccessibleName } from "../common/diagnostic";
import { Iterable } from "@siteimprove/alfa-iterable";
import { Scope, Stability } from "../tags";

const { hasNonEmptyAccessibleName, hasRole, isIncludedInTheAccessibilityTree } =
DOM;
Expand Down Expand Up @@ -77,6 +77,12 @@ export default Rule.Atomic.of<Page, Group<Element>, Question.Metadata>({
"reference-equivalent-resources",
target,
`Do the links resolve to equivalent resources?`,
{
diagnostic: WithAccessibleName.of(
`Do the links resolve to equivalent resources?`,
name,
),
},
).map((embedEquivalentResources) =>
expectation(
embedEquivalentResources,
Expand Down
8 changes: 7 additions & 1 deletion packages/alfa-rules/src/sia-r81/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { referenceSameResource } from "../common/predicate";

import { normalize } from "../common/normalize";

import { Scope, Stability } from "../tags";
import { WithAccessibleName } from "../common/diagnostic";
import { Scope, Stability } from "../tags";

const { hasNonEmptyAccessibleName, hasRole, isIncludedInTheAccessibilityTree } =
DOM;
Expand Down Expand Up @@ -92,6 +92,12 @@ export default Rule.Atomic.of<Page, Group<Element>, Question.Metadata>({
"reference-equivalent-resources",
target,
`Do the links resolve to equivalent resources?`,
{
diagnostic: WithAccessibleName.of(
`Do the links resolve to equivalent resources?`,
name,
),
},
).map((embedEquivalentResources) =>
expectation(
embedEquivalentResources,
Expand Down
30 changes: 24 additions & 6 deletions packages/alfa-rules/test/sia-r15/rule.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import R15, { Outcomes } from "../../src/sia-r15/rule";

import { Group } from "../../src/common/act/group";

import { WithAccessibleName } from "../../src/common/diagnostic";
import { evaluate } from "../common/evaluate";
import { oracle } from "../common/oracle";
import { passed, failed, inapplicable, cantTell } from "../common/outcome";
import { cantTell, failed, inapplicable, passed } from "../common/outcome";

test("evaluate() passes when two iframes embed the exact same resource", async (t) => {
const accessibleName = "Foo";
Expand Down Expand Up @@ -138,25 +139,42 @@ test("evaluate() is inapplicable when there is no two iframe with the same name"
});

test("evaluate() can't tell if URLs are identical but invalid", async (t) => {
const accName = "Foo";

const target = [
<iframe title="Foo" src="https:////////@@@" />,
<iframe aria-label="Foo" src="https:////////@@@" />,
<iframe title={accName} src="https:////////@@@" />,
<iframe aria-label={accName} src="https:////////@@@" />,
];

const document = h.document(target);

t.deepEqual(await evaluate(R15, { document }), [
cantTell(R15, Group.of(target)),
cantTell(
R15,
Group.of(target),
WithAccessibleName.of(
"Do the <iframe> elements embed equivalent resources?",
accName,
),
),
]);
});

test("evaluate() can't tell if there is no source", async (t) => {
const target = [<iframe title="Foo" />, <iframe aria-label="Foo" />];
const accName = "Foo";
const target = [<iframe title={accName} />, <iframe aria-label={accName} />];

const document = h.document(target);

t.deepEqual(await evaluate(R15, { document }), [
cantTell(R15, Group.of(target)),
cantTell(
R15,
Group.of(target),
WithAccessibleName.of(
"Do the <iframe> elements embed equivalent resources?",
accName,
),
),
]);
});

Expand Down
20 changes: 19 additions & 1 deletion packages/alfa-rules/test/sia-r39/rule.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { test } from "@siteimprove/alfa-test";

import R39, { Outcomes } from "../../src/sia-r39/rule";

import { WithAccessibleName } from "../../src/common/diagnostic";
import { evaluate } from "../common/evaluate";
import { oracle } from "../common/oracle";
import { passed, failed, inapplicable } from "../common/outcome";
import { cantTell, failed, inapplicable, passed } from "../common/outcome";

test("evaluate() passes images whose name is descriptive", async (t) => {
const target = <img src="Placeholder" alt="Placeholder" />;
Expand Down Expand Up @@ -65,3 +66,20 @@ test("evaluate() is inapplicable to images whose name differ from source", async

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

test("evaluate() can't tell that name is descriptive", async (t) => {
const target = <img src="Placeholder" alt="Placeholder" />;

const document = h.document([target]);

t.deepEqual(await evaluate(R39, { document }), [
cantTell(
R39,
target,
WithAccessibleName.of(
"Does the accessible name of the `<img>` element describe its purpose?",
"Placeholder",
),
),
]);
});
26 changes: 25 additions & 1 deletion packages/alfa-rules/test/sia-r41/rule.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import { Group } from "../../src/common/act/group";

import { Response } from "@siteimprove/alfa-http";
import { URL } from "@siteimprove/alfa-url";
import { WithAccessibleName } from "../../src/common/diagnostic";
import { evaluate } from "../common/evaluate";
import { oracle } from "../common/oracle";
import { failed, inapplicable, passed } from "../common/outcome";
import { cantTell, failed, inapplicable, passed } from "../common/outcome";

test(`evaluate() passes two links that have the same name and reference the same
resource`, async (t) => {
Expand Down Expand Up @@ -147,3 +148,26 @@ test(`evaluate() gather links from the full page`, async (t) => {
}),
]);
});

test(`evaluate() can't tell if two links that have the same name references
equivalent resources`, async (t) => {
const accessibleName = "Foo";

const target = [
<a href="foo.html">{accessibleName}</a>,
<a href="bar.html">{accessibleName}</a>,
];

const document = h.document(target);

t.deepEqual(await evaluate(R41, { document }), [
cantTell(
R41,
Group.of(target),
WithAccessibleName.of(
"Do the links resolve to equivalent resources?",
accessibleName,
),
),
]);
});
36 changes: 33 additions & 3 deletions packages/alfa-rules/test/sia-r81/rule.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import R81, { Outcomes } from "../../src/sia-r81/rule";

import { Group } from "../../src/common/act/group";

import { evaluate } from "../common/evaluate";
import { oracle } from "../common/oracle";
import { passed, failed, inapplicable } from "../common/outcome";
import { Response } from "@siteimprove/alfa-http";
import { URL } from "@siteimprove/alfa-url";
import { WithAccessibleName } from "../../src/common/diagnostic";
import { evaluate } from "../common/evaluate";
import { oracle } from "../common/oracle";
import { cantTell, failed, inapplicable, passed } from "../common/outcome";

test(`evaluate() passes two links that have the same name and reference the same
resource in the same context`, async (t) => {
Expand Down Expand Up @@ -223,3 +224,32 @@ test(`evaluate() gather links from the full page`, async (t) => {
}),
]);
});

test(`evaluate() can't tell if two links that have the same name references
equivalent resources in the same context`, async (t) => {
const accessibleName = "Foo";
const target = [
<a href="foo.html">{accessibleName}</a>,
<a href="bar.html">{accessibleName}</a>,
];

const document = h.document([
<html>
<p>
{target[0]}
{target[1]}
</p>
</html>,
]);

t.deepEqual(await evaluate(R81, { document }), [
cantTell(
R81,
Group.of(target),
WithAccessibleName.of(
"Do the links resolve to equivalent resources?",
accessibleName,
),
),
]);
});

0 comments on commit 874f0e6

Please sign in to comment.