Welcome to mirror list, hosted at ThFree Co, Russian Federation.

action_component_spec.js « graph « pipelines « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 890255f225e7535d65ec3f3d2ecab366ca6ef022 (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
import { GlButton } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import MockAdapter from 'axios-mock-adapter';
import { nextTick } from 'vue';
import waitForPromises from 'helpers/wait_for_promises';
import axios from '~/lib/utils/axios_utils';
import { HTTP_STATUS_OK } from '~/lib/utils/http_status';
import ActionComponent from '~/pipelines/components/jobs_shared/action_component.vue';

describe('pipeline graph action component', () => {
  let wrapper;
  let mock;
  const findButton = () => wrapper.findComponent(GlButton);
  const findTooltipWrapper = () => wrapper.find('[data-testid="ci-action-icon-tooltip-wrapper"]');

  const defaultProps = {
    tooltipText: 'bar',
    link: 'foo',
    actionIcon: 'cancel',
  };

  const createComponent = ({ props } = {}) => {
    wrapper = mount(ActionComponent, {
      propsData: { ...defaultProps, ...props },
    });
  };

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

    mock.onPost('foo.json').reply(HTTP_STATUS_OK);
  });

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

  describe('render', () => {
    beforeEach(() => {
      createComponent();
    });

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

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

      await nextTick();
      expect(findTooltipWrapper().attributes('title')).toBe('changed');
    });

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

  describe('on click', () => {
    beforeEach(() => {
      createComponent();
    });

    it('emits `pipelineActionRequestComplete` after a successful request', async () => {
      findButton().trigger('click');

      await waitForPromises();

      expect(wrapper.emitted().pipelineActionRequestComplete).toHaveLength(1);
    });

    it('renders a loading icon while waiting for request', async () => {
      findButton().trigger('click');

      await nextTick();
      expect(wrapper.find('.js-action-icon-loading').exists()).toBe(true);
    });
  });

  describe('when has a confirmation modal', () => {
    beforeEach(() => {
      createComponent({ props: { withConfirmationModal: true, shouldTriggerClick: false } });
    });

    describe('and a first click is initiated', () => {
      beforeEach(async () => {
        findButton().trigger('click');

        await waitForPromises();
      });

      it('emits `showActionConfirmationModal` event', () => {
        expect(wrapper.emitted().showActionConfirmationModal).toHaveLength(1);
      });

      it('does not emit `pipelineActionRequestComplete` event', () => {
        expect(wrapper.emitted().pipelineActionRequestComplete).toBeUndefined();
      });
    });

    describe('and the `shouldTriggerClick` value becomes true', () => {
      beforeEach(async () => {
        await wrapper.setProps({ shouldTriggerClick: true });
      });

      it('does not emit `showActionConfirmationModal` event', () => {
        expect(wrapper.emitted().showActionConfirmationModal).toBeUndefined();
      });

      it('emits `actionButtonClicked` event', () => {
        expect(wrapper.emitted().actionButtonClicked).toHaveLength(1);
      });
    });
  });
});