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

96 lines
2.5 KiB
JavaScript
Raw Normal View History

2018-03-17 18:26:18 +05:30
import Vue from 'vue';
import fileIcon from '~/vue_shared/components/file_icon.vue';
2018-03-27 19:54:05 +05:30
import mountComponent from 'spec/helpers/vue_mount_component_helper';
2018-03-17 18:26:18 +05:30
describe('File Icon component', () => {
let vm;
let FileIcon;
beforeEach(() => {
FileIcon = Vue.extend(fileIcon);
});
afterEach(() => {
vm.$destroy();
});
it('should render a span element with an svg', () => {
vm = mountComponent(FileIcon, {
fileName: 'test.js',
});
expect(vm.$el.tagName).toEqual('SPAN');
expect(vm.$el.querySelector('span > svg')).toBeDefined();
});
it('should render a javascript icon based on file ending', () => {
vm = mountComponent(FileIcon, {
fileName: 'test.js',
});
2018-12-13 13:39:08 +05:30
expect(vm.$el.firstChild.firstChild.getAttribute('xlink:href')).toBe(
`${gon.sprite_file_icons}#javascript`,
);
2018-03-17 18:26:18 +05:30
});
it('should render a image icon based on file ending', () => {
vm = mountComponent(FileIcon, {
fileName: 'test.png',
});
2018-12-13 13:39:08 +05:30
expect(vm.$el.firstChild.firstChild.getAttribute('xlink:href')).toBe(
`${gon.sprite_file_icons}#image`,
);
2018-03-17 18:26:18 +05:30
});
it('should render a webpack icon based on file namer', () => {
vm = mountComponent(FileIcon, {
fileName: 'webpack.js',
});
2018-12-13 13:39:08 +05:30
expect(vm.$el.firstChild.firstChild.getAttribute('xlink:href')).toBe(
`${gon.sprite_file_icons}#webpack`,
);
2018-03-17 18:26:18 +05:30
});
it('should render a standard folder icon', () => {
vm = mountComponent(FileIcon, {
fileName: 'js',
folder: true,
});
2018-12-13 13:39:08 +05:30
expect(vm.$el.querySelector('span > svg > use').getAttribute('xlink:href')).toBe(
`${gon.sprite_file_icons}#folder`,
);
2018-03-17 18:26:18 +05:30
});
it('should render a loading icon', () => {
vm = mountComponent(FileIcon, {
fileName: 'test.js',
loading: true,
});
2018-12-05 23:21:45 +05:30
const { classList } = vm.$el.querySelector('i');
2018-12-13 13:39:08 +05:30
2018-12-05 23:21:45 +05:30
expect(classList.contains('fa')).toEqual(true);
expect(classList.contains('fa-spin')).toEqual(true);
expect(classList.contains('fa-spinner')).toEqual(true);
expect(classList.contains('fa-1x')).toEqual(true);
2018-03-17 18:26:18 +05:30
});
it('should add a special class and a size class', () => {
vm = mountComponent(FileIcon, {
fileName: 'test.js',
cssClasses: 'extraclasses',
size: 120,
});
2018-11-08 19:23:39 +05:30
const { classList } = vm.$el.firstChild;
2018-03-17 18:26:18 +05:30
const containsSizeClass = classList.contains('s120');
const containsCustomClass = classList.contains('extraclasses');
2018-12-13 13:39:08 +05:30
2018-03-17 18:26:18 +05:30
expect(containsSizeClass).toBe(true);
expect(containsCustomClass).toBe(true);
});
});