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); + }); +});