Commit 6ff5e0c3 authored by Tim Zallmann's avatar Tim Zallmann

Updated icon.vue to be more inline with other components + added spec for it

parent 3f315370
...@@ -43,7 +43,6 @@ ...@@ -43,7 +43,6 @@
computed: { computed: {
cssClass() { cssClass() {
const className = this.status.group; const className = this.status.group;
return className ? `ci-status ci-${className}` : 'ci-status'; return className ? `ci-status ci-${className}` : 'ci-status';
}, },
}, },
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
/> />
*/ */
export default { export default {
props: { props: {
name: { name: {
...@@ -27,7 +26,7 @@ ...@@ -27,7 +26,7 @@
default: 0, default: 0,
}, },
cssClass: { cssClasses: {
type: String, type: String,
required: false, required: false,
default: '', default: '',
...@@ -38,17 +37,15 @@ ...@@ -38,17 +37,15 @@
spriteHref() { spriteHref() {
return `${gon.sprite_icons}#${this.name}`; return `${gon.sprite_icons}#${this.name}`;
}, },
fullCssClass() { iconSizeClass() {
let classString = '' || this.cssClass; return this.size ? `s${this.size}` : '';
if (this.size) classString += `s${this.size}`;
return classString;
}, },
}, },
}; };
</script> </script>
<template> <template>
<svg <svg
:class="fullCssClass"> :class="[iconSizeClass, cssClasses]">
<use <use
v-bind="{'xlink:href':spriteHref}"/> v-bind="{'xlink:href':spriteHref}"/>
</svg> </svg>
......
import Vue from 'vue';
import Icon from '~/vue_shared/components/icon.vue';
const IconComponent = Vue.extend(Icon);
fdescribe('Sprite Icon Component', function () {
describe('Initialization', function () {
beforeEach(function () {
this.propsData = {
name: 'test',
size: 99,
cssClasses: 'extraclasses',
};
this.icon = new IconComponent({
propsData: this.propsData,
}).$mount();
});
it('should return a defined Vue component', function () {
expect(this.icon).toBeDefined();
});
it('should have <svg> as a child element', function () {
expect(this.icon.$el.tagName).toBe('svg');
});
it('should have <use> as a child element with the correct href', function () {
expect(this.icon.$el.firstChild.tagName).toBe('use');
expect(this.icon.$el.firstChild.getAttribute('xlink:href')).toBe(`${gon.sprite_icons}#test`);
});
it('should properly compute iconSizeClass', function () {
expect(this.icon.iconSizeClass).toBe('s99');
});
it('should properly render img css', function () {
const classList = this.icon.$el.classList;
const containsSizeClass = classList.contains('s99');
const containsCustomClass = classList.contains('extraclasses');
expect(containsSizeClass).toBe(true);
expect(containsCustomClass).toBe(true);
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment