mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Sketch a test for a custom image component
@tansaku @aonomike I hope this clarifies the task. When you're done, feel free to use this component wherever we use `<img>` in `/webapp/`.
This commit is contained in:
parent
98ad101549
commit
5978adff68
23
webapp/components/Image/index.vue
Normal file
23
webapp/components/Image/index.vue
Normal file
@ -0,0 +1,23 @@
|
||||
<template>
|
||||
<img
|
||||
v-bind="imageProps"
|
||||
:src="imageSrc"
|
||||
>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
props: {
|
||||
imageProps: {
|
||||
type: Object,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
imageSrc() {
|
||||
// TODO implement
|
||||
return 'this should be an image source attribute'
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
43
webapp/components/Image/spec.js
Normal file
43
webapp/components/Image/spec.js
Normal file
@ -0,0 +1,43 @@
|
||||
import { shallowMount } from '@vue/test-utils'
|
||||
import Image from '.'
|
||||
|
||||
describe('Image', () => {
|
||||
let propsData = { imageProps: { class: 'hc-badge', src: '' } }
|
||||
|
||||
const Wrapper = () => {
|
||||
return shallowMount(Image, { propsData })
|
||||
}
|
||||
|
||||
it('renders', () => {
|
||||
expect(Wrapper().is('img')).toBe(true)
|
||||
})
|
||||
|
||||
it('passes properties down to `img`', () => {
|
||||
expect(Wrapper().classes()).toEqual(['hc-badge'])
|
||||
})
|
||||
|
||||
describe('given a relative `src`', () => {
|
||||
beforeEach(() => {
|
||||
propsData.imageProps.src = '/img/badges/fundraisingbox_de_airship.svg'
|
||||
})
|
||||
|
||||
it('adds a prefix to load the image from the backend', () => {
|
||||
expect(Wrapper().attributes('src')).toBe(
|
||||
'/api/img/badges/fundraisingbox_de_airship.svg'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('given an absolute `src`', () => {
|
||||
beforeEach(() => {
|
||||
propsData.imageProps.src = 'http://lorempixel.com/640/480/animals'
|
||||
})
|
||||
|
||||
it('keeps the URL as is', () => {
|
||||
// e.g. our seeds have absolute image URLs
|
||||
expect(Wrapper().attributes('src')).toBe(
|
||||
'http://lorempixel.com/640/480/animals'
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user