-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: Missing key prop * fix: Jest config to work with common-rendering * feat: Added KeyEvents to LiveLayout * chore: I ran prettier * feat: Removed superfluous caching Co-authored-by: Olly <olly.namey@theguardian.com> * fix: Formatting Co-authored-by: OllysCoding * fix: Add yarn command back in Co-authored by @OllysCoding * chore: Oh my God, how hard is this Co-Authored-By: Olly <9575458+OllysCoding@users.noreply.github.com> * fix: Skipping for now while we wait to fix jest config Co-Authored-By: Olly <9575458+OllysCoding@users.noreply.github.com> * fix: Added `preserveSymlinks` to jest config to workaround monorepo issues with jest kulshekhar/ts-jest#1336 (comment) * fix: Added `preserveSymLinks` to tsconfig.test kulshekhar/ts-jest#1336 (comment) * fix: Restore tests * fix: Restore previous config * refactor: Replace reduce with filter > map Co-authored-by: Olly <olly.namey@theguardian.com> Co-authored-by: Olly <9575458+OllysCoding@users.noreply.github.com>
- Loading branch information
1 parent
7f1ee41
commit 9ab4ca4
Showing
5 changed files
with
134 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
dotcom-rendering/src/web/components/KeyEventsContainer.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { render } from '@testing-library/react'; | ||
import { ArticleDisplay, ArticleDesign, ArticlePillar } from '@guardian/libs'; | ||
|
||
import { KeyEventsContainer } from './KeyEventsContainer'; | ||
|
||
const baseProperties = { | ||
id: '123', | ||
elements: [], | ||
primaryDateLine: '', | ||
secondaryDateLine: '', | ||
}; | ||
|
||
describe('KeyEventsContainer', () => { | ||
it('It should render KeyEventsContainer as expected', () => { | ||
const { container } = render( | ||
<KeyEventsContainer | ||
format={{ | ||
display: ArticleDisplay.Standard, | ||
design: ArticleDesign.Standard, | ||
theme: ArticlePillar.News, | ||
}} | ||
keyEvents={[ | ||
{ | ||
...baseProperties, | ||
blockFirstPublishedDisplay: | ||
'blockFirstPublishedDisplay', | ||
title: 'title', | ||
}, | ||
]} | ||
/>, | ||
); | ||
expect(container).toHaveTextContent('title'); | ||
}); | ||
|
||
it('It should not render events without a blockFirstPublishedDisplay property', () => { | ||
const { container } = render( | ||
<KeyEventsContainer | ||
format={{ | ||
display: ArticleDisplay.Standard, | ||
design: ArticleDesign.Standard, | ||
theme: ArticlePillar.News, | ||
}} | ||
keyEvents={[ | ||
{ | ||
...baseProperties, | ||
blockFirstPublishedDisplay: | ||
'blockFirstPublishedDisplay', | ||
title: 'title', | ||
}, | ||
{ ...baseProperties, title: 'should not exist' }, | ||
]} | ||
/>, | ||
); | ||
expect(container).toHaveTextContent('title'); | ||
expect(container).not.toHaveTextContent('should not exist'); | ||
}); | ||
|
||
it('It should not render events without a title property', () => { | ||
const { container } = render( | ||
<KeyEventsContainer | ||
format={{ | ||
display: ArticleDisplay.Standard, | ||
design: ArticleDesign.Standard, | ||
theme: ArticlePillar.News, | ||
}} | ||
keyEvents={[ | ||
{ | ||
...baseProperties, | ||
blockFirstPublishedDisplay: 'should exist', | ||
title: 'title', | ||
}, | ||
{ | ||
...baseProperties, | ||
blockFirstPublishedDisplay: 'should not exist', | ||
}, | ||
]} | ||
/>, | ||
); | ||
expect(container).toHaveTextContent('title'); | ||
expect(container).not.toHaveTextContent('should not exist'); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
dotcom-rendering/src/web/components/KeyEventsContainer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import KeyEvents, { | ||
KeyEvent, | ||
} from '@guardian/common-rendering/src/components/keyEvents'; | ||
|
||
type Props = { | ||
keyEvents: Block[]; | ||
format: ArticleFormat; | ||
}; | ||
|
||
export const KeyEventsContainer = ({ keyEvents, format }: Props) => { | ||
const transformedKeyEvents: KeyEvent[] = keyEvents | ||
.filter((keyEvent) => { | ||
return keyEvent.title && keyEvent.blockFirstPublishedDisplay; | ||
}) | ||
.map((keyEvent) => { | ||
return { | ||
text: keyEvent.title || '', // We fallback to '' here purely to keep ts happy | ||
url: `?page=with:block-${keyEvent.id}#block-${keyEvent.id}`, | ||
time: keyEvent.blockFirstPublishedDisplay || '', // We fallback to '' here purely to keep ts happy | ||
}; | ||
}); | ||
|
||
return ( | ||
<KeyEvents | ||
theme={format.theme} | ||
keyEvents={transformedKeyEvents} | ||
supportsDarkMode={false} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ | ||
"target": "ES2018" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */, | ||
} | ||
} |