diff --git a/webapp/components/Avatar/Avatar.spec.js b/webapp/components/Avatar/Avatar.spec.js new file mode 100644 index 000000000..ae91fecfe --- /dev/null +++ b/webapp/components/Avatar/Avatar.spec.js @@ -0,0 +1,69 @@ +import { mount, createLocalVue } from '@vue/test-utils' +import Styleguide from '@human-connection/styleguide' +import Avatar from './Avatar.vue' + +const localVue = createLocalVue() +localVue.use(Styleguide) + +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') + }) + }) + }) +}) diff --git a/webapp/components/Avatar/Avatar.vue b/webapp/components/Avatar/Avatar.vue new file mode 100644 index 000000000..2c5cf1ddc --- /dev/null +++ b/webapp/components/Avatar/Avatar.vue @@ -0,0 +1,33 @@ + + + diff --git a/webapp/components/User/index.vue b/webapp/components/User/index.vue index 82a08c5e1..fd435d0c5 100644 --- a/webapp/components/User/index.vue +++ b/webapp/components/User/index.vue @@ -3,10 +3,7 @@
- +
-
@@ -143,6 +137,7 @@ import { mapGetters } from 'vuex' import HcRelativeDateTime from '~/components/RelativeDateTime' import HcFollowButton from '~/components/FollowButton' import HcBadges from '~/components/Badges' +import HcAvatar from '~/components/Avatar/Avatar.vue' import Dropdown from '~/components/Dropdown' export default { @@ -150,6 +145,7 @@ export default { components: { HcRelativeDateTime, HcFollowButton, + HcAvatar, HcBadges, Dropdown, }, @@ -183,12 +179,6 @@ export default {