summaryrefslogtreecommitdiff
path: root/spec/javascripts/ide/components/jobs/list_spec.js
blob: b24853c56fa339f7298585cd974743521bef8547 (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
import Vue from 'vue';
import StageList from '~/ide/components/jobs/list.vue';
import { createStore } from '~/ide/stores';
import { createComponentWithStore } from '../../../helpers/vue_mount_component_helper';
import { stages, jobs } from '../../mock_data';

describe('IDE stages list', () => {
  const Component = Vue.extend(StageList);
  let vm;

  beforeEach(() => {
    const store = createStore();

    vm = createComponentWithStore(Component, store, {
      stages: stages.map((mappedState, i) => ({
        ...mappedState,
        id: i,
        dropdownPath: mappedState.dropdown_path,
        jobs: [...jobs],
        isLoading: false,
        isCollapsed: false,
      })),
      loading: false,
    });

    spyOn(vm, 'fetchJobs');
    spyOn(vm, 'toggleStageCollapsed');

    vm.$mount();
  });

  afterEach(() => {
    vm.$destroy();
  });

  it('renders list of stages', () => {
    expect(vm.$el.querySelectorAll('.card').length).toBe(2);
  });

  it('renders loading icon when no stages & is loading', done => {
    vm.stages = [];
    vm.loading = true;

    vm.$nextTick(() => {
      expect(vm.$el.querySelector('.loading-container')).not.toBe(null);

      done();
    });
  });

  it('calls toggleStageCollapsed when clicking stage header', done => {
    vm.$el.querySelector('.card-header').click();

    vm.$nextTick(() => {
      expect(vm.toggleStageCollapsed).toHaveBeenCalledWith(0);

      done();
    });
  });

  it('calls fetchJobs when stage is mounted', () => {
    expect(vm.fetchJobs.calls.count()).toBe(stages.length);

    expect(vm.fetchJobs.calls.argsFor(0)).toEqual([vm.stages[0]]);
    expect(vm.fetchJobs.calls.argsFor(1)).toEqual([vm.stages[1]]);
  });
});