Skip to content

Commit

Permalink
SIA R5: add test (#794)
Browse files Browse the repository at this point in the history
* Test r5 added

* Apply suggestions from code review

Co-authored-by: Jean-Yves Moyen <[email protected]>

* variable const target changed to html

Co-authored-by: Jean-Yves Moyen <[email protected]>
  • Loading branch information
elenamongelli and Jym77 authored May 11, 2021
1 parent f66b35e commit 6bc0448
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
51 changes: 51 additions & 0 deletions packages/alfa-rules/test/sia-r5/rule.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { test } from "@siteimprove/alfa-test";

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

import R5, { Outcomes } from "../../src/sia-r5/rule";

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

test(`evaluate() passes a lang attribute with valid primary tag`, async (t) => {
const html = <html lang="en"></html>;

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

t.deepEqual(await evaluate(R5, { document }), [
passed(R5, html.attribute("lang").get(), {
1: Outcomes.HasValidLanguage,
}),
]);
});

test(`evaluate() passes a lang attribute with valid primary tag and invalid region subtag`, async (t) => {
const html = <html lang="en-US-GB"></html>;

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

t.deepEqual(await evaluate(R5, { document }), [
passed(R5, html.attribute("lang").get(), {
1: Outcomes.HasValidLanguage,
}),
]);
});

test(`evaluate() fails a lang attribute with invalid primary tag.`, async (t) => {
const html = <html lang="invalid"></html>;

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

t.deepEqual(await evaluate(R5, { document }), [
failed(R5, html.attribute("lang").get(), {
1: Outcomes.HasNoValidLanguage,
}),
]);
});

test(`evaluate() is inapplicable to svg elements.`, async (t) => {
const html = <svg xmlns="http://www.w3.org/2000/svg" lang="fr"></svg>;
const document = Document.of([html]);

t.deepEqual(await evaluate(R5, { document }), [inapplicable(R5)]);
});
1 change: 1 addition & 0 deletions packages/alfa-rules/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
"test/sia-r2/rule.spec.tsx",
"test/sia-r3/rule.spec.tsx",
"test/sia-r4/rule.spec.tsx",
"test/sia-r5/rule.spec.tsx",
"test/sia-r6/rule.spec.tsx",
"test/sia-r7/rule.spec.tsx",
"test/sia-r9/rule.spec.tsx",
Expand Down

0 comments on commit 6bc0448

Please sign in to comment.