Skip to content

Commit

Permalink
fix(page header): formats date in page header
Browse files Browse the repository at this point in the history
Formats the date in the PageHeader components

closes #181
  • Loading branch information
anguspiv committed Nov 15, 2022
1 parent a05f366 commit 6110d8b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/components/molecules/PageHeader/PageHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Image from 'next/image';
import { spacing, media } from '@styles/utils';
import { BreadCrumbs } from '@components/molecules/BreadCrumbs';
import { TagList } from '@components/molecules/TagList';
import { formatDate } from '@utils/date';

const headerCss = css`
display: flex;
Expand Down Expand Up @@ -90,14 +91,15 @@ export function PageHeader({
}) {
const hasDetails = !!publishDate;
const imageTop = variant === 'imageTop';
const formattedDate = formatDate(publishDate);

return (
<header css={headerCss}>
<h1 css={titleCss}>{title}</h1>
{!!location?.pathname && <BreadCrumbs location={location} />}
{hasDetails && (
<div css={detailsCss}>
{publishDate && <span css={detailCss}>{publishDate}</span>}
{formattedDate && <span css={detailCss}>{formattedDate}</span>}
{!!readingTime && <span css={readingTimeCss}>Reading Time: {readingTime} min.</span>}
</div>
)}
Expand Down
6 changes: 3 additions & 3 deletions src/components/molecules/PageHeader/PageHeader.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('<PageHeader />', () => {
<PageHeader
title="Test Title"
location={location}
publishDate="Dec. 2, 2010"
publishDate="2010-12-02"
readingTime={10}
tags={['Test Tag']}
excerpt={excerpt}
Expand All @@ -26,7 +26,7 @@ describe('<PageHeader />', () => {
expect(screen.getByRole('heading', { name: 'Test Title' })).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Somewhere' })).toHaveAttribute('href', '/somewhere');
expect(screen.getByText('Else Where')).toBeInTheDocument();
expect(screen.getByText('Dec. 2, 2010')).toBeInTheDocument();
expect(screen.getByText('Dec. 2nd, 2010')).toBeInTheDocument();
expect(screen.getByText('Reading Time: 10 min.')).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Test Tag' })).toHaveAttribute(
'href',
Expand All @@ -51,7 +51,7 @@ describe('<PageHeader />', () => {
<PageHeader
title="Test Title"
location={location}
publishDate="Dec. 2, 2010"
publishDate="2010-12-02"
readingTime={10}
tags={['Test Tag']}
excerpt={excerpt}
Expand Down

0 comments on commit 6110d8b

Please sign in to comment.