Commit 42e694f3 authored by Tim Zallmann's avatar Tim Zallmann

Fixes Based on MR Discusssions

parent e4ff8407
...@@ -95,7 +95,7 @@ ...@@ -95,7 +95,7 @@
class="repo-file-name" class="repo-file-name"
> >
<file-icon <file-icon
:fileName="file.name" :file-name="file.name"
:loading="file.loading" :loading="file.loading"
:folder="file.type === 'tree'" :folder="file.type === 'tree'"
:opened="file.opened" :opened="file.opened"
......
...@@ -71,7 +71,7 @@ export default { ...@@ -71,7 +71,7 @@ export default {
:title="tab.url" :title="tab.url"
> >
<file-icon <file-icon
:fileName="tab.name" :file-name="tab.name"
:size="16" :size="16"
> >
</file-icon> </file-icon>
......
<script> <script>
import { getIconForFile } from './file_icon/file_icon_map'; import getIconForFile from './file_icon/file_icon_map';
import loadingIcon from '../../vue_shared/components/loading_icon.vue'; import loadingIcon from '../../vue_shared/components/loading_icon.vue';
import icon from '../../vue_shared/components/icon.vue'; import icon from '../../vue_shared/components/icon.vue';
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
size: { size: {
type: Number, type: Number,
required: false, required: false,
default: 0, default: 16,
}, },
cssClasses: { cssClasses: {
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
<icon <icon
v-if="!loading && folder" v-if="!loading && folder"
:name="folderIconName" :name="folderIconName"
:size="size || 16" :size="size"
/> />
<loading-icon <loading-icon
v-if="loading" v-if="loading"
......
...@@ -582,9 +582,8 @@ const fileNameIcons = { ...@@ -582,9 +582,8 @@ const fileNameIcons = {
'.drone.yml': 'drone', '.drone.yml': 'drone',
}; };
export const getIconForFile = name => export default function getIconForFile(name) {
fileNameIcons[name] || return fileNameIcons[name] ||
fileExtensionIcons[name ? name.split('.').pop() : ''] || fileExtensionIcons[name ? name.split('.').pop() : ''] ||
''; '';
}
export default getIconForFile;
import Vue from 'vue'; import Vue from 'vue';
import fileIcon from '~/vue_shared/components/file_icon.vue'; import fileIcon from '~/vue_shared/components/file_icon.vue';
import mountComponent from '../../helpers/vue_mount_component_helper';
describe('File Icon component', () => { describe('File Icon component', () => {
let vm;
let FileIcon; let FileIcon;
beforeEach(() => { beforeEach(() => {
FileIcon = Vue.extend(fileIcon); FileIcon = Vue.extend(fileIcon);
}); });
afterEach(() => {
vm.$destroy();
});
it('should render a span element with an svg', () => { it('should render a span element with an svg', () => {
const component = new FileIcon({ vm = mountComponent(FileIcon, {
propsData: {
fileName: 'test.js', fileName: 'test.js',
}, });
}).$mount();
expect(component.$el.tagName).toEqual('SPAN'); expect(vm.$el.tagName).toEqual('SPAN');
expect(component.$el.querySelector('span > svg')).toBeDefined(); expect(vm.$el.querySelector('span > svg')).toBeDefined();
}); });
it('should render a javascript icon based on file ending', () => { it('should render a javascript icon based on file ending', () => {
const component = new FileIcon({ vm = mountComponent(FileIcon, {
propsData: {
fileName: 'test.js', fileName: 'test.js',
}, });
}).$mount();
expect(component.$el.firstChild.firstChild.getAttribute('xlink:href')).toBe(`${gon.sprite_file_icons}#javascript`); expect(vm.$el.firstChild.firstChild.getAttribute('xlink:href')).toBe(`${gon.sprite_file_icons}#javascript`);
}); });
it('should render a image icon based on file ending', () => { it('should render a image icon based on file ending', () => {
const component = new FileIcon({ vm = mountComponent(FileIcon, {
propsData: {
fileName: 'test.png', fileName: 'test.png',
}, });
}).$mount();
expect(component.$el.firstChild.firstChild.getAttribute('xlink:href')).toBe(`${gon.sprite_file_icons}#image`); expect(vm.$el.firstChild.firstChild.getAttribute('xlink:href')).toBe(`${gon.sprite_file_icons}#image`);
}); });
it('should render a webpack icon based on file namer', () => { it('should render a webpack icon based on file namer', () => {
const component = new FileIcon({ vm = mountComponent(FileIcon, {
propsData: {
fileName: 'webpack.js', fileName: 'webpack.js',
}, });
}).$mount();
expect(component.$el.firstChild.firstChild.getAttribute('xlink:href')).toBe(`${gon.sprite_file_icons}#webpack`); expect(vm.$el.firstChild.firstChild.getAttribute('xlink:href')).toBe(`${gon.sprite_file_icons}#webpack`);
}); });
it('should render a standard folder icon', () => { it('should render a standard folder icon', () => {
const component = new FileIcon({ vm = mountComponent(FileIcon, {
propsData: {
fileName: 'js', fileName: 'js',
folder: true, folder: true,
}, });
}).$mount();
expect(component.$el.querySelector('span > svg > use').getAttribute('xlink:href')).toBe(`${gon.sprite_file_icons}#folder`); expect(vm.$el.querySelector('span > svg > use').getAttribute('xlink:href')).toBe(`${gon.sprite_file_icons}#folder`);
}); });
it('should render a loading icon', () => { it('should render a loading icon', () => {
const component = new FileIcon({ vm = mountComponent(FileIcon, {
propsData: {
fileName: 'test.js', fileName: 'test.js',
loading: true, loading: true,
}, });
}).$mount();
expect( expect(
component.$el.querySelector('i').getAttribute('class'), vm.$el.querySelector('i').getAttribute('class'),
).toEqual('fa fa-spin fa-spinner fa-1x'); ).toEqual('fa fa-spin fa-spinner fa-1x');
}); });
it('should add a special class and a size class', () => { it('should add a special class and a size class', () => {
const component = new FileIcon({ vm = mountComponent(FileIcon, {
propsData: {
fileName: 'test.js', fileName: 'test.js',
cssClasses: 'extraclasses', cssClasses: 'extraclasses',
size: 120, size: 120,
}, });
}).$mount();
const classList = component.$el.firstChild.classList; const classList = vm.$el.firstChild.classList;
const containsSizeClass = classList.contains('s120'); const containsSizeClass = classList.contains('s120');
const containsCustomClass = classList.contains('extraclasses'); const containsCustomClass = classList.contains('extraclasses');
expect(containsSizeClass).toBe(true); expect(containsSizeClass).toBe(true);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment