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

item_actions_spec.js « components « groups « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3ceb038dd3cb8ea979dc12e5921fbf2908bcc165 (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
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import ItemActions from '~/groups/components/item_actions.vue';
import eventHub from '~/groups/event_hub';
import { mockParentGroupItem, mockChildren } from '../mock_data';

describe('ItemActions', () => {
  let wrapper;
  const parentGroup = mockChildren[0];

  const defaultProps = {
    group: mockParentGroupItem,
    parentGroup,
  };

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

  afterEach(() => {
    wrapper.destroy();
    wrapper = null;
  });

  const findEditGroupBtn = () => wrapper.findByTestId(`edit-group-${mockParentGroupItem.id}-btn`);
  const findLeaveGroupBtn = () => wrapper.findByTestId(`leave-group-${mockParentGroupItem.id}-btn`);
  const findRemoveGroupBtn = () =>
    wrapper.findByTestId(`remove-group-${mockParentGroupItem.id}-btn`);

  describe('template', () => {
    let group;

    beforeEach(() => {
      group = {
        ...mockParentGroupItem,
        canEdit: true,
        canLeave: true,
        canRemove: true,
      };
      createComponent({ group });
    });

    it('renders component template correctly', () => {
      createComponent();

      expect(wrapper.classes()).toContain('gl-display-flex', 'gl-justify-content-end', 'gl-ml-5');
    });

    it('renders "Edit" group button with correct attribute values', () => {
      const button = findEditGroupBtn();
      expect(button.exists()).toBe(true);
      expect(button.attributes('href')).toBe(mockParentGroupItem.editPath);
    });

    it('renders "Delete" group button with correct attribute values', () => {
      const button = findRemoveGroupBtn();
      expect(button.exists()).toBe(true);
      expect(button.attributes('href')).toBe(
        `${mockParentGroupItem.editPath}#js-remove-group-form`,
      );
    });

    it('emits `showLeaveGroupModal` event in the event hub', () => {
      jest.spyOn(eventHub, '$emit');
      findLeaveGroupBtn().vm.$emit('click', { stopPropagation: () => {} });

      expect(eventHub.$emit).toHaveBeenCalledWith('showLeaveGroupModal', group, parentGroup);
    });
  });

  it('emits `showLeaveGroupModal` event with the correct prefix if `action` prop is passed', () => {
    const group = {
      ...mockParentGroupItem,
      canEdit: true,
      canLeave: true,
    };
    createComponent({
      group,
      action: 'test',
    });
    jest.spyOn(eventHub, '$emit');
    findLeaveGroupBtn().vm.$emit('click', { stopPropagation: () => {} });

    expect(eventHub.$emit).toHaveBeenCalledWith('testshowLeaveGroupModal', group, parentGroup);
  });

  it('does not render leave button if group can not be left', () => {
    createComponent({
      group: {
        ...mockParentGroupItem,
        canLeave: false,
      },
    });

    expect(findLeaveGroupBtn().exists()).toBe(false);
  });

  it('does not render edit button if group can not be edited', () => {
    createComponent({
      group: {
        ...mockParentGroupItem,
        canEdit: false,
      },
    });

    expect(findEditGroupBtn().exists()).toBe(false);
  });

  it('does not render delete button if group can not be edited', () => {
    createComponent({
      group: {
        ...mockParentGroupItem,
        canRemove: false,
      },
    });

    expect(findRemoveGroupBtn().exists()).toBe(false);
  });
});