summaryrefslogtreecommitdiff
path: root/spec/frontend/pipelines/graph/action_component_spec.js
blob: 38ffe98c79bee75e2a45b0196bf12a589ba57204 (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
import { mount } from '@vue/test-utils';
import MockAdapter from 'axios-mock-adapter';
import waitForPromises from 'helpers/wait_for_promises';
import axios from '~/lib/utils/axios_utils';
import ActionComponent from '~/pipelines/components/graph/action_component.vue';

describe('pipeline graph action component', () => {
  let wrapper;
  let mock;

  beforeEach(() => {
    mock = new MockAdapter(axios);

    mock.onPost('foo.json').reply(200);

    wrapper = mount(ActionComponent, {
      propsData: {
        tooltipText: 'bar',
        link: 'foo',
        actionIcon: 'cancel',
      },
      sync: false,
    });
  });

  afterEach(() => {
    mock.restore();
    wrapper.destroy();
  });

  it('should render the provided title as a bootstrap tooltip', () => {
    expect(wrapper.attributes('data-original-title')).toBe('bar');
  });

  it('should update bootstrap tooltip when title changes', done => {
    wrapper.setProps({ tooltipText: 'changed' });

    wrapper.vm
      .$nextTick()
      .then(() => {
        expect(wrapper.attributes('data-original-title')).toBe('changed');
      })
      .then(done)
      .catch(done.fail);
  });

  it('should render an svg', () => {
    expect(wrapper.find('.ci-action-icon-wrapper')).toBeDefined();
    expect(wrapper.find('svg')).toBeDefined();
  });

  describe('on click', () => {
    it('emits `pipelineActionRequestComplete` after a successful request', done => {
      jest.spyOn(wrapper.vm, '$emit');

      wrapper.find('button').trigger('click');

      waitForPromises()
        .then(() => {
          expect(wrapper.vm.$emit).toHaveBeenCalledWith('pipelineActionRequestComplete');
          done();
        })
        .catch(done.fail);
    });

    it('renders a loading icon while waiting for request', done => {
      wrapper.find('button').trigger('click');

      wrapper.vm.$nextTick(() => {
        expect(wrapper.find('.js-action-icon-loading').exists()).toBe(true);
        done();
      });
    });
  });
});