From 11f6aa3b6a5755d7f1c8c18c09a2cd636075b73c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rolf=20Christian=20J=C3=B8rgensen?= <114920418+rcj-siteimprove@users.noreply.github.com> Date: Tue, 16 Jan 2024 13:57:37 +0100 Subject: [PATCH] Add filtering of punctuation-only texts in applicability of R69 --- packages/alfa-rules/src/sia-r69/rule.ts | 11 +++++- .../alfa-rules/test/sia-r69/rule.spec.tsx | 34 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/packages/alfa-rules/src/sia-r69/rule.ts b/packages/alfa-rules/src/sia-r69/rule.ts index 61702b8d61..c230c70d83 100644 --- a/packages/alfa-rules/src/sia-r69/rule.ts +++ b/packages/alfa-rules/src/sia-r69/rule.ts @@ -1,5 +1,6 @@ import { Rule } from "@siteimprove/alfa-act"; import { Element, Text } from "@siteimprove/alfa-dom"; +import { Predicate } from "@siteimprove/alfa-predicate"; import { Criterion } from "@siteimprove/alfa-wcag"; import { Page } from "@siteimprove/alfa-web"; @@ -11,6 +12,8 @@ import { hasSufficientContrast } from "../common/expectation/contrast"; import { Scope, Stability, Version } from "../tags"; +const { not } = Predicate; + export default Rule.Atomic.of< Page, Text, @@ -23,7 +26,9 @@ export default Rule.Atomic.of< evaluate({ device, document }) { return { applicability() { - return nonDisabledTexts(document, device); + return nonDisabledTexts(document, device).filter( + not(isOnlyPunctuation), + ); }, expectations(target) { @@ -32,3 +37,7 @@ export default Rule.Atomic.of< }; }, }); + +function isOnlyPunctuation(text: Text): boolean { + return text.data.replace(/\p{P}|\p{S}|\p{Cf}/gu, "").length === 0; +} diff --git a/packages/alfa-rules/test/sia-r69/rule.spec.tsx b/packages/alfa-rules/test/sia-r69/rule.spec.tsx index e6677473c9..61ff67bbb3 100644 --- a/packages/alfa-rules/test/sia-r69/rule.spec.tsx +++ b/packages/alfa-rules/test/sia-r69/rule.spec.tsx @@ -395,6 +395,40 @@ test(`evaluate() is inapplicable to the text that is part of a label of a disabl t.deepEqual(await evaluate(R69, { document }), [inapplicable(R69)]); }); +test("evaluate() is inapplicable to text that would otherwise pass if it was not only punctuation", async (t) => { + const target = h.text(",./;'[]\\-=?<>:\"{}|_+!@#$%^&*()"); + + const document = h.document([ + + {target} + , + ]); + + t.deepEqual(await evaluate(R69, { document }), [inapplicable(R69)]); +}); + +test("evaluate() is inapplicable to text that would otherwise fail if it was not only punctuation", async (t) => { + const target = h.text(",./;'[]\\-=?<>:\"{}|_+!@#$%^&*()"); + + const document = h.document([ + + {target} + , + ]); + + t.deepEqual(await evaluate(R69, { document }), [inapplicable(R69)]); +}); + test("evaluate() passes when a background color with sufficient contrast is input", async (t) => { const target = h.text("Hello world");