2018-03-17 18:26:18 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
import mountComponent from 'helpers/vue_mount_component_helper';
|
2020-01-01 13:55:28 +05:30
|
|
|
import itemStatsValueComponent from '~/groups/components/item_stats_value.vue';
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
const createComponent = ({ title, cssClass, iconName, tooltipPlacement, value }) => {
|
|
|
|
const Component = Vue.extend(itemStatsValueComponent);
|
|
|
|
|
|
|
|
return mountComponent(Component, {
|
|
|
|
title,
|
|
|
|
cssClass,
|
|
|
|
iconName,
|
|
|
|
tooltipPlacement,
|
|
|
|
value,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('ItemStatsValueComponent', () => {
|
|
|
|
describe('computed', () => {
|
|
|
|
let vm;
|
|
|
|
const itemConfig = {
|
|
|
|
title: 'Subgroups',
|
|
|
|
cssClass: 'number-subgroups',
|
|
|
|
iconName: 'folder',
|
|
|
|
tooltipPlacement: 'left',
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('isValuePresent', () => {
|
|
|
|
it('returns true if non-empty `value` is present', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
vm = createComponent({ ...itemConfig, value: 10 });
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.isValuePresent).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false if empty `value` is present', () => {
|
|
|
|
vm = createComponent(itemConfig);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.isValuePresent).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('template', () => {
|
|
|
|
let vm;
|
|
|
|
beforeEach(() => {
|
|
|
|
vm = createComponent({
|
|
|
|
title: 'Subgroups',
|
|
|
|
cssClass: 'number-subgroups',
|
|
|
|
iconName: 'folder',
|
|
|
|
tooltipPlacement: 'left',
|
|
|
|
value: 10,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it('renders component element correctly', () => {
|
|
|
|
expect(vm.$el.classList.contains('number-subgroups')).toBeTruthy();
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelectorAll('svg').length).toBeGreaterThan(0);
|
|
|
|
expect(vm.$el.querySelectorAll('.stat-value').length).toBeGreaterThan(0);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders element tooltip correctly', () => {
|
|
|
|
expect(vm.$el.dataset.originalTitle).toBe('Subgroups');
|
|
|
|
expect(vm.$el.dataset.placement).toBe('left');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders element icon correctly', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(vm.$el.querySelector('svg').getAttribute('data-testid')).toBe('folder-icon');
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders value count correctly', () => {
|
|
|
|
expect(vm.$el.querySelector('.stat-value').innerText.trim()).toContain('10');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|