-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(REC-740): refacto chapter card
- Loading branch information
1 parent
044cf70
commit 5997bb0
Showing
8 changed files
with
203 additions
and
148 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
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
30 changes: 30 additions & 0 deletions
30
front/components/ChapterCard/Paragraphs/Paragraphs.spec.js
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 Paragraphs from './Paragraphs.vue' | ||
|
||
describe('Component | Paragraphs.vue', () => { | ||
let wrapper | ||
let propsData | ||
|
||
beforeEach(() => { | ||
propsData = { title: 'title', chapterText: ['voilà', ''] } | ||
}) | ||
|
||
describe('template', () => { | ||
it('should match snapshot with text', () => { | ||
wrapper = shallowMount(Paragraphs, { propsData }) | ||
expect(wrapper).toMatchSnapshot() | ||
}) | ||
|
||
it('should match snapshot with link', () => { | ||
propsData = { title: 'title', chapterText: ['https://www.rec.me'] } | ||
wrapper = shallowMount(Paragraphs, { propsData }) | ||
expect(wrapper).toMatchSnapshot() | ||
}) | ||
|
||
it('should match snapshot with video', () => { | ||
propsData = { title: 'title', chapterText: ['https://www.youtu.be/embed/123'] } | ||
wrapper = shallowMount(Paragraphs, { propsData }) | ||
expect(wrapper).toMatchSnapshot() | ||
}) | ||
}) | ||
}) | ||
|
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,129 @@ | ||
<template> | ||
<footer class="chapter__footer"> | ||
<ul | ||
v-for="paragraph in paragraphs" | ||
:key="paragraph.text" | ||
class="paragraph-container"> | ||
<li | ||
v-if="paragraph" | ||
class="paragraph"> | ||
<iframe | ||
v-if="paragraph.iframeSrc" | ||
:width="dimensions.width" | ||
:height="dimensions.height" | ||
:src="paragraph.iframeSrc" | ||
:title="title" | ||
class="youtube-iframe" | ||
allow="accelerometer; encrypted-media; gyroscope;" | ||
allowfullscreen/> | ||
<p | ||
v-else-if="paragraph.link" | ||
class="chapter__footer_text"> | ||
<a | ||
:href="paragraph.link" | ||
rel="noreferrer" | ||
target="_blank"> | ||
{{ paragraph.link }} | ||
</a> | ||
</p> | ||
<h3 | ||
v-else | ||
class="chapter__footer_text"> | ||
{{ paragraph.text }} | ||
</h3> | ||
</li> | ||
</ul> | ||
</footer> | ||
</template> | ||
<script> | ||
import { iframeDimensions } from '../../../services' | ||
import { | ||
generateCleanUrlLink, | ||
generateIframeLink, | ||
urlTester, | ||
youtubeEmbedUrlTester, | ||
} from './paragraph-link-utils' | ||
export default { | ||
name: 'Paragraphs', | ||
props: { | ||
chapterText: { type: Array, default: () => [] }, | ||
title: { type: String, default: () => '' }, | ||
}, | ||
data: () => ({ dimensions: iframeDimensions() }), | ||
computed: { | ||
paragraphs() { | ||
return this.chapterText | ||
.filter(paragraph => !!paragraph) | ||
.map(this.enhanceParagraph) | ||
}, | ||
}, | ||
methods: { | ||
enhanceParagraph(paragraph) { | ||
return { | ||
iframeSrc: youtubeEmbedUrlTester(paragraph) ? generateIframeLink(paragraph) : undefined, | ||
link: urlTester(paragraph) ? generateCleanUrlLink(paragraph) : undefined, | ||
text: paragraph, | ||
} | ||
}, | ||
}, | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.chapter__footer { | ||
text-align: center; | ||
padding: 0 15px; | ||
border-top: 1px solid #E6E6E6; | ||
} | ||
.chapter__footer button { | ||
text-transform: uppercase; | ||
color: #D14800; | ||
background: #FFFFFF; | ||
border: 1px solid #D14800; | ||
cursor: pointer; | ||
padding: 15px 30px; | ||
border-radius: 4px; | ||
width: 100%; | ||
margin-bottom: 10px; | ||
font-weight: 700; | ||
} | ||
.chapter__footer button:hover { | ||
background: #D14800; | ||
color: #FFFFFF; | ||
} | ||
.chapter__footer button:disabled, | ||
.chapter__footer button:active { | ||
background: #BDBDBD; | ||
border-color: #616161; | ||
color: #FAFAFA; | ||
cursor: auto; | ||
} | ||
.youtube-iframe { | ||
margin: 30px 0; | ||
border: none; | ||
} | ||
.chapter__footer_text { | ||
font-size: 18px; | ||
word-spacing: 1px; | ||
} | ||
.paragraph { | ||
list-style-type: none; | ||
} | ||
.paragraph-container { | ||
padding: 0; | ||
} | ||
@media only screen and (min-width: 640px) { | ||
.chapter__footer_text { | ||
font-weight: lighter; | ||
} | ||
} | ||
</style> |
33 changes: 33 additions & 0 deletions
33
front/components/ChapterCard/Paragraphs/__snapshots__/Paragraphs.spec.js.snap
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,33 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Component | Paragraphs.vue template should match snapshot with link 1`] = ` | ||
<footer class="chapter__footer"> | ||
<ul class="paragraph-container"> | ||
<li class="paragraph"> | ||
<p class="chapter__footer_text"><a href="https://www.rec.me" rel="noreferrer" target="_blank"> | ||
https://www.rec.me | ||
</a></p> | ||
</li> | ||
</ul> | ||
</footer> | ||
`; | ||
|
||
exports[`Component | Paragraphs.vue template should match snapshot with text 1`] = ` | ||
<footer class="chapter__footer"> | ||
<ul class="paragraph-container"> | ||
<li class="paragraph"> | ||
<h3 class="chapter__footer_text"> | ||
voilà | ||
</h3> | ||
</li> | ||
</ul> | ||
</footer> | ||
`; | ||
|
||
exports[`Component | Paragraphs.vue template should match snapshot with video 1`] = ` | ||
<footer class="chapter__footer"> | ||
<ul class="paragraph-container"> | ||
<li class="paragraph"><iframe width="512" height="288" src="https://www.youtu.be/embed/123?rel=0&modestbranding=1" title="title" allow="accelerometer; encrypted-media; gyroscope;" allowfullscreen="allowfullscreen" class="youtube-iframe"></iframe></li> | ||
</ul> | ||
</footer> | ||
`; |
File renamed without changes.
File renamed without changes.
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