debian-mirror-gitlab/spec/frontend/groups/components/item_actions_spec.js

107 lines
2.9 KiB
JavaScript
Raw Normal View History

2021-01-03 14:25:43 +05:30
import { shallowMount } from '@vue/test-utils';
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 = {}) => {
wrapper = shallowMount(ItemActions, {
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
});
2021-01-03 14:25:43 +05:30
const findEditGroupBtn = () => wrapper.find('[data-testid="edit-group-btn"]');
const findLeaveGroupBtn = () => wrapper.find('[data-testid="leave-group-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,
};
createComponent({ group });
});
2021-01-03 14:25:43 +05:30
it('renders component template correctly', () => {
createComponent();
2018-03-17 18:26:18 +05:30
2021-01-03 14:25:43 +05:30
expect(wrapper.classes()).toContain('controls');
});
2018-03-17 18:26:18 +05:30
2021-01-03 14:25:43 +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);
expect(button.props('icon')).toBe('pencil');
expect(button.attributes('aria-label')).toBe('Edit group');
2021-01-03 14:25:43 +05:30
});
2018-12-13 13:39:08 +05:30
2021-01-29 00:20:46 +05:30
it('renders "Leave this group" button with correct attribute values', () => {
const button = findLeaveGroupBtn();
expect(button.exists()).toBe(true);
expect(button.props('icon')).toBe('leave');
expect(button.attributes('aria-label')).toBe('Leave this group');
});
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
});
});