From b8c5db48a6d4711e4f7d27f11bd55cc9075b647a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Thu, 13 Jun 2019 16:56:41 +0200 Subject: [PATCH] Implement prefix of image urls with a filter Fix #820 Ok, so after I would have to use the same method in three different locations (`` 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. --- webapp/components/Avatar/Avatar.spec.js | 2 + webapp/components/Avatar/Avatar.vue | 12 +++--- webapp/components/Badges.vue | 6 +-- webapp/components/Image/index.vue | 20 ---------- webapp/components/Image/spec.js | 39 ------------------- webapp/components/Password/Change.spec.js | 2 + webapp/components/User/spec.js | 2 + .../comments/CommentList/CommentList.spec.js | 2 + webapp/pages/profile/_id/_slug.spec.js | 2 + webapp/pages/settings/my-social-media.spec.js | 2 + webapp/pages/settings/my-social-media.vue | 11 +----- webapp/plugins/vue-filters.js | 4 ++ 12 files changed, 24 insertions(+), 80 deletions(-) delete mode 100644 webapp/components/Image/index.vue delete mode 100644 webapp/components/Image/spec.js diff --git a/webapp/components/Avatar/Avatar.spec.js b/webapp/components/Avatar/Avatar.spec.js index ae91fecfe..d3ebcb030 100644 --- a/webapp/components/Avatar/Avatar.spec.js +++ b/webapp/components/Avatar/Avatar.spec.js @@ -1,9 +1,11 @@ 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 = {} diff --git a/webapp/components/Avatar/Avatar.vue b/webapp/components/Avatar/Avatar.vue index 0d997c745..ec2f9b28b 100644 --- a/webapp/components/Avatar/Avatar.vue +++ b/webapp/components/Avatar/Avatar.vue @@ -1,5 +1,10 @@ diff --git a/webapp/components/Image/spec.js b/webapp/components/Image/spec.js deleted file mode 100644 index be568964a..000000000 --- a/webapp/components/Image/spec.js +++ /dev/null @@ -1,39 +0,0 @@ -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') - }) - }) -}) diff --git a/webapp/components/Password/Change.spec.js b/webapp/components/Password/Change.spec.js index cffe86466..a15695a55 100644 --- a/webapp/components/Password/Change.spec.js +++ b/webapp/components/Password/Change.spec.js @@ -1,10 +1,12 @@ import { mount, createLocalVue } from '@vue/test-utils' import ChangePassword from './Change.vue' import Styleguide from '@human-connection/styleguide' +import Filters from '~/plugins/vue-filters' const localVue = createLocalVue() localVue.use(Styleguide) +localVue.use(Filters) describe('ChangePassword.vue', () => { let mocks diff --git a/webapp/components/User/spec.js b/webapp/components/User/spec.js index 56bdc10f1..312615a5b 100644 --- a/webapp/components/User/spec.js +++ b/webapp/components/User/spec.js @@ -2,6 +2,7 @@ import { mount, createLocalVue, RouterLinkStub } from '@vue/test-utils' import User from './index' import Vuex from 'vuex' import VTooltip from 'v-tooltip' +import Filters from '~/plugins/vue-filters' import Styleguide from '@human-connection/styleguide' @@ -11,6 +12,7 @@ const filter = jest.fn(str => str) localVue.use(Vuex) localVue.use(VTooltip) localVue.use(Styleguide) +localVue.use(Filters) localVue.filter('truncate', filter) diff --git a/webapp/components/comments/CommentList/CommentList.spec.js b/webapp/components/comments/CommentList/CommentList.spec.js index 9bfa13ea5..c4ee0624c 100644 --- a/webapp/components/comments/CommentList/CommentList.spec.js +++ b/webapp/components/comments/CommentList/CommentList.spec.js @@ -3,11 +3,13 @@ import CommentList from '.' import Empty from '~/components/Empty' import Vuex from 'vuex' import Styleguide from '@human-connection/styleguide' +import Filters from '~/plugins/vue-filters' const localVue = createLocalVue() localVue.use(Styleguide) localVue.use(Vuex) +localVue.use(Filters) localVue.filter('truncate', string => string) config.stubs['v-popover'] = '' diff --git a/webapp/pages/profile/_id/_slug.spec.js b/webapp/pages/profile/_id/_slug.spec.js index 1bb0eea2e..3c849f538 100644 --- a/webapp/pages/profile/_id/_slug.spec.js +++ b/webapp/pages/profile/_id/_slug.spec.js @@ -2,11 +2,13 @@ import { config, mount, shallowMount, createLocalVue } from '@vue/test-utils' import ProfileSlug from './_slug.vue' import Vuex from 'vuex' import Styleguide from '@human-connection/styleguide' +import Filters from '~/plugins/vue-filters' const localVue = createLocalVue() localVue.use(Vuex) localVue.use(Styleguide) +localVue.use(Filters) localVue.filter('date', d => d) config.stubs['no-ssr'] = '' diff --git a/webapp/pages/settings/my-social-media.spec.js b/webapp/pages/settings/my-social-media.spec.js index 34793e066..55ba27bb8 100644 --- a/webapp/pages/settings/my-social-media.spec.js +++ b/webapp/pages/settings/my-social-media.spec.js @@ -2,11 +2,13 @@ import { mount, createLocalVue } from '@vue/test-utils' import MySocialMedia from './my-social-media.vue' import Vuex from 'vuex' import Styleguide from '@human-connection/styleguide' +import Filters from '~/plugins/vue-filters' const localVue = createLocalVue() localVue.use(Vuex) localVue.use(Styleguide) +localVue.use(Filters) describe('my-social-media.vue', () => { let wrapper diff --git a/webapp/pages/settings/my-social-media.vue b/webapp/pages/settings/my-social-media.vue index b53df6170..948e77407 100644 --- a/webapp/pages/settings/my-social-media.vue +++ b/webapp/pages/settings/my-social-media.vue @@ -4,12 +4,7 @@ - + Social Media link {{ link.url }}    @@ -44,12 +39,8 @@