Loading src/rules/wcag/h32.spec.ts +17 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,14 @@ describe("wcag/h32", () => { beforeAll(() => { htmlvalidate = new HtmlValidate({ elements: [ "html5", { "my-form": { form: true, }, }, ], rules: { "wcag/h32": "error" }, }); }); Loading Loading @@ -44,6 +52,15 @@ describe("wcag/h32", () => { ); }); it("should support custom elements", () => { const report = htmlvalidate.validateString("<my-form></my-form>"); expect(report).toBeInvalid(); expect(report).toHaveError( "WCAG/H32", "<my-form> element must have a submit button" ); }); it("smoketest", () => { const report = htmlvalidate.validateFile("test-files/rules/wcag/h32.html"); expect(report.results).toMatchSnapshot(); Loading src/rules/wcag/h32.ts +11 −2 Original line number Diff line number Diff line Loading @@ -17,8 +17,14 @@ class H32 extends Rule { } public setup(): void { /* query all tags with form property, normally this is only the <form> tag * but with custom element metadata other tags might be considered form * (usually a component wrapping a <form> element) */ const formTags = this.getTagsWithProperty("form"); const formSelector = formTags.join(","); this.on("dom:ready", (event: DOMReadyEvent) => { const forms = event.document.getElementsByTagName("form"); const forms = event.document.querySelectorAll(formSelector); forms.forEach((node: HtmlElement) => { /* find submit buttons */ for (const button of node.querySelectorAll("button,input")) { Loading @@ -28,7 +34,10 @@ class H32 extends Rule { } } this.report(node, "<form> element must have a submit button"); this.report( node, `<${node.tagName}> element must have a submit button` ); }); }); } Loading Loading
src/rules/wcag/h32.spec.ts +17 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,14 @@ describe("wcag/h32", () => { beforeAll(() => { htmlvalidate = new HtmlValidate({ elements: [ "html5", { "my-form": { form: true, }, }, ], rules: { "wcag/h32": "error" }, }); }); Loading Loading @@ -44,6 +52,15 @@ describe("wcag/h32", () => { ); }); it("should support custom elements", () => { const report = htmlvalidate.validateString("<my-form></my-form>"); expect(report).toBeInvalid(); expect(report).toHaveError( "WCAG/H32", "<my-form> element must have a submit button" ); }); it("smoketest", () => { const report = htmlvalidate.validateFile("test-files/rules/wcag/h32.html"); expect(report.results).toMatchSnapshot(); Loading
src/rules/wcag/h32.ts +11 −2 Original line number Diff line number Diff line Loading @@ -17,8 +17,14 @@ class H32 extends Rule { } public setup(): void { /* query all tags with form property, normally this is only the <form> tag * but with custom element metadata other tags might be considered form * (usually a component wrapping a <form> element) */ const formTags = this.getTagsWithProperty("form"); const formSelector = formTags.join(","); this.on("dom:ready", (event: DOMReadyEvent) => { const forms = event.document.getElementsByTagName("form"); const forms = event.document.querySelectorAll(formSelector); forms.forEach((node: HtmlElement) => { /* find submit buttons */ for (const button of node.querySelectorAll("button,input")) { Loading @@ -28,7 +34,10 @@ class H32 extends Rule { } } this.report(node, "<form> element must have a submit button"); this.report( node, `<${node.tagName}> element must have a submit button` ); }); }); } Loading