summaryrefslogtreecommitdiff
path: root/spec/javascripts/vue_shared/components/loading_icon_spec.js
blob: 5cd3466f501d10e4a2191d823942f884f0f41199 (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
import Vue from 'vue';
import loadingIcon from '~/vue_shared/components/loading_icon.vue';

describe('Loading Icon Component', () => {
  let LoadingIconComponent;

  beforeEach(() => {
    LoadingIconComponent = Vue.extend(loadingIcon);
  });

  it('should render a spinner font awesome icon', () => {
    const component = new LoadingIconComponent().$mount();

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

    expect(component.$el.tagName).toEqual('DIV');
    expect(component.$el.classList).toContain('text-center');
    expect(component.$el.classList).toContain('loading-container');
  });

  it('should render accessibility attributes', () => {
    const component = new LoadingIconComponent().$mount();

    const icon = component.$el.querySelector('i');
    expect(icon.getAttribute('aria-hidden')).toEqual('true');
    expect(icon.getAttribute('aria-label')).toEqual('Loading');
  });

  it('should render the provided label', () => {
    const component = new LoadingIconComponent({
      propsData: {
        label: 'This is a loading icon',
      },
    }).$mount();

    expect(
      component.$el.querySelector('i').getAttribute('aria-label'),
    ).toEqual('This is a loading icon');
  });

  it('should render the provided size', () => {
    const component = new LoadingIconComponent({
      propsData: {
        size: '2',
      },
    }).$mount();

    expect(
      component.$el.querySelector('i').classList.contains('fa-2x'),
    ).toEqual(true);
  });
});