2020-10-02 12:09:03 +00:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import { GlIcon } from '@gitlab/ui';
|
|
|
|
import ItemTypeIcon from '~/groups/components/item_type_icon.vue';
|
2017-10-04 14:10:24 +00:00
|
|
|
import { ITEM_TYPE } from '../mock_data';
|
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
describe('ItemTypeIcon', () => {
|
|
|
|
let wrapper;
|
2017-10-04 14:10:24 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
const defaultProps = {
|
|
|
|
itemType: ITEM_TYPE.GROUP,
|
|
|
|
isGroupOpen: false,
|
|
|
|
};
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
const createComponent = (props = {}) => {
|
|
|
|
wrapper = shallowMount(ItemTypeIcon, {
|
|
|
|
propsData: { ...defaultProps, ...props },
|
2017-10-04 14:10:24 +00:00
|
|
|
});
|
2020-10-02 12:09:03 +00:00
|
|
|
};
|
2017-10-04 14:10:24 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
afterEach(() => {
|
|
|
|
if (wrapper) {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
}
|
|
|
|
});
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
const findGlIcon = () => wrapper.find(GlIcon);
|
2017-10-04 14:10:24 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
describe('template', () => {
|
|
|
|
it('renders component template correctly', () => {
|
|
|
|
createComponent();
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
expect(wrapper.classes()).toContain('item-type-icon');
|
2017-10-04 14:10:24 +00:00
|
|
|
});
|
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
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);
|
|
|
|
},
|
|
|
|
);
|
2017-10-04 14:10:24 +00:00
|
|
|
});
|
|
|
|
});
|