From d2e894907185772d794ba0f100adf9b8ef479085 Mon Sep 17 00:00:00 2001 From: Albina Starykova Date: Tue, 28 May 2024 09:05:40 +0300 Subject: [PATCH] Linting --- client/src/includes/a11y-result.test.ts | 63 ++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/client/src/includes/a11y-result.test.ts b/client/src/includes/a11y-result.test.ts index 1bc9133fe52f..5825af0396b5 100644 --- a/client/src/includes/a11y-result.test.ts +++ b/client/src/includes/a11y-result.test.ts @@ -1,5 +1,5 @@ import { AxeResults } from 'axe-core'; -import { sortAxeViolations } from './a11y-result'; +import { sortAxeViolations, checkImageAltText } from './a11y-result'; const mockDocument = `
@@ -55,3 +55,64 @@ describe('sortAxeViolations', () => { ]); }); }); + +describe('checkImageAltText', () => { + beforeEach(() => { + document.body.innerHTML = ` + Good alt text with words like GIFted and moTIF + Bad alt text.png + Bad alt text.TIFF more text + https://Bad.alt.text + + + `; + }); + + it('should not flag images with good alt text', () => { + const image = document.querySelector( + 'img[src="image1.jpg"]', + ); + if (!image) return; + expect(checkImageAltText(image)).toBe(true); + }); + + it('should flag images with a file extension in the alt text', () => { + const image = document.querySelector( + 'img[src="image2.png"]', + ); + if (!image) return; + expect(checkImageAltText(image)).toBe(false); + }); + + it('should flag images with a capitalised file extension in the alt text', () => { + const image = document.querySelector( + 'img[src="image3.tiff"]', + ); + if (!image) return; + expect(checkImageAltText(image)).toBe(false); + }); + + it('should flag images with a file URL in the alt text', () => { + const image = document.querySelector( + 'img[src="image4.png"]', + ); + if (!image) return; + expect(checkImageAltText(image)).toBe(false); + }); + + it('should not flag images with empty alt attribute', () => { + const image = document.querySelector( + 'img[src="https://example.com/image5.gif"]', + ); + if (!image) return; + expect(checkImageAltText(image)).toBe(true); + }); + + it('should not flag images with no alt attribute', () => { + const image = document.querySelector( + 'img[src="image6.jpg"]', + ); + if (!image) return; + expect(checkImageAltText(image)).toBe(true); + }); +});