Implement first test for Notification

Fixed a bug along the way `(post.contentExcerpt == null)`
This commit is contained in:
Robert Schäfer 2019-04-16 23:13:55 +02:00
parent af60ad39a4
commit 128480fd0e
2 changed files with 49 additions and 1 deletions

View File

@ -20,10 +20,13 @@
/>
</no-ssr>
<ds-space margin-bottom="x-small" />
<!-- eslint-disable vue/no-v-html -->
<!-- TODO: replace editor content with tiptap render view -->
<div
class="hc-editor-content"
v-html="excerpt"
/>
<!-- eslint-enable vue/no-v-html -->
</ds-card>
</template>
@ -43,8 +46,10 @@ export default {
},
computed: {
excerpt() {
const { contentExcerpt } = this.post
if (!contentExcerpt) return ''
// remove all links from excerpt to prevent issues with the sorrounding link
let excerpt = this.post.contentExcerpt.replace(/<a.*>(.+)<\/a>/gim, '$1')
let excerpt = contentExcerpt.replace(/<a.*>(.+)<\/a>/gim, '$1')
// do not display content that is only linebreaks
if (excerpt.replace(/<br>/gim, '').trim() === '') {
excerpt = ''

View File

@ -0,0 +1,43 @@
import { config, mount, createLocalVue, RouterLinkStub } from '@vue/test-utils'
import Notification from '.'
import Styleguide from '@human-connection/styleguide'
const localVue = createLocalVue()
localVue.use(Styleguide)
config.stubs['no-ssr'] = '<span><slot /></span>'
describe('Notification', () => {
let wrapper
let stubs
let propsData
beforeEach(() => {
propsData = {}
stubs = {
NuxtLink: RouterLinkStub
}
})
const Wrapper = () => {
return mount(Notification, {
stubs,
propsData,
localVue
})
}
describe('given a notification', () => {
beforeEach(() => {
propsData.notification = {
post: {
title: "It's a title"
}
}
})
it('renders title', () => {
expect(Wrapper().text()).toContain("It's a title")
})
})
})