diff --git a/src/app/helpers/errata.ts b/src/app/helpers/errata.ts index 9604f3be6..bd95c4ab9 100644 --- a/src/app/helpers/errata.ts +++ b/src/app/helpers/errata.ts @@ -18,7 +18,7 @@ export type Errata = { resolutionNotes: string; }; -type Detail = Pick< +export type Detail = Pick< Errata, 'id' | 'status' | 'errorType' | 'detail' | 'resolutionNotes' > & { diff --git a/src/app/pages/errata-detail/detail/detail.js b/src/app/pages/errata-detail/detail/detail.js deleted file mode 100644 index dc1cbd342..000000000 --- a/src/app/pages/errata-detail/detail/detail.js +++ /dev/null @@ -1,63 +0,0 @@ -import React from 'react'; -import RawHTML from '~/components/jsx-helpers/raw-html'; -import {useErrataDetail, shouldShowDecisionDetails} from '~/helpers/errata'; -import './detail.scss'; - -const detailDataPairs = [ - ['Submission ID', 'id'], - ['Title', 'bookTitle'], - ['Source', 'source'], - ['Status', 'status'], - ['Error Type', 'errorType'], - ['Location', 'location'], - ['Description', 'detail'], - ['Date Submitted', 'date'] -]; -const decisionDataPairs = [ - ['Decision', 'resolutionNotes'] -]; - -function LabelValuePairs({detail, pairs}) { - return ( - - { - pairs.map((pair) => -
-
{pair[0]}
- -
- ) - } -
- ); -} - -export default function Detail({data}) { - const detail = useErrataDetail(data); - - if (!detail) { - return null; - } - const showDecisionDetails = shouldShowDecisionDetails(data); - - return ( - - { - showDecisionDetails && -
- -
- } -
- -
-
- {'You can check the status of all errata submissions on the '} - - - {' '}Errata Page - . -
-
- ); -} diff --git a/src/app/pages/errata-detail/detail/detail.tsx b/src/app/pages/errata-detail/detail/detail.tsx new file mode 100644 index 000000000..31c78a2b7 --- /dev/null +++ b/src/app/pages/errata-detail/detail/detail.tsx @@ -0,0 +1,70 @@ +import React from 'react'; +import RawHTML from '~/components/jsx-helpers/raw-html'; +import { + useErrataDetail, + shouldShowDecisionDetails, + Errata, + Detail as DetailData +} from '~/helpers/errata'; +import './detail.scss'; + +type Pairs = Array<[s: string, i: keyof DetailData]>; + +const detailDataPairs: Pairs = [ + ['Submission ID', 'id'], + ['Title', 'bookTitle'], + ['Source', 'source'], + ['Status', 'status'], + ['Error Type', 'errorType'], + ['Location', 'location'], + ['Description', 'detail'], + ['Date Submitted', 'date'] +]; +const decisionDataPairs: Pairs = [['Decision', 'resolutionNotes']]; + +function LabelValuePairs({detail, pairs}: {detail: DetailData; pairs: Pairs}) { + return ( + + {pairs.map((pair) => ( +
+
{pair[0]}
+ +
+ ))} +
+ ); +} + +export default function Detail({data}: {data: Errata}) { + const detail = useErrataDetail(data); + + if (!detail) { + return null; + } + const showDecisionDetails = shouldShowDecisionDetails(data); + + return ( + + {showDecisionDetails && ( +
+ +
+ )} +
+ +
+
+ {'You can check the status of all errata submissions on the '} + + Errata Page + + . +
+
+ ); +} diff --git a/src/app/pages/errata-detail/errata-detail.js b/src/app/pages/errata-detail/errata-detail.tsx similarity index 64% rename from src/app/pages/errata-detail/errata-detail.js rename to src/app/pages/errata-detail/errata-detail.tsx index 46aa1f1dc..169094f09 100644 --- a/src/app/pages/errata-detail/errata-detail.js +++ b/src/app/pages/errata-detail/errata-detail.tsx @@ -2,10 +2,11 @@ import LoaderPage from '~/components/jsx-helpers/loader-page'; import React from 'react'; import ProgressBar from './progress-bar/progress-bar'; import Detail from './detail/detail'; -import {getDisplayStatus} from '~/helpers/errata'; +import {getDisplayStatus, Errata} from '~/helpers/errata'; +import {useLocation} from 'react-router-dom'; import './errata-detail.scss'; -function ProgressBarBlock({data}) { +function ProgressBarBlock({data}: {data: Errata}) { const {status, barStatus} = getDisplayStatus(data); return ( @@ -15,7 +16,7 @@ function ProgressBarBlock({data}) { ); } -export function ErrataDetailBlock({data}) { +export function ErrataDetailBlock({data}: {data: Errata}) { return (
@@ -23,13 +24,12 @@ export function ErrataDetailBlock({data}) { ); } -function ErrataDetail({data}) { - if (!data) { - return null; - } +function ErrataDetail({data}: {data: Errata}) { return ( -

Errata Submission Details

+
+

Errata Submission Details

+
@@ -39,9 +39,11 @@ function ErrataDetail({data}) { } export default function ErrataDetailLoader() { + const slug = useLocation().pathname.substring(1); + return (
- +
); } diff --git a/src/app/pages/errata-detail/progress-bar/progress-bar.js b/src/app/pages/errata-detail/progress-bar/progress-bar.tsx similarity index 79% rename from src/app/pages/errata-detail/progress-bar/progress-bar.js rename to src/app/pages/errata-detail/progress-bar/progress-bar.tsx index 4ffe18299..1a5599edc 100644 --- a/src/app/pages/errata-detail/progress-bar/progress-bar.js +++ b/src/app/pages/errata-detail/progress-bar/progress-bar.tsx @@ -2,14 +2,23 @@ import React from 'react'; import './progress-bar.scss'; // eslint-disable-next-line complexity -export default function ProgressBar({status, barStatus}) { - const thirdNodeFill = ['Corrected', 'Will correct'].includes(barStatus) ? - ' filled' : ' filled-no'; - const bars = barStatus ? 2 : { - 'In Review': 0, - 'Reviewed': 1, - 'Will Correct': 1 - }[status]; +export default function ProgressBar({ + status, + barStatus +}: { + status: string; + barStatus: string; +}) { + const thirdNodeFill = ['Corrected', 'Will correct'].includes(barStatus) + ? ' filled' + : ' filled-no'; + const bars = barStatus + ? 2 + : ({ + 'In Review': 0, + Reviewed: 1, + 'Will Correct': 1 + }[status] as number); const firstNodeClass = bars === 0 ? ' filled ' : ''; const secondNodeClass = bars === 1 ? ' filled' : ''; const thirdNodeClass = bars > 1 ? thirdNodeFill : ''; diff --git a/test/src/pages/errata/errata-detail.test.tsx b/test/src/pages/errata/errata-detail.test.tsx new file mode 100644 index 000000000..13790d6fc --- /dev/null +++ b/test/src/pages/errata/errata-detail.test.tsx @@ -0,0 +1,66 @@ +import React from 'react'; +import {render, screen} from '@testing-library/preact'; +import ErrataDetailLoader from '~/pages/errata-detail/errata-detail'; +import MemoryRouter from '~/../../test/helpers/future-memory-router'; +import ProgressBar from '~/pages/errata-detail/progress-bar/progress-bar'; +import * as HE from '~/helpers/errata'; +import * as DH from '~/helpers/use-document-head'; + +jest.spyOn(DH, 'setPageTitleAndDescriptionFromBookData').mockReturnValue(); + +describe('Errata Detail', () => { + it('renders', async () => { + render( + + + + ); + await screen.findByRole('heading', { + level: 1, + name: 'Errata Submission Details' + }); + await screen.findByText('You can check', {exact: false}); + }); + it('renders decision details', async () => { + const spySSED = jest + .spyOn(HE, 'shouldShowDecisionDetails') + .mockReturnValueOnce(true); + + render( + + + + ); + await screen.findByText('You can check', {exact: false}); + const bb = document.querySelector('.body-block.graybottom'); + + expect(bb?.textContent).toBe('Decision'); + spySSED.mockReset(); + }); + describe('progress bar', () => { + it('represents reviewed', () => { + render(); + const bar = document.querySelectorAll('.progress-bar-layer')[1]; + + expect(bar?.innerHTML).toBe( + '
' + ); + }); + it('represents will-correct', () => { + render(); + const bar = document.querySelectorAll('.progress-bar-layer')[1]; + + expect(bar?.innerHTML).toBe( + '
' + ); + }); + it('represents corrected', () => { + render(); + const bar = document.querySelectorAll('.progress-bar-layer')[1]; + + expect(bar?.innerHTML).toBe( + '
' + ); + }); + }); +});