summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_shared/components/members/action_buttons/remove_member_button_spec.js
blob: 7aa304942341711d66e7b92922cb1a850a3919bf (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
import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import RemoveMemberButton from '~/vue_shared/components/members/action_buttons/remove_member_button.vue';

const localVue = createLocalVue();
localVue.use(Vuex);

describe('RemoveMemberButton', () => {
  let wrapper;

  const createStore = (state = {}) => {
    return new Vuex.Store({
      state: {
        memberPath: '/groups/foo-bar/-/group_members/:id',
        ...state,
      },
    });
  };

  const createComponent = (propsData = {}, state) => {
    wrapper = shallowMount(RemoveMemberButton, {
      localVue,
      store: createStore(state),
      propsData: {
        memberId: 1,
        message: 'Are you sure you want to remove John Smith?',
        title: 'Remove member',
        isAccessRequest: true,
        ...propsData,
      },
      directives: {
        GlTooltip: createMockDirective(),
      },
    });
  };

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

  it('sets attributes on button', () => {
    createComponent();

    expect(wrapper.attributes()).toMatchObject({
      'data-member-path': '/groups/foo-bar/-/group_members/1',
      'data-message': 'Are you sure you want to remove John Smith?',
      'data-is-access-request': 'true',
      'aria-label': 'Remove member',
      title: 'Remove member',
      icon: 'remove',
    });
  });

  it('displays `title` prop as a tooltip', () => {
    createComponent();

    expect(getBinding(wrapper.element, 'gl-tooltip')).not.toBeUndefined();
  });

  it('has CSS class used by `remove_member_modal.vue`', () => {
    createComponent();

    expect(wrapper.classes()).toContain('js-remove-member-button');
  });
});