2022-04-04 11:22:00 +05:30
|
|
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
|
2021-01-03 14:25:43 +05:30
|
|
|
import ItemActions from '~/groups/components/item_actions.vue';
|
2018-03-17 18:26:18 +05:30
|
|
|
import eventHub from '~/groups/event_hub';
|
|
|
|
import { mockParentGroupItem, mockChildren } from '../mock_data';
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
describe('ItemActions', () => {
|
|
|
|
let wrapper;
|
|
|
|
const parentGroup = mockChildren[0];
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
const defaultProps = {
|
|
|
|
group: mockParentGroupItem,
|
2018-03-17 18:26:18 +05:30
|
|
|
parentGroup,
|
2021-01-03 14:25:43 +05:30
|
|
|
};
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
const createComponent = (props = {}) => {
|
2022-04-04 11:22:00 +05:30
|
|
|
wrapper = shallowMountExtended(ItemActions, {
|
2021-01-03 14:25:43 +05:30
|
|
|
propsData: { ...defaultProps, ...props },
|
|
|
|
});
|
|
|
|
};
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
afterEach(() => {
|
2021-01-29 00:20:46 +05:30
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
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`);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
describe('template', () => {
|
2021-01-29 00:20:46 +05:30
|
|
|
let group;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
group = {
|
|
|
|
...mockParentGroupItem,
|
|
|
|
canEdit: true,
|
|
|
|
canLeave: true,
|
2022-04-04 11:22:00 +05:30
|
|
|
canRemove: true,
|
2021-01-29 00:20:46 +05:30
|
|
|
};
|
|
|
|
createComponent({ group });
|
|
|
|
});
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it('renders component template correctly', () => {
|
|
|
|
createComponent();
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(wrapper.classes()).toContain('gl-display-flex', 'gl-justify-content-end', 'gl-ml-5');
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('renders "Edit" group button with correct attribute values', () => {
|
2021-01-29 00:20:46 +05:30
|
|
|
const button = findEditGroupBtn();
|
|
|
|
expect(button.exists()).toBe(true);
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(button.attributes('href')).toBe(mockParentGroupItem.editPath);
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('renders "Delete" group button with correct attribute values', () => {
|
|
|
|
const button = findRemoveGroupBtn();
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(button.exists()).toBe(true);
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(button.attributes('href')).toBe(
|
|
|
|
`${mockParentGroupItem.editPath}#js-remove-group-form`,
|
|
|
|
);
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it('emits `showLeaveGroupModal` event in the event hub', () => {
|
|
|
|
jest.spyOn(eventHub, '$emit');
|
|
|
|
findLeaveGroupBtn().vm.$emit('click', { stopPropagation: () => {} });
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('showLeaveGroupModal', group, parentGroup);
|
|
|
|
});
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it('does not render leave button if group can not be left', () => {
|
|
|
|
createComponent({
|
|
|
|
group: {
|
|
|
|
...mockParentGroupItem,
|
|
|
|
canLeave: false,
|
|
|
|
},
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(findLeaveGroupBtn().exists()).toBe(false);
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it('does not render edit button if group can not be edited', () => {
|
|
|
|
createComponent({
|
|
|
|
group: {
|
|
|
|
...mockParentGroupItem,
|
|
|
|
canEdit: false,
|
|
|
|
},
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
expect(findEditGroupBtn().exists()).toBe(false);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2022-04-04 11:22:00 +05:30
|
|
|
|
|
|
|
it('does not render delete button if group can not be edited', () => {
|
|
|
|
createComponent({
|
|
|
|
group: {
|
|
|
|
...mockParentGroupItem,
|
|
|
|
canRemove: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(findRemoveGroupBtn().exists()).toBe(false);
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|