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

action_buttons_spec.js « components « vue_merge_request_widget « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 02e23b814132c09a8fd313b2fe450acdf877e398 (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
import { GlButton, GlDisclosureDropdown } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Actions from '~/vue_merge_request_widget/components/action_buttons.vue';

let wrapper;

function factory(propsData = {}) {
  wrapper = shallowMount(Actions, {
    propsData,
  });
}

describe('MR widget extension actions', () => {
  describe('tertiaryButtons', () => {
    it('renders buttons', () => {
      factory({
        tertiaryButtons: [{ text: 'hello world', href: 'https://gitlab.com', target: '_blank' }],
      });

      expect(wrapper.findAllComponents(GlButton)).toHaveLength(1);
    });

    it('calls action click handler', async () => {
      const onClick = jest.fn();

      factory({
        tertiaryButtons: [{ text: 'hello world', onClick }],
      });

      await wrapper.findComponent(GlButton).vm.$emit('click');

      expect(onClick).toHaveBeenCalled();
    });

    it('renders tertiary actions in dropdown', () => {
      const action = { text: 'hello world', href: 'https://gitlab.com', target: '_blank' };
      factory({
        tertiaryButtons: [action, action],
      });

      const component = wrapper.findComponent(GlDisclosureDropdown);
      expect(component.exists()).toBe(true);
      expect(component.props('items')).toMatchObject([
        {
          text: action.text,
          href: action.href,
          extraAttrs: {
            target: action.target,
          },
        },
        {
          text: action.text,
          href: action.href,
          extraAttrs: {
            target: action.target,
          },
        },
      ]);
    });
  });
});