Refactor test, component

- Remove redundant code
- change socialMediaUrl to add the attributes().href since that's the url
- grab last element of url as username, makes an assumption, but a safer one
This commit is contained in:
Matt Rider 2019-04-12 08:34:06 -03:00
parent 366c5d776b
commit 444f01f879
2 changed files with 30 additions and 32 deletions

View File

@ -202,14 +202,12 @@
</p> </p>
</template> </template>
</ds-card> </ds-card>
<ds-space />
<ds-space <ds-space
v-if="user.socialMedia && user.socialMedia.length" v-if="user.socialMedia && user.socialMedia.length"
margin="x-small" margin="large"
/> >
<ds-card style="position: relative; height: auto;"> <ds-card style="position: relative; height: auto;">
<ds-space <ds-space
v-if="user.socialMedia && user.socialMedia.length"
margin="x-small" margin="x-small"
> >
<ds-text <ds-text
@ -218,13 +216,12 @@
> >
{{ $t('profile.socialMedia') }} {{ user.name | truncate(15) }}? {{ $t('profile.socialMedia') }} {{ user.name | truncate(15) }}?
</ds-text> </ds-text>
<template v-if="user.socialMedia && user.socialMedia.length"> <template>
<ds-space <ds-space
v-for="link in socialMediaLinks" v-for="link in socialMediaLinks"
:key="link.username" :key="link.username"
margin="x-small" margin="x-small"
> >
<!-- TODO: find better solution for rendering errors -->
<a :href="link.url"> <a :href="link.url">
<ds-avatar <ds-avatar
:image="link.favicon" :image="link.favicon"
@ -235,6 +232,7 @@
</template> </template>
</ds-space> </ds-space>
</ds-card> </ds-card>
</ds-space>
</ds-flex-item> </ds-flex-item>
<ds-flex-item :width="{ base: '100%', sm: 3, md: 5, lg: 3 }"> <ds-flex-item :width="{ base: '100%', sm: 3, md: 5, lg: 3 }">
<ds-flex <ds-flex
@ -391,7 +389,7 @@ export default {
) )
const [domain] = matches || [] const [domain] = matches || []
const favicon = domain ? `${domain}/favicon.ico` : null const favicon = domain ? `${domain}/favicon.ico` : null
const username = url.split('/')[3] const username = url.split('/').pop()
return { url, username, favicon } return { url, username, favicon }
}) })
} }

View File

@ -68,8 +68,8 @@ describe('my-social-media.vue', () => {
it("displays a link to the currentUser's social media", () => { it("displays a link to the currentUser's social media", () => {
wrapper = Wrapper() wrapper = Wrapper()
const socialMediaLink = wrapper.find('a') const socialMediaLink = wrapper.find('a').attributes().href
expect(socialMediaLink.attributes().href).toBe(socialMediaUrl) expect(socialMediaLink).toBe(socialMediaUrl)
}) })
}) })