Commit 23aa7710 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'mw-remove-repository-icon-utils' into 'master'

Remove unused repository icon utils

See merge request gitlab-org/gitlab!44698
parents 8d2b59db dc4e73b0
const entryTypeIcons = {
tree: 'folder',
commit: 'archive',
};
const fileTypeIcons = [
{ extensions: ['pdf'], name: 'file-pdf-o' },
{
extensions: [
'jpg',
'jpeg',
'jif',
'jfif',
'jp2',
'jpx',
'j2k',
'j2c',
'png',
'gif',
'tif',
'tiff',
'svg',
'ico',
'bmp',
],
name: 'file-image-o',
},
{
extensions: ['zip', 'zipx', 'tar', 'gz', 'bz', 'bzip', 'xz', 'rar', '7z'],
name: 'file-archive-o',
},
{ extensions: ['mp3', 'wma', 'ogg', 'oga', 'wav', 'flac', 'aac'], name: 'file-audio-o' },
{
extensions: [
'mp4',
'm4p',
'm4v',
'mpg',
'mp2',
'mpeg',
'mpe',
'mpv',
'm2v',
'avi',
'mkv',
'flv',
'ogv',
'mov',
'3gp',
'3g2',
],
name: 'file-video-o',
},
{ extensions: ['doc', 'dot', 'docx', 'docm', 'dotx', 'dotm', 'docb'], name: 'file-word-o' },
{
extensions: [
'xls',
'xlt',
'xlm',
'xlsx',
'xlsm',
'xltx',
'xltm',
'xlsb',
'xla',
'xlam',
'xll',
'xlw',
],
name: 'file-excel-o',
},
{
extensions: [
'ppt',
'pot',
'pps',
'pptx',
'pptm',
'potx',
'potm',
'ppam',
'ppsx',
'ppsm',
'sldx',
'sldm',
],
name: 'file-powerpoint-o',
},
];
export const getIconName = (type, path) => {
if (entryTypeIcons[type]) return entryTypeIcons[type];
const extension = path.split('.').pop();
const file = fileTypeIcons.find(t => t.extensions.some(ext => ext === extension));
return file ? file.name : 'file-text-o';
};
import { getIconName } from '~/repository/utils/icon';
describe('getIconName', () => {
// Tests the returning font awesome icon name
// We only test one for each file type to save testing a lot of different
// file types
it.each`
type | path | icon
${'tree'} | ${''} | ${'folder'}
${'commit'} | ${''} | ${'archive'}
${'file'} | ${'test.pdf'} | ${'file-pdf-o'}
${'file'} | ${'test.jpg'} | ${'file-image-o'}
${'file'} | ${'test.zip'} | ${'file-archive-o'}
${'file'} | ${'test.mp3'} | ${'file-audio-o'}
${'file'} | ${'test.flv'} | ${'file-video-o'}
${'file'} | ${'test.dotx'} | ${'file-word-o'}
${'file'} | ${'test.xlsb'} | ${'file-excel-o'}
${'file'} | ${'test.ppam'} | ${'file-powerpoint-o'}
${'file'} | ${'test.js'} | ${'file-text-o'}
`('returns $icon for $type with path $path', ({ type, path, icon }) => {
expect(getIconName(type, path)).toEqual(icon);
});
});
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