Skip to content
Snippets Groups Projects
Commit b73959a9 authored by Bryce Johnson's avatar Bryce Johnson
Browse files

Fixes per feedback on user avatar components.

parent 3c668fa0
No related branches found
No related tags found
No related merge requests found
Loading
@@ -16,12 +16,11 @@
Loading
@@ -16,12 +16,11 @@
*/ */
   
import defaultAvatarUrl from 'images/no_avatar.png'; import defaultAvatarUrl from 'images/no_avatar.png';
import UserAvatarSizeMixin from './user_avatar_size_mixin';
import TooltipMixin from '../../mixins/tooltip'; import TooltipMixin from '../../mixins/tooltip';
   
export default { export default {
name: 'UserAvatarImage', name: 'UserAvatarImage',
mixins: [UserAvatarSizeMixin, TooltipMixin], mixins: [TooltipMixin],
props: { props: {
imgSrc: { imgSrc: {
type: String, type: String,
Loading
@@ -58,8 +57,8 @@ export default {
Loading
@@ -58,8 +57,8 @@ export default {
tooltipContainer() { tooltipContainer() {
return this.tooltipText ? 'body' : null; return this.tooltipText ? 'body' : null;
}, },
imgCssClasses() { avatarSizeClass() {
return `avatar ${this.avatarSizeClass} ${this.cssClasses}`; return `s${this.size}`;
}, },
}, },
}; };
Loading
@@ -67,9 +66,11 @@ export default {
Loading
@@ -67,9 +66,11 @@ export default {
   
<template> <template>
<img <img
:class="imgCssClasses" class="avatar"
:class="[avatarSizeClass, cssClasses]"
:src="imgSrc" :src="imgSrc"
:style="avatarSizeStylesMap" :width="size"
:height="size"
:alt="imgAlt" :alt="imgAlt"
:data-container="tooltipContainer" :data-container="tooltipContainer"
:data-placement="tooltipPlacement" :data-placement="tooltipPlacement"
Loading
Loading
export default {
computed: {
avatarSizeStylesMap() {
return {
width: `${this.size}px`,
height: `${this.size}px`,
};
},
avatarSizeClass() {
return `s${this.size}`;
},
},
};
Loading
@@ -14,10 +14,7 @@
Loading
@@ -14,10 +14,7 @@
   
*/ */
   
import UserAvatarSizeMixin from './user_avatar_size_mixin';
export default { export default {
mixins: [UserAvatarSizeMixin],
props: { props: {
svg: { svg: {
type: String, type: String,
Loading
@@ -29,13 +26,19 @@ export default {
Loading
@@ -29,13 +26,19 @@ export default {
default: 20, default: 20,
}, },
}, },
computed: {
avatarSizeClass() {
return `s${this.size}`;
},
},
}; };
</script> </script>
   
<template> <template>
<svg <svg
:class="avatarSizeClass" :class="avatarSizeClass"
:style="avatarSizeStylesMap" :height="size"
:width="size"
v-html="svg"> v-html="svg">
</svg> </svg>
</template> </template>
Loading
Loading
Loading
@@ -18,8 +18,6 @@ describe('User Avatar Image Component', function () {
Loading
@@ -18,8 +18,6 @@ describe('User Avatar Image Component', function () {
this.userAvatarImage = new UserAvatarImageComponent({ this.userAvatarImage = new UserAvatarImageComponent({
propsData: this.propsData, propsData: this.propsData,
}).$mount(); }).$mount();
this.imageElement = this.userAvatarImage.$el.outerHTML;
}); });
   
it('should return a defined Vue component', function () { it('should return a defined Vue component', function () {
Loading
@@ -27,14 +25,7 @@ describe('User Avatar Image Component', function () {
Loading
@@ -27,14 +25,7 @@ describe('User Avatar Image Component', function () {
}); });
   
it('should have <img> as a child element', function () { it('should have <img> as a child element', function () {
const componentImgTag = this.userAvatarImage.$el.outerHTML; expect(this.userAvatarImage.$el.tagName).toBe('IMG');
expect(componentImgTag).toContain('<img');
});
it('should return neccessary props as defined', function () {
_.each(this.propsData, (val, key) => {
expect(this.userAvatarImage[key]).toBeDefined();
});
}); });
   
it('should properly compute tooltipContainer', function () { it('should properly compute tooltipContainer', function () {
Loading
@@ -42,19 +33,22 @@ describe('User Avatar Image Component', function () {
Loading
@@ -42,19 +33,22 @@ describe('User Avatar Image Component', function () {
}); });
   
it('should properly render tooltipContainer', function () { it('should properly render tooltipContainer', function () {
expect(this.imageElement).toContain('data-container="body"'); expect(this.userAvatarImage.$el.getAttribute('data-container')).toBe('body');
}); });
   
it('should properly compute avatarSizeClass', function () { it('should properly compute avatarSizeClass', function () {
expect(this.userAvatarImage.avatarSizeClass).toBe('s99'); expect(this.userAvatarImage.avatarSizeClass).toBe('s99');
}); });
   
it('should properly compute imgCssClasses', function () { it('should properly render img css', function () {
expect(this.userAvatarImage.imgCssClasses).toBe('avatar s99 myextraavatarclass'); const classList = this.userAvatarImage.$el.classList;
}); const containsAvatar = classList.contains('avatar');
const containsSizeClass = classList.contains('s99');
const containsCustomClass = classList.contains('myextraavatarclass');
   
it('should properly render imgCssClasses', function () { expect(containsAvatar).toBe(true);
expect(this.imageElement).toContain('avatar s99 myextraavatarclass'); expect(containsSizeClass).toBe(true);
expect(containsCustomClass).toBe(true);
}); });
}); });
}); });
Loading
@@ -35,13 +35,11 @@ describe('User Avatar Link Component', function () {
Loading
@@ -35,13 +35,11 @@ describe('User Avatar Link Component', function () {
}); });
   
it('should render <a> as a child element', function () { it('should render <a> as a child element', function () {
const componentLinkTag = this.userAvatarLink.$el.outerHTML; expect(this.userAvatarLink.$el.tagName).toBe('A');
expect(componentLinkTag).toContain('<a');
}); });
   
it('should have <img> as a child element', function () { it('should have <img> as a child element', function () {
const componentImgTag = this.userAvatarLink.$el.outerHTML; expect(this.userAvatarLink.$el.querySelector('img')).not.toBeNull();
expect(componentImgTag).toContain('<img');
}); });
   
it('should return neccessary props as defined', function () { it('should return neccessary props as defined', function () {
Loading
@@ -49,10 +47,4 @@ describe('User Avatar Link Component', function () {
Loading
@@ -49,10 +47,4 @@ describe('User Avatar Link Component', function () {
expect(this.userAvatarLink[key]).toBeDefined(); expect(this.userAvatarLink[key]).toBeDefined();
}); });
}); });
it('should include props in the rendered output', function () {
_.each(this.propsData, (val) => {
expect(this.userAvatarLink.$el.outerHTML).toContain(val);
});
});
}); });
import Vue from 'vue';
import UserAvatarSizeMixin from '~/vue_shared/components/user_avatar/user_avatar_size_mixin';
describe('User Avatar Size Mixin', () => {
beforeEach(() => {
this.vueInstance = new Vue({
data: {
size: 99,
},
mixins: [UserAvatarSizeMixin],
});
});
describe('#avatarSizeClass', () => {
it('should be a defined computed value', () => {
expect(this.vueInstance.avatarSizeClass).toBeDefined();
});
it('should correctly transform size into the class name', () => {
expect(this.vueInstance.avatarSizeClass).toBe('s99');
});
});
describe('#avatarSizeStylesMap', () => {
it('should be a defined computed value', () => {
expect(this.vueInstance.avatarSizeStylesMap).toBeDefined();
});
it('should return a correctly formatted styles width', () => {
expect(this.vueInstance.avatarSizeStylesMap.width).toBe('99px');
});
it('should return a correctly formatted styles height', () => {
expect(this.vueInstance.avatarSizeStylesMap.height).toBe('99px');
});
});
});
Loading
@@ -25,11 +25,5 @@ describe('User Avatar Svg Component', function () {
Loading
@@ -25,11 +25,5 @@ describe('User Avatar Svg Component', function () {
expect(this.userAvatarSvg.$el.tagName).toEqual('svg'); expect(this.userAvatarSvg.$el.tagName).toEqual('svg');
expect(this.userAvatarSvg.$el.innerHTML).toContain('<path'); expect(this.userAvatarSvg.$el.innerHTML).toContain('<path');
}); });
it('should return neccessary props as defined', function () {
_.each(this.propsData, (val, key) => {
expect(this.userAvatarSvg[key]).toBeDefined();
});
});
}); });
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment