2021-01-03 14:25:43 +05:30
|
|
|
import { GlIcon } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2021-01-03 14:25:43 +05:30
|
|
|
import ItemStatsValue from '~/groups/components/item_stats_value.vue';
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
describe('ItemStatsValue', () => {
|
|
|
|
let wrapper;
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
const defaultProps = {
|
|
|
|
title: 'Subgroups',
|
|
|
|
cssClass: 'number-subgroups',
|
|
|
|
iconName: 'folder',
|
|
|
|
tooltipPlacement: 'left',
|
|
|
|
};
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
const createComponent = (props = {}) => {
|
|
|
|
wrapper = shallowMount(ItemStatsValue, {
|
|
|
|
propsData: { ...defaultProps, ...props },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
if (wrapper) {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
}
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
const findGlIcon = () => wrapper.find(GlIcon);
|
|
|
|
const findStatValue = () => wrapper.find('[data-testid="itemStatValue"]');
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
describe('template', () => {
|
|
|
|
describe('when `value` is not provided', () => {
|
|
|
|
it('does not render value count', () => {
|
|
|
|
createComponent();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(findStatValue().exists()).toBe(false);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
describe('when `value` is provided', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({
|
|
|
|
value: 10,
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it('renders component element correctly', () => {
|
|
|
|
expect(wrapper.classes()).toContain('number-subgroups');
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it('renders element tooltip correctly', () => {
|
|
|
|
expect(wrapper.attributes('title')).toBe('Subgroups');
|
|
|
|
expect(wrapper.attributes('data-placement')).toBe('left');
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it('renders element icon correctly', () => {
|
|
|
|
expect(findGlIcon().exists()).toBe(true);
|
|
|
|
expect(findGlIcon().props('name')).toBe('folder');
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it('renders value count correctly', () => {
|
|
|
|
expect(findStatValue().classes()).toContain('stat-value');
|
|
|
|
expect(findStatValue().text()).toBe('10');
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|