From 3bfd8af978dec5f0e85a1ca563e7f9800059f7f4 Mon Sep 17 00:00:00 2001 From: chisom chima Date: Thu, 15 Feb 2024 11:11:06 +0100 Subject: [PATCH 1/6] feat: add warnings to the button component for accessibility --- collections/forms/i18n/en.pot | 4 +- .../src/button/__tests__/Button.test.js | 46 +++++++++++++++++++ components/button/src/button/button.js | 7 +++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/collections/forms/i18n/en.pot b/collections/forms/i18n/en.pot index e65ed246e0..581c2d0a90 100644 --- a/collections/forms/i18n/en.pot +++ b/collections/forms/i18n/en.pot @@ -5,8 +5,8 @@ msgstr "" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1)\n" -"POT-Creation-Date: 2024-02-12T14:58:56.792Z\n" -"PO-Revision-Date: 2024-02-12T14:58:56.792Z\n" +"POT-Creation-Date: 2024-02-15T10:07:40.463Z\n" +"PO-Revision-Date: 2024-02-15T10:07:40.463Z\n" msgid "Upload file" msgstr "Upload file" diff --git a/components/button/src/button/__tests__/Button.test.js b/components/button/src/button/__tests__/Button.test.js index 9126fb798f..edd9b01d20 100644 --- a/components/button/src/button/__tests__/Button.test.js +++ b/components/button/src/button/__tests__/Button.test.js @@ -4,6 +4,52 @@ import React from 'react' import { Button } from '../button.js' describe(') + + expect(consoleSpy).not.toHaveBeenCalled() + }) + + it('does not warn if aria-label or title is present', () => { + render( + + ) + + expect(consoleSpy).not.toHaveBeenCalled() + }) + + it('warns if no children are present with no arial-label and title', () => { + render() + + expect(consoleSpy).toHaveBeenCalledWith( + 'Button component has no children but is missing title or ariaLabel attribute.' + ) + }) + + it('No warning if there are no children but arial label and title', () => { + render( + + ) + + expect(consoleSpy).not.toHaveBeenCalled() + }) + }) + it('renders a default data-test attribute', () => { const dataTest = 'dhis2-uicore-button' const wrapper = mount() expect(consoleSpy).not.toHaveBeenCalled() }) - it('does not warn if aria-label or title is present', () => { + it('does not warn if aria-label and title is present', () => { render( - ) @@ -41,7 +41,7 @@ describe(' ) From c8abea908de2ddc03b8c8e37eef017a51f621b90 Mon Sep 17 00:00:00 2001 From: chisom chima Date: Wed, 21 Feb 2024 12:06:34 +0100 Subject: [PATCH 6/6] feat: update warning in button component --- components/button/src/button/__tests__/Button.test.js | 2 +- components/button/src/button/button.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/button/src/button/__tests__/Button.test.js b/components/button/src/button/__tests__/Button.test.js index 79cb840137..b36146c492 100644 --- a/components/button/src/button/__tests__/Button.test.js +++ b/components/button/src/button/__tests__/Button.test.js @@ -35,7 +35,7 @@ describe(') expect(consoleSpy).toHaveBeenCalledWith( - 'Button component has no children but is missing title or ariaLabel attribute.' + 'Button component has no children but is missing title and ariaLabel attribute.' ) }) diff --git a/components/button/src/button/button.js b/components/button/src/button/button.js index 89095a5c44..7f27d98223 100644 --- a/components/button/src/button/button.js +++ b/components/button/src/button/button.js @@ -41,7 +41,7 @@ export const Button = ({ if (!children && !title && !ariaLabel) { console.debug( - 'Button component has no children but is missing title or ariaLabel attribute.' + 'Button component has no children but is missing title and ariaLabel attribute.' ) }