summaryrefslogtreecommitdiff
path: root/spec/javascripts/vue_shared/components/file_icon_spec.js
blob: 1c666fc6c55a61d7860b8522c4a337adb164d0b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import Vue from 'vue';
import fileIcon from '~/vue_shared/components/file_icon.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';

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',
    });

    expect(vm.$el.firstChild.firstChild.getAttribute('xlink:href')).toBe(`${gon.sprite_file_icons}#javascript`);
  });

  it('should render a image icon based on file ending', () => {
    vm = mountComponent(FileIcon, {
      fileName: 'test.png',
    });

    expect(vm.$el.firstChild.firstChild.getAttribute('xlink:href')).toBe(`${gon.sprite_file_icons}#image`);
  });

  it('should render a webpack icon based on file namer', () => {
    vm = mountComponent(FileIcon, {
      fileName: 'webpack.js',
    });

    expect(vm.$el.firstChild.firstChild.getAttribute('xlink:href')).toBe(`${gon.sprite_file_icons}#webpack`);
  });

  it('should render a standard folder icon', () => {
    vm = mountComponent(FileIcon, {
      fileName: 'js',
      folder: true,
    });

    expect(vm.$el.querySelector('span > svg > use').getAttribute('xlink:href')).toBe(`${gon.sprite_file_icons}#folder`);
  });

  it('should render a loading icon', () => {
    vm = mountComponent(FileIcon, {
      fileName: 'test.js',
      loading: true,
    });

    expect(
      vm.$el.querySelector('i').getAttribute('class'),
    ).toEqual('fa fa-spin fa-spinner fa-1x');
  });

  it('should add a special class and a size class', () => {
    vm = mountComponent(FileIcon, {
      fileName: 'test.js',
      cssClasses: 'extraclasses',
      size: 120,
    });

    const { classList } = vm.$el.firstChild;
    const containsSizeClass = classList.contains('s120');
    const containsCustomClass = classList.contains('extraclasses');
    expect(containsSizeClass).toBe(true);
    expect(containsCustomClass).toBe(true);
  });
});