debian-mirror-gitlab/spec/frontend/groups/components/item_type_icon_spec.js

54 lines
1.4 KiB
JavaScript
Raw Normal View History

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 ItemTypeIcon from '~/groups/components/item_type_icon.vue';
2018-03-17 18:26:18 +05:30
import { ITEM_TYPE } from '../mock_data';
2021-01-03 14:25:43 +05:30
describe('ItemTypeIcon', () => {
let wrapper;
2018-03-17 18:26:18 +05:30
2021-01-03 14:25:43 +05:30
const defaultProps = {
itemType: ITEM_TYPE.GROUP,
isGroupOpen: false,
};
2018-12-13 13:39:08 +05:30
2021-01-03 14:25:43 +05:30
const createComponent = (props = {}) => {
wrapper = shallowMount(ItemTypeIcon, {
propsData: { ...defaultProps, ...props },
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
afterEach(() => {
if (wrapper) {
wrapper.destroy();
wrapper = null;
}
});
2018-12-13 13:39:08 +05:30
2021-01-03 14:25:43 +05:30
const findGlIcon = () => wrapper.find(GlIcon);
2018-03-17 18:26:18 +05:30
2021-01-03 14:25:43 +05:30
describe('template', () => {
it('renders component template correctly', () => {
createComponent();
2018-12-13 13:39:08 +05:30
2021-01-03 14:25:43 +05:30
expect(wrapper.classes()).toContain('item-type-icon');
2018-03-17 18:26:18 +05:30
});
2021-01-03 14:25:43 +05:30
it.each`
type | isGroupOpen | icon
${ITEM_TYPE.GROUP} | ${true} | ${'folder-open'}
${ITEM_TYPE.GROUP} | ${false} | ${'folder-o'}
${ITEM_TYPE.PROJECT} | ${true} | ${'bookmark'}
${ITEM_TYPE.PROJECT} | ${false} | ${'bookmark'}
`(
'shows "$icon" icon when `itemType` is "$type" and `isGroupOpen` is $isGroupOpen',
({ type, isGroupOpen, icon }) => {
createComponent({
itemType: type,
isGroupOpen,
});
expect(findGlIcon().props('name')).toBe(icon);
},
);
2018-03-17 18:26:18 +05:30
});
});