From 6f2f4393a0cb1bea7569b1773bc7f8531e7a2e3a Mon Sep 17 00:00:00 2001 From: kongmoumou <35442047+kongmoumou@users.noreply.github.com> Date: Mon, 2 Oct 2023 20:54:24 +0800 Subject: [PATCH 1/3] fix(result-page): allow details to be null --- src/components/result-page/result-page.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/result-page/result-page.tsx b/src/components/result-page/result-page.tsx index 7190a83f74..7648b8f8a7 100644 --- a/src/components/result-page/result-page.tsx +++ b/src/components/result-page/result-page.tsx @@ -39,7 +39,7 @@ export type ResultPageProps = { title: ReactNode description?: ReactNode icon?: ReactNode - details?: ResultPageDetails + details?: ResultPageDetails | null children?: ReactNode primaryButtonText?: ReactNode secondaryButtonText?: ReactNode @@ -81,7 +81,7 @@ export const ResultPage: FC = p => { {isNodeWithContent(description) ? (
{description}
) : null} - {details.length ? ( + {details?.length ? (
{(collapse ? details.slice(0, 3) : details).map((detail, index) => { return ( From 48179afd4c30ae257cb385d01a36fdb91414539c Mon Sep 17 00:00:00 2001 From: kongmoumou <35442047+kongmoumou@users.noreply.github.com> Date: Mon, 2 Oct 2023 20:55:07 +0800 Subject: [PATCH 2/3] fix: hide footer when no btn text --- src/components/result-page/result-page.tsx | 60 +++++++++++----------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/components/result-page/result-page.tsx b/src/components/result-page/result-page.tsx index 7648b8f8a7..69b5cc440b 100644 --- a/src/components/result-page/result-page.tsx +++ b/src/components/result-page/result-page.tsx @@ -116,35 +116,37 @@ export const ResultPage: FC = p => {
{props.children}
-
- {showSecondaryButton && ( - - )} - {showPrimaryButton && showSecondaryButton && ( -
- )} - {showPrimaryButton && ( - - )} -
+ {(showPrimaryButton || showSecondaryButton) && ( +
+ {showSecondaryButton && ( + + )} + {showPrimaryButton && showSecondaryButton && ( +
+ )} + {showPrimaryButton && ( + + )} +
+ )}
) } From a587b0d50c28b556c7961bdb3164075b49f0d040 Mon Sep 17 00:00:00 2001 From: kongmoumou <35442047+kongmoumou@users.noreply.github.com> Date: Mon, 2 Oct 2023 20:56:19 +0800 Subject: [PATCH 3/3] fix: add test case --- .../result-page/tests/result-page.test.tsx | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/components/result-page/tests/result-page.test.tsx diff --git a/src/components/result-page/tests/result-page.test.tsx b/src/components/result-page/tests/result-page.test.tsx new file mode 100644 index 0000000000..d34b804a88 --- /dev/null +++ b/src/components/result-page/tests/result-page.test.tsx @@ -0,0 +1,44 @@ +import React from 'react' +import { render, screen } from 'testing' +import ResultPage from '..' + +const classPrefix = 'adm-result-page' + +describe('ResultPage', () => { + test('renders with success status', () => { + render( + + ) + expect(screen.getByText('title')).toBeInTheDocument() + expect(screen.getByText('desc')).toBeInTheDocument() + expect(screen.getByText('primary')).toBeInTheDocument() + expect(screen.getByText('secondary')).toBeInTheDocument() + }) + + test('renders with details: null', () => { + render( + + ) + expect(screen.getByText('title')).toBeInTheDocument() + expect(screen.getByText('desc')).toBeInTheDocument() + expect(document.querySelector(`.${classPrefix}-detail`)).not.toBeInTheDocument() + }) + + test('renders with no footer', () => { + render() + expect(screen.getByText('title')).toBeInTheDocument() + expect(screen.getByText('desc')).toBeInTheDocument() + expect(document.querySelector(`.${classPrefix}-footer`)).not.toBeInTheDocument() + }) +})