debian-mirror-gitlab/spec/frontend/vue_shared/components/file_icon_spec.js

87 lines
2.2 KiB
JavaScript
Raw Normal View History

2019-12-04 20:38:33 +05:30
import { shallowMount } from '@vue/test-utils';
2020-04-22 19:07:51 +05:30
import { GlLoadingIcon, GlIcon } from '@gitlab/ui';
2019-12-04 20:38:33 +05:30
import FileIcon from '~/vue_shared/components/file_icon.vue';
2020-07-28 23:09:34 +05:30
import { FILE_SYMLINK_MODE } from '~/vue_shared/constants';
2019-12-04 20:38:33 +05:30
describe('File Icon component', () => {
let wrapper;
2020-07-28 23:09:34 +05:30
const findSvgIcon = () => wrapper.find('svg');
const findGlIcon = () => wrapper.find(GlIcon);
2019-12-04 20:38:33 +05:30
const getIconName = () =>
2020-07-28 23:09:34 +05:30
findSvgIcon()
2019-12-04 20:38:33 +05:30
.find('use')
.element.getAttribute('xlink:href')
.replace(`${gon.sprite_file_icons}#`, '');
const createComponent = (props = {}) => {
wrapper = shallowMount(FileIcon, {
propsData: { ...props },
});
};
afterEach(() => {
wrapper.destroy();
});
it('should render a span element and an icon', () => {
createComponent({
fileName: 'test.js',
});
expect(wrapper.element.tagName).toEqual('SPAN');
2020-07-28 23:09:34 +05:30
expect(findSvgIcon().exists()).toBeDefined();
2019-12-04 20:38:33 +05:30
});
it.each`
fileName | iconName
${'test.js'} | ${'javascript'}
${'test.png'} | ${'image'}
${'webpack.js'} | ${'webpack'}
`('should render a $iconName icon based on file ending', ({ fileName, iconName }) => {
createComponent({ fileName });
expect(getIconName()).toBe(iconName);
});
it('should render a standard folder icon', () => {
createComponent({
fileName: 'js',
folder: true,
});
2020-07-28 23:09:34 +05:30
expect(findSvgIcon().exists()).toBe(false);
expect(findGlIcon().classes()).toContain('folder-icon');
2019-12-04 20:38:33 +05:30
});
it('should render a loading icon', () => {
createComponent({
fileName: 'test.js',
loading: true,
});
expect(wrapper.find(GlLoadingIcon).exists()).toBe(true);
});
it('should add a special class and a size class', () => {
const size = 120;
createComponent({
fileName: 'test.js',
cssClasses: 'extraclasses',
size,
});
2020-07-28 23:09:34 +05:30
const classes = findSvgIcon().classes();
2019-12-04 20:38:33 +05:30
2020-07-28 23:09:34 +05:30
expect(classes).toContain(`s${size}`);
expect(classes).toContain('extraclasses');
});
it('should render a symlink icon', () => {
createComponent({
fileName: 'anything',
fileMode: FILE_SYMLINK_MODE,
});
expect(findSvgIcon().exists()).toBe(false);
expect(findGlIcon().attributes('name')).toBe('symlink');
2019-12-04 20:38:33 +05:30
});
});