summaryrefslogtreecommitdiff
path: root/spec/frontend/jobs/components/empty_state_spec.js
blob: dfba5a936eeb7cd5e2f76c172ceb93b2f920eb55 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import Vue from 'vue';
import component from '~/jobs/components/empty_state.vue';
import mountComponent from '../../helpers/vue_mount_component_helper';

describe('Empty State', () => {
  const Component = Vue.extend(component);
  let vm;

  const props = {
    illustrationPath: 'illustrations/pending_job_empty.svg',
    illustrationSizeClass: 'svg-430',
    title: 'This job has not started yet',
    playable: false,
    variablesSettingsUrl: '',
  };

  const content = 'This job is in pending state and is waiting to be picked by a runner';

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

  describe('renders image and title', () => {
    beforeEach(() => {
      vm = mountComponent(Component, {
        ...props,
        content,
      });
    });

    it('renders img with provided path and size', () => {
      expect(vm.$el.querySelector('img').getAttribute('src')).toEqual(props.illustrationPath);
      expect(vm.$el.querySelector('.svg-content').classList).toContain(props.illustrationSizeClass);
    });

    it('renders provided title', () => {
      expect(vm.$el.querySelector('.js-job-empty-state-title').textContent.trim()).toEqual(
        props.title,
      );
    });
  });

  describe('with content', () => {
    it('renders content', () => {
      vm = mountComponent(Component, {
        ...props,
        content,
      });

      expect(vm.$el.querySelector('.js-job-empty-state-content').textContent.trim()).toEqual(
        content,
      );
    });
  });

  describe('without content', () => {
    it('does not render content', () => {
      vm = mountComponent(Component, {
        ...props,
      });

      expect(vm.$el.querySelector('.js-job-empty-state-content')).toBeNull();
    });
  });

  describe('with action', () => {
    it('renders action', () => {
      vm = mountComponent(Component, {
        ...props,
        content,
        action: {
          path: 'runner',
          button_title: 'Check runner',
          method: 'post',
        },
      });

      expect(vm.$el.querySelector('.js-job-empty-state-action').getAttribute('href')).toEqual(
        'runner',
      );
    });
  });

  describe('without action', () => {
    it('does not render action', () => {
      vm = mountComponent(Component, {
        ...props,
        content,
        action: null,
      });

      expect(vm.$el.querySelector('.js-job-empty-state-action')).toBeNull();
    });
  });

  describe('without playbale action', () => {
    it('does not render manual variables form', () => {
      vm = mountComponent(Component, {
        ...props,
        content,
      });

      expect(vm.$el.querySelector('.js-manual-vars-form')).toBeNull();
    });
  });

  describe('with playbale action and not scheduled job', () => {
    it('renders manual variables form', () => {
      vm = mountComponent(Component, {
        ...props,
        content,
        playable: true,
        scheduled: false,
        action: {
          path: 'runner',
          button_title: 'Check runner',
          method: 'post',
        },
      });

      expect(vm.$el.querySelector('.js-manual-vars-form')).not.toBeNull();
    });
  });

  describe('with playbale action and  scheduled job', () => {
    it('does not render manual variables form', () => {
      vm = mountComponent(Component, {
        ...props,
        content,
      });

      expect(vm.$el.querySelector('.js-manual-vars-form')).toBeNull();
    });
  });
});