2020-04-22 19:07:51 +05:30
|
|
|
import { GlLoadingIcon, GlIcon } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
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');
|
2022-08-27 11:52:29 +05:30
|
|
|
const findGlIcon = () => wrapper.findComponent(GlIcon);
|
2019-12-04 20:38:33 +05:30
|
|
|
const getIconName = () =>
|
2023-04-23 21:23:45 +05:30
|
|
|
findSvgIcon().find('use').element.getAttribute('href').replace(`${gon.sprite_file_icons}#`, '');
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
const createComponent = (props = {}) => {
|
|
|
|
wrapper = shallowMount(FileIcon, {
|
|
|
|
propsData: { ...props },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
2022-01-26 12:08:38 +05:30
|
|
|
${'index.js'} | ${'javascript'}
|
2019-12-04 20:38:33 +05:30
|
|
|
${'test.png'} | ${'image'}
|
2020-10-24 23:57:45 +05:30
|
|
|
${'test.PNG'} | ${'image'}
|
|
|
|
${'.npmrc'} | ${'npm'}
|
|
|
|
${'.Npmrc'} | ${'file'}
|
2019-12-04 20:38:33 +05:30
|
|
|
${'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,
|
|
|
|
});
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(true);
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|