mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Fix #820 Ok, so after I would have to use the same method in three different locations (`<ds-card>` expects an `image` attribute but cannot render entire components) I decided to implement the prefix of image urls with a filter rather than a component. The downside of this is that we have to add the filter on a lot of component tests. The benefit is less components and hopefully less complexity.
72 lines
1.5 KiB
JavaScript
72 lines
1.5 KiB
JavaScript
import { mount, createLocalVue } from '@vue/test-utils'
|
|
import Styleguide from '@human-connection/styleguide'
|
|
import Avatar from './Avatar.vue'
|
|
import Filters from '~/plugins/vue-filters'
|
|
|
|
const localVue = createLocalVue()
|
|
localVue.use(Styleguide)
|
|
localVue.use(Filters)
|
|
|
|
describe('Avatar.vue', () => {
|
|
let propsData = {}
|
|
|
|
const Wrapper = () => {
|
|
return mount(Avatar, { propsData, localVue })
|
|
}
|
|
|
|
it('renders no image', () => {
|
|
expect(
|
|
Wrapper()
|
|
.find('img')
|
|
.exists(),
|
|
).toBe(false)
|
|
})
|
|
|
|
it('renders an icon', () => {
|
|
expect(
|
|
Wrapper()
|
|
.find('.ds-icon')
|
|
.exists(),
|
|
).toBe(true)
|
|
})
|
|
|
|
describe('given a user', () => {
|
|
describe('with a relative avatar url', () => {
|
|
beforeEach(() => {
|
|
propsData = {
|
|
user: {
|
|
avatar: '/avatar.jpg',
|
|
},
|
|
}
|
|
})
|
|
|
|
it('adds a prefix to load the image from the uploads service', () => {
|
|
expect(
|
|
Wrapper()
|
|
.find('img')
|
|
.attributes('src'),
|
|
).toBe('/api/avatar.jpg')
|
|
})
|
|
})
|
|
|
|
describe('with an absolute avatar url', () => {
|
|
beforeEach(() => {
|
|
propsData = {
|
|
user: {
|
|
avatar: 'http://lorempixel.com/640/480/animals',
|
|
},
|
|
}
|
|
})
|
|
|
|
it('keeps the avatar URL as is', () => {
|
|
// e.g. our seeds have absolute image URLs
|
|
expect(
|
|
Wrapper()
|
|
.find('img')
|
|
.attributes('src'),
|
|
).toBe('http://lorempixel.com/640/480/animals')
|
|
})
|
|
})
|
|
})
|
|
})
|