summaryrefslogtreecommitdiff
path: root/spec/javascripts/jobs/components/empty_state_spec.js
blob: 03e196369e0a1526cd450fdb07de03376843e7b6 (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
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 = component;
  let vm;

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

  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();
    });
  });
});