Skip to content

Commit cee7074

Browse files
hola-soy-milkjtfairbank
authored andcommitted
feat: Implement generic YouTube block
1 parent b73e9c2 commit cee7074

File tree

6 files changed

+42
-12
lines changed

6 files changed

+42
-12
lines changed

src/components/section/ContentBlock.spec.tsx

+11-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe('Blocks', () => {
1414
blocks = [
1515
factory.getBlockTitleNode({ text: 'My Title' }),
1616
factory.getBlockTextNode({ text: 'My text.' }),
17+
factory.getBlockYoutubeNode({ title: 'My video.' }),
1718
]
1819
})
1920

@@ -25,11 +26,13 @@ describe('Blocks', () => {
2526

2627
const text = getByText('My text.')
2728
expect(text).toBeTruthy()
29+
30+
const youTubeTitle = getByText('My video.')
31+
expect(youTubeTitle).toBeTruthy()
2832
})
2933

3034
it('gracefully drops unimplemented block types', () => {
3135
blocks = blocks.concat([
32-
factory.getBlockYoutubeNode(),
3336
factory.getBlockTimelineNode(),
3437
factory.getBlockImageNode(),
3538
factory.getBlockCardNode(),
@@ -42,9 +45,6 @@ describe('Blocks', () => {
4245
const text = getByText('My text.')
4346
expect(text).toBeTruthy()
4447

45-
const youtube = queryByText('youtube')
46-
expect(youtube).toBeFalsy()
47-
4848
const timelineEntry = queryByText('2020')
4949
expect(timelineEntry).toBeFalsy()
5050

@@ -84,7 +84,13 @@ describe('Block', () => {
8484
expect(text).toBeTruthy()
8585
})
8686

87-
test.todo('can render a youtube block')
87+
it('can render a youtube block', () => {
88+
const block = factory.getBlockYoutubeNode({ title: 'My video.' })
89+
const { getByText } = render(<Block block={block} />)
90+
const text = getByText('My video.')
91+
expect(text).toBeTruthy()
92+
})
93+
8894
test.todo('can render a timeline block')
8995
test.todo('can render a links list block')
9096
test.todo('can render an updates list block')

src/components/section/ContentBlock.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import {
55
BlockText as BlockTextType,
66
BlockTitle as BlockTitleType,
77
BlockUpdatesList as BlockUpdatesListType,
8+
BlockYoutube as BlockYoutubeType,
89
} from '../../types/generic-page.d'
910
import { BlockLinksList } from './blocks/BlockLinksList'
1011
import { BlockText } from './blocks/BlockText'
1112
import { BlockTitle } from './blocks/BlockTitle'
1213
import { BlockUpdatesList } from './blocks/BlockUpdatesList'
14+
import { BlockYouTube } from './blocks/BlockYouTube'
1315

1416
type BlocksProps = {
1517
blocks: BlockNode[]
@@ -35,10 +37,10 @@ export const Block: FC<BlockProps> = ({ block }) => {
3537
return <BlockLinksList block={block as BlockLinksListType} />
3638
case 'DABlockUpdatesList':
3739
return <BlockUpdatesList block={block as BlockUpdatesListType} />
40+
case 'DABlockYoutube':
41+
return <BlockYouTube block={block as BlockYoutubeType} />
3842

3943
// wishlist
40-
case 'DABlockYoutube':
41-
return null
4244
case 'DABlockTimeline':
4345
return null
4446
case 'DABlockImage':

src/components/section/Section.spec.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ describe('Sections', () => {
4242

4343
sections[1] = factory.getSectionGridNode({
4444
blocks: [
45-
factory.getBlockYoutubeNode(),
4645
factory.getBlockTimelineNode(),
4746
factory.getBlockImageNode(),
4847
factory.getBlockCardNode(),
@@ -56,9 +55,6 @@ describe('Sections', () => {
5655
const text = getByText('My text.')
5756
expect(text).toBeTruthy()
5857

59-
const youtube = queryByText('youtube')
60-
expect(youtube).toBeFalsy()
61-
6258
const timelineEntry = queryByText('2020')
6359
expect(timelineEntry).toBeFalsy()
6460

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { render } from '@testing-library/react'
2+
import { BlockYoutubeNode } from '../../../types/generic-page.d'
3+
import { BlockYouTube } from './BlockYouTube'
4+
5+
describe('BlockYouTube', () => {
6+
it('renders the title', () => {
7+
const block = {
8+
embedUrl: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
9+
title: 'My video',
10+
} as BlockYoutubeNode
11+
const { getByText } = render(<BlockYouTube block={block} />)
12+
const title = getByText('My video')
13+
expect(title).toBeTruthy()
14+
})
15+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { YouTubeEmbed } from '@components/youtube-embed/YouTubeEmbed'
2+
import { FC } from 'react'
3+
import { BlockYoutube as BlockYoutubeType } from '../../../types/generic-page.d'
4+
5+
type BlockYouTubeProps = {
6+
block: BlockYoutubeType
7+
}
8+
9+
export const BlockYouTube: FC<BlockYouTubeProps> = ({ block }) => {
10+
return <YouTubeEmbed videoUrl={block.embedUrl} videoTitle={block.title} />
11+
}

src/components/youtube-embed/YouTubeEmbed.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { FC, PropsWithChildren } from 'react'
33
export const YouTubeEmbed: FC<
44
PropsWithChildren<{
55
videoUrl: string
6-
videoTitle?: string
6+
videoTitle?: string | undefined
77
}>
88
> = ({ videoUrl, videoTitle }) => (
99
<figure>

0 commit comments

Comments
 (0)