Add support for `sizeClass`, defaults to `s40`

This commit is contained in:
kushalpandya 2017-09-04 21:12:27 +05:30
parent c47e1c3975
commit 8c70224d18
2 changed files with 30 additions and 8 deletions

View File

@ -9,6 +9,11 @@ export default {
type: String,
required: true,
},
sizeClass: {
type: String,
required: false,
default: 's40',
},
},
computed: {
/**
@ -38,7 +43,8 @@ export default {
<template>
<div
class="avatar s40 identicon"
class="avatar identicon"
:class="sizeClass"
:style="identiconStyles">
{{identiconTitle}}
</div>

View File

@ -1,25 +1,30 @@
import Vue from 'vue';
import identiconComponent from '~/vue_shared/components/identicon.vue';
const createComponent = () => {
const createComponent = (sizeClass) => {
const Component = Vue.extend(identiconComponent);
return new Component({
propsData: {
entityId: 1,
entityName: 'entity-name',
sizeClass,
},
}).$mount();
};
describe('IdenticonComponent', () => {
let vm;
beforeEach(() => {
vm = createComponent();
});
describe('computed', () => {
let vm;
beforeEach(() => {
vm = createComponent();
});
afterEach(() => {
vm.$destroy();
});
describe('identiconStyles', () => {
it('should return styles attribute value with `background-color` property', () => {
vm.entityId = 4;
@ -48,9 +53,20 @@ describe('IdenticonComponent', () => {
describe('template', () => {
it('should render identicon', () => {
const vm = createComponent();
expect(vm.$el.nodeName).toBe('DIV');
expect(vm.$el.classList.contains('identicon')).toBeTruthy();
expect(vm.$el.classList.contains('s40')).toBeTruthy();
expect(vm.$el.getAttribute('style').indexOf('background-color') > -1).toBeTruthy();
vm.$destroy();
});
it('should render identicon with provided sizing class', () => {
const vm = createComponent('s32');
expect(vm.$el.classList.contains('s32')).toBeTruthy();
vm.$destroy();
});
});
});