debian-mirror-gitlab/spec/javascripts/vue_shared/components/identicon_spec.js

66 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-09-10 17:25:29 +05:30
import Vue from 'vue';
2018-03-17 18:26:18 +05:30
import identiconComponent from '~/vue_shared/components/identicon.vue';
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
const createComponent = (sizeClass) => {
const Component = Vue.extend(identiconComponent);
2017-09-10 17:25:29 +05:30
return new Component({
propsData: {
2018-03-17 18:26:18 +05:30
entityId: 1,
entityName: 'entity-name',
sizeClass,
2017-09-10 17:25:29 +05:30
},
}).$mount();
};
2018-03-17 18:26:18 +05:30
describe('IdenticonComponent', () => {
describe('computed', () => {
let vm;
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
beforeEach(() => {
vm = createComponent();
});
afterEach(() => {
vm.$destroy();
});
2017-09-10 17:25:29 +05:30
2018-11-18 11:00:15 +05:30
describe('identiconBackgroundClass', () => {
it('should return bg class based on entityId', () => {
2017-09-10 17:25:29 +05:30
vm.entityId = 4;
2018-11-18 11:00:15 +05:30
expect(vm.identiconBackgroundClass).toBeDefined();
expect(vm.identiconBackgroundClass).toBe('bg5');
2017-09-10 17:25:29 +05:30
});
});
describe('identiconTitle', () => {
it('should return first letter of entity title in uppercase', () => {
vm.entityName = 'dummy-group';
expect(vm.identiconTitle).toBeDefined();
expect(vm.identiconTitle).toBe('D');
});
});
});
describe('template', () => {
it('should render identicon', () => {
2018-03-17 18:26:18 +05:30
const vm = createComponent();
2017-09-10 17:25:29 +05:30
expect(vm.$el.nodeName).toBe('DIV');
expect(vm.$el.classList.contains('identicon')).toBeTruthy();
2018-03-17 18:26:18 +05:30
expect(vm.$el.classList.contains('s40')).toBeTruthy();
2018-11-18 11:00:15 +05:30
expect(vm.$el.classList.contains('bg2')).toBeTruthy();
2018-03-17 18:26:18 +05:30
vm.$destroy();
});
it('should render identicon with provided sizing class', () => {
const vm = createComponent('s32');
expect(vm.$el.classList.contains('s32')).toBeTruthy();
vm.$destroy();
2017-09-10 17:25:29 +05:30
});
});
});