From a43209f6b80a8c7138f7ed1b74e4138f5238b5cd Mon Sep 17 00:00:00 2001 From: Mathieu Suen Date: Mon, 18 Mar 2024 12:20:14 +0100 Subject: SONAR-21808 Add the failed badge on software quality cards --- server/sonar-web/design-system/src/components/Badge.tsx | 7 +++---- .../design-system/src/components/__tests__/Badge-test.tsx | 10 +++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'server/sonar-web/design-system/src') diff --git a/server/sonar-web/design-system/src/components/Badge.tsx b/server/sonar-web/design-system/src/components/Badge.tsx index 54ed4d62289..1746a417d0c 100644 --- a/server/sonar-web/design-system/src/components/Badge.tsx +++ b/server/sonar-web/design-system/src/components/Badge.tsx @@ -32,8 +32,7 @@ const variantList: Record = { counterFailed: 'badgeCounterFailed', }; -interface BadgeProps { - children: string | number; +interface BadgeProps extends React.PropsWithChildren { className?: string; title?: string; variant?: BadgeVariant; @@ -41,9 +40,9 @@ interface BadgeProps { export function Badge({ className, children, title, variant = 'default' }: BadgeProps) { const commonProps = { - 'aria-label': title ?? children.toString(), + 'aria-label': title, className, - role: 'status', + role: title ? 'img' : 'presentation', title, }; diff --git a/server/sonar-web/design-system/src/components/__tests__/Badge-test.tsx b/server/sonar-web/design-system/src/components/__tests__/Badge-test.tsx index 97f901852d8..5429ccc2a16 100644 --- a/server/sonar-web/design-system/src/components/__tests__/Badge-test.tsx +++ b/server/sonar-web/design-system/src/components/__tests__/Badge-test.tsx @@ -23,10 +23,14 @@ import { Badge } from '../Badge'; it('renders badge correctly', () => { render(foo); - expect(screen.getByRole('status')).toBeInTheDocument(); + expect(screen.getByText('foo')).toBeInTheDocument(); }); it('renders counter correctly', () => { - render(23); - expect(screen.getByRole('status')).toHaveAttribute('aria-label', '23'); + render( + + 23 + , + ); + expect(screen.getByRole('img')).toHaveAccessibleName('This 23'); }); -- cgit v1.2.3