From eb48d87f87be3727309c2e7965380c39b4b6c635 Mon Sep 17 00:00:00 2001 From: Jean-Yves Moyen Date: Wed, 4 Dec 2024 17:27:31 +0100 Subject: [PATCH] Add test cases --- packages/alfa-rules/src/sia-r116/rule.ts | 2 +- .../alfa-rules/test/sia-r116/rule.spec.tsx | 144 +++++++++++++++--- 2 files changed, 123 insertions(+), 23 deletions(-) diff --git a/packages/alfa-rules/src/sia-r116/rule.ts b/packages/alfa-rules/src/sia-r116/rule.ts index 7761be5b3f..a9d6dc541c 100644 --- a/packages/alfa-rules/src/sia-r116/rule.ts +++ b/packages/alfa-rules/src/sia-r116/rule.ts @@ -35,7 +35,7 @@ export default Rule.Atomic.of>({ // If the explicit role is none/presentation but the element is // nonetheless included in the accessibility tree, then the // conflict triggered, and we want to keep it as target. - not(hasExplicitRole(Role.hasName("none", "presentation"))), + not(hasExplicitRole(not(Role.hasName("none", "presentation")))), ), ); }, diff --git a/packages/alfa-rules/test/sia-r116/rule.spec.tsx b/packages/alfa-rules/test/sia-r116/rule.spec.tsx index 830952ee88..a16d1c9e1c 100644 --- a/packages/alfa-rules/test/sia-r116/rule.spec.tsx +++ b/packages/alfa-rules/test/sia-r116/rule.spec.tsx @@ -1,4 +1,3 @@ -/// import { Device } from "@siteimprove/alfa-device"; import { type Element, h } from "@siteimprove/alfa-dom"; import { Node } from "@siteimprove/alfa-aria"; @@ -9,7 +8,26 @@ import R116, { Outcomes } from "../../dist/sia-r116/rule.js"; import { evaluate } from "../common/evaluate.js"; import { failed, inapplicable, passed } from "../common/outcome.js"; -test("evaluate() passes summary elements with an accessible name", async (t) => { +test("evaluate() passes summary elements with an accessible name from aria-label", async (t) => { + const target = ( + Opening times + ) as Element<"summary">; + + const document = h.document([ +
+ {target} +

This is a website. We are available 24/7.

+
, + ]); + + t.deepEqual(await evaluate(R116, { document }), [ + passed(R116, target, { + 1: Outcomes.HasAccessibleName, + }), + ]); +}); + +test("evaluate() passes summary elements with an accessible name from content", async (t) => { const target = (Opening times) as Element<"summary">; const document = h.document([ @@ -19,11 +37,22 @@ test("evaluate() passes summary elements with an accessible name", async (t) => , ]); - const ariaSummary = Node.from(target, Device.standard()); - console.dir(ariaSummary.toJSON()); + t.deepEqual(await evaluate(R116, { document }), [ + passed(R116, target, { + 1: Outcomes.HasAccessibleName, + }), + ]); +}); - const ariaDetails = Node.from(target.parent().getUnsafe(), Device.standard()); - console.dir(ariaDetails.toJSON()); +test("evaluate() passes summary elements that are not the first children", async (t) => { + const target = (Opening times) as Element<"summary">; + + const document = h.document([ +
+

This is a website. We are available 24/7.

+ {target} +
, + ]); t.deepEqual(await evaluate(R116, { document }), [ passed(R116, target, { @@ -32,19 +61,90 @@ test("evaluate() passes summary elements with an accessible name", async (t) => ]); }); -// test("evaluate() passes summary elements that are not the first children", async (t) => { -// const target = (Opening times) as Element<"summary">; -// -// const document = h.document([ -//
-//

This is a website. We are available 24/7.

-// {target} -//
, -// ]); -// -// t.deepEqual(await evaluate(R116, { document }), [ -// passed(R116, target, { -// 1: Outcomes.HasAccessibleName, -// }), -// ]); -// }); +test("evaluate() is only applicable to the first summary element child", async (t) => { + const target = (Opening times) as Element<"summary">; + + const document = h.document([ +
+ {target} + Hello +

This is a website. We are available 24/7.

+
, + ]); + + t.deepEqual(await evaluate(R116, { document }), [ + passed(R116, target, { + 1: Outcomes.HasAccessibleName, + }), + ]); +}); + +test("evaluate() fails summary elements without an accessible name", async (t) => { + const target = () as Element<"summary">; + + const document = h.document([ +
+ {target} +

This is a website. We are available 24/7.

+
, + ]); + + t.deepEqual(await evaluate(R116, { document }), [ + failed(R116, target, { + 1: Outcomes.HasNoAccessibleName, + }), + ]); +}); + +test("evaluate() applies to element where the presentational conflict triggers", async (t) => { + const target = () as Element<"summary">; + + const document = h.document([ +
+ {target} +

This is a website. We are available 24/7.

+
, + ]); + + t.deepEqual(await evaluate(R116, { document }), [ + failed(R116, target, { + 1: Outcomes.HasNoAccessibleName, + }), + ]); +}); + +test("evaluate() is inapplicable to summary elements that are not summary for their parent details", async (t) => { + const document = h.document([ + Isolated, +
+
+ Nested +
+

This is a website. We are available 24/7.

+
, + ]); + + t.deepEqual(await evaluate(R116, { document }), [inapplicable(R116)]); +}); + +test("evaluate() is inapplicable to summary elements that are not exposed", async (t) => { + const document = h.document([ +
+ Opening times +

This is a website. We are available 24/7.

+
, + ]); + + t.deepEqual(await evaluate(R116, { document }), [inapplicable(R116)]); +}); + +test("evaluate() is inapplicable to summary elements with an explicit role", async (t) => { + const document = h.document([ +
+ Opening times +

This is a website. We are available 24/7.

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