Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: result page enhancement #6387

Merged
merged 3 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 33 additions & 31 deletions src/components/result-page/result-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type ResultPageProps = {
title: ReactNode
description?: ReactNode
icon?: ReactNode
details?: ResultPageDetails
details?: ResultPageDetails | null
children?: ReactNode
primaryButtonText?: ReactNode
secondaryButtonText?: ReactNode
Expand Down Expand Up @@ -81,7 +81,7 @@ export const ResultPage: FC<ResultPageProps> = p => {
{isNodeWithContent(description) ? (
<div className={`${classPrefix}-description`}>{description}</div>
) : null}
{details.length ? (
{details?.length ? (
<div className={`${classPrefix}-details`}>
{(collapse ? details.slice(0, 3) : details).map((detail, index) => {
return (
Expand Down Expand Up @@ -116,35 +116,37 @@ export const ResultPage: FC<ResultPageProps> = p => {

<div className={`${classPrefix}-content`}>{props.children}</div>

<div className={`${classPrefix}-footer`}>
{showSecondaryButton && (
<Button
block
color='default'
fill='solid'
size='large'
onClick={onSecondaryButtonClick}
className={`${classPrefix}-footer-btn`}
>
{secondaryButtonText}
</Button>
)}
{showPrimaryButton && showSecondaryButton && (
<div className={`${classPrefix}-footer-space`} />
)}
{showPrimaryButton && (
<Button
block
color='primary'
fill='solid'
size='large'
onClick={onPrimaryButtonClick}
className={`${classPrefix}-footer-btn`}
>
{primaryButtonText}
</Button>
)}
</div>
{(showPrimaryButton || showSecondaryButton) && (
<div className={`${classPrefix}-footer`}>
{showSecondaryButton && (
<Button
block
color='default'
fill='solid'
size='large'
onClick={onSecondaryButtonClick}
className={`${classPrefix}-footer-btn`}
>
{secondaryButtonText}
</Button>
)}
{showPrimaryButton && showSecondaryButton && (
<div className={`${classPrefix}-footer-space`} />
)}
{showPrimaryButton && (
<Button
block
color='primary'
fill='solid'
size='large'
onClick={onPrimaryButtonClick}
className={`${classPrefix}-footer-btn`}
>
{primaryButtonText}
</Button>
)}
</div>
)}
</div>
)
}
44 changes: 44 additions & 0 deletions src/components/result-page/tests/result-page.test.tsx
Original file line number Diff line number Diff line change
@@ -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(
<ResultPage
status='success'
title='title'
description='desc'
primaryButtonText='primary'
secondaryButtonText='secondary'
/>
)
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(
<ResultPage
status='success'
title='title'
description='desc'
details={null}
/>
)
expect(screen.getByText('title')).toBeInTheDocument()
expect(screen.getByText('desc')).toBeInTheDocument()
expect(document.querySelector(`.${classPrefix}-detail`)).not.toBeInTheDocument()
})

test('renders with no footer', () => {
render(<ResultPage status='success' title='title' description='desc' />)
expect(screen.getByText('title')).toBeInTheDocument()
expect(screen.getByText('desc')).toBeInTheDocument()
expect(document.querySelector(`.${classPrefix}-footer`)).not.toBeInTheDocument()
})
})
Loading