2021-03-11 19:13:27 +05:30
|
|
|
import { GlButton } from '@gitlab/ui';
|
2021-01-03 14:25:43 +05:30
|
|
|
import { shallowMount, createLocalVue } from '@vue/test-utils';
|
|
|
|
import Vuex from 'vuex';
|
|
|
|
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
|
2021-02-22 17:27:13 +05:30
|
|
|
import ResendInviteButton from '~/members/components/action_buttons/resend_invite_button.vue';
|
2021-04-29 21:17:54 +05:30
|
|
|
import { MEMBER_TYPES } from '~/members/constants';
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
jest.mock('~/lib/utils/csrf', () => ({ token: 'mock-csrf-token' }));
|
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(Vuex);
|
|
|
|
|
|
|
|
describe('ResendInviteButton', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const createStore = (state = {}) => {
|
|
|
|
return new Vuex.Store({
|
2021-04-29 21:17:54 +05:30
|
|
|
modules: {
|
|
|
|
[MEMBER_TYPES.invite]: {
|
|
|
|
namespaced: true,
|
|
|
|
state: {
|
|
|
|
memberPath: '/groups/foo-bar/-/group_members/:id',
|
|
|
|
...state,
|
|
|
|
},
|
|
|
|
},
|
2021-01-03 14:25:43 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const createComponent = (propsData = {}, state) => {
|
|
|
|
wrapper = shallowMount(ResendInviteButton, {
|
|
|
|
localVue,
|
|
|
|
store: createStore(state),
|
2021-04-29 21:17:54 +05:30
|
|
|
provide: {
|
|
|
|
namespace: MEMBER_TYPES.invite,
|
|
|
|
},
|
2021-01-03 14:25:43 +05:30
|
|
|
propsData: {
|
|
|
|
memberId: 1,
|
|
|
|
...propsData,
|
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
GlTooltip: createMockDirective(),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const findForm = () => wrapper.find('form');
|
|
|
|
const findButton = () => findForm().find(GlButton);
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays a tooltip', () => {
|
|
|
|
expect(getBinding(findButton().element, 'gl-tooltip')).not.toBeUndefined();
|
|
|
|
expect(findButton().attributes('title')).toBe('Resend invite');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('submits the form when button is clicked', () => {
|
|
|
|
expect(findButton().attributes('type')).toBe('submit');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays form with correct action and inputs', () => {
|
|
|
|
expect(findForm().attributes('action')).toBe('/groups/foo-bar/-/group_members/1/resend_invite');
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(findForm().find('input[name="authenticity_token"]').attributes('value')).toBe(
|
|
|
|
'mock-csrf-token',
|
|
|
|
);
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
});
|