From cd9966f0a1416fcf7c4702828d7dd9b369a39e3f Mon Sep 17 00:00:00 2001 From: Siddharth Kshetrapal Date: Mon, 22 Jul 2024 14:21:55 +0200 Subject: [PATCH 01/12] fix accessibility issue first --- packages/react/src/StateLabel/StateLabel.tsx | 22 +++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/react/src/StateLabel/StateLabel.tsx b/packages/react/src/StateLabel/StateLabel.tsx index 28fb261353f..4b9af7b278a 100644 --- a/packages/react/src/StateLabel/StateLabel.tsx +++ b/packages/react/src/StateLabel/StateLabel.tsx @@ -33,6 +33,19 @@ const octiconMap = { unavailable: AlertIcon, } +const labelMap = { + issueOpened: 'Issue', + pullOpened: 'Pull request', + issueClosed: 'Issue', + issueClosedNotPlanned: 'Issue', + pullClosed: 'Pull request', + pullMerged: 'Pull request', + draft: 'Pull request', + issueDraft: 'Issue', + pullQueued: 'Pull request', + unavailable: '', +} + const colorVariants = variant({ prop: 'status', variants: { @@ -120,7 +133,14 @@ function StateLabel({children, status, variant: variantProp = 'normal', ...rest} return ( {/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition */} - {status && } + {status && ( + + )} {children} ) From 17a092227a28aae519087640ff12b0e48207144a Mon Sep 17 00:00:00 2001 From: Siddharth Kshetrapal Date: Mon, 22 Jul 2024 14:22:56 +0200 Subject: [PATCH 02/12] stronger types --- packages/react/src/StateLabel/StateLabel.tsx | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/packages/react/src/StateLabel/StateLabel.tsx b/packages/react/src/StateLabel/StateLabel.tsx index 4b9af7b278a..5aba22dc172 100644 --- a/packages/react/src/StateLabel/StateLabel.tsx +++ b/packages/react/src/StateLabel/StateLabel.tsx @@ -33,7 +33,7 @@ const octiconMap = { unavailable: AlertIcon, } -const labelMap = { +const labelMap: Record = { issueOpened: 'Issue', pullOpened: 'Pull request', issueClosed: 'Issue', @@ -133,14 +133,7 @@ function StateLabel({children, status, variant: variantProp = 'normal', ...rest} return ( {/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition */} - {status && ( - - )} + {status && } {children} ) From ea6bc8fe4b0184b61191402d6da14aa01c16ba99 Mon Sep 17 00:00:00 2001 From: Siddharth Kshetrapal Date: Mon, 22 Jul 2024 15:55:18 +0200 Subject: [PATCH 03/12] add tests, update snapshots --- .../StateLabel/__tests__/StateLabel.test.tsx | 10 ++++++++ .../__snapshots__/StateLabel.test.tsx.snap | 24 ++++++++++++------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/packages/react/src/StateLabel/__tests__/StateLabel.test.tsx b/packages/react/src/StateLabel/__tests__/StateLabel.test.tsx index f7a492b1d6a..1739f891ce9 100644 --- a/packages/react/src/StateLabel/__tests__/StateLabel.test.tsx +++ b/packages/react/src/StateLabel/__tests__/StateLabel.test.tsx @@ -43,4 +43,14 @@ describe('StateLabel', () => { it('renders children', () => { expect(render(hi)).toMatchSnapshot() }) + + it('adds label to icon', () => { + const screen1 = HTMLRender(Open) + expect(screen1.getByLabelText('Issue')).toBeInTheDocument() // svg + expect(screen1.getByText('Open')).toBeInTheDocument() // text + + const screen2 = HTMLRender(Merged) + expect(screen2.getByLabelText('Pull request')).toBeInTheDocument() // svg + expect(screen2.getByText('Merged')).toBeInTheDocument() // text + }) }) diff --git a/packages/react/src/StateLabel/__tests__/__snapshots__/StateLabel.test.tsx.snap b/packages/react/src/StateLabel/__tests__/__snapshots__/StateLabel.test.tsx.snap index abf071fef16..9fa743d45f8 100644 --- a/packages/react/src/StateLabel/__tests__/__snapshots__/StateLabel.test.tsx.snap +++ b/packages/react/src/StateLabel/__tests__/__snapshots__/StateLabel.test.tsx.snap @@ -32,11 +32,12 @@ exports[`StateLabel renders children 1`] = ` className="c0" >