2020-10-02 12:09:03 +00:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import { GlIcon } from '@gitlab/ui';
|
|
|
|
import ItemActions from '~/groups/components/item_actions.vue';
|
2017-10-04 14:10:24 +00:00
|
|
|
import eventHub from '~/groups/event_hub';
|
|
|
|
import { mockParentGroupItem, mockChildren } from '../mock_data';
|
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
describe('ItemActions', () => {
|
|
|
|
let wrapper;
|
|
|
|
const parentGroup = mockChildren[0];
|
2017-10-04 14:10:24 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
const defaultProps = {
|
|
|
|
group: mockParentGroupItem,
|
2017-10-04 14:10:24 +00:00
|
|
|
parentGroup,
|
2020-10-02 12:09:03 +00:00
|
|
|
};
|
2017-10-04 14:10:24 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
const createComponent = (props = {}) => {
|
|
|
|
wrapper = shallowMount(ItemActions, {
|
|
|
|
propsData: { ...defaultProps, ...props },
|
|
|
|
});
|
|
|
|
};
|
2017-10-04 14:10:24 +00:00
|
|
|
|
|
|
|
afterEach(() => {
|
2020-10-02 12:09:03 +00:00
|
|
|
if (wrapper) {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
}
|
2017-10-04 14:10:24 +00:00
|
|
|
});
|
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
const findEditGroupBtn = () => wrapper.find('[data-testid="edit-group-btn"]');
|
|
|
|
const findEditGroupIcon = () => findEditGroupBtn().find(GlIcon);
|
|
|
|
const findLeaveGroupBtn = () => wrapper.find('[data-testid="leave-group-btn"]');
|
|
|
|
const findLeaveGroupIcon = () => findLeaveGroupBtn().find(GlIcon);
|
2017-10-04 14:10:24 +00:00
|
|
|
|
|
|
|
describe('template', () => {
|
2020-10-02 12:09:03 +00:00
|
|
|
it('renders component template correctly', () => {
|
|
|
|
createComponent();
|
2017-10-04 14:10:24 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
expect(wrapper.classes()).toContain('controls');
|
|
|
|
});
|
2017-10-04 14:10:24 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
it('renders "Edit group" button with correct attribute values', () => {
|
|
|
|
const group = {
|
|
|
|
...mockParentGroupItem,
|
|
|
|
canEdit: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
createComponent({ group });
|
|
|
|
|
|
|
|
expect(findEditGroupBtn().exists()).toBe(true);
|
|
|
|
expect(findEditGroupBtn().classes()).toContain('no-expand');
|
|
|
|
expect(findEditGroupBtn().attributes('href')).toBe(group.editPath);
|
|
|
|
expect(findEditGroupBtn().attributes('aria-label')).toBe('Edit group');
|
2020-10-22 06:08:26 +00:00
|
|
|
expect(findEditGroupBtn().attributes('title')).toBe('Edit group');
|
2020-10-02 12:09:03 +00:00
|
|
|
expect(findEditGroupIcon().exists()).toBe(true);
|
|
|
|
expect(findEditGroupIcon().props('name')).toBe('settings');
|
|
|
|
});
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
describe('`canLeave` is true', () => {
|
|
|
|
const group = {
|
|
|
|
...mockParentGroupItem,
|
|
|
|
canLeave: true,
|
|
|
|
};
|
2017-10-04 14:10:24 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({ group });
|
|
|
|
});
|
2017-10-04 14:10:24 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
it('renders "Leave this group" button with correct attribute values', () => {
|
|
|
|
expect(findLeaveGroupBtn().exists()).toBe(true);
|
|
|
|
expect(findLeaveGroupBtn().classes()).toContain('no-expand');
|
|
|
|
expect(findLeaveGroupBtn().attributes('href')).toBe(group.leavePath);
|
|
|
|
expect(findLeaveGroupBtn().attributes('aria-label')).toBe('Leave this group');
|
2020-10-22 06:08:26 +00:00
|
|
|
expect(findLeaveGroupBtn().attributes('title')).toBe('Leave this group');
|
2020-10-02 12:09:03 +00:00
|
|
|
expect(findLeaveGroupIcon().exists()).toBe(true);
|
|
|
|
expect(findLeaveGroupIcon().props('name')).toBe('leave');
|
|
|
|
});
|
2017-10-04 14:10:24 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
it('emits event on "Leave this group" button click', () => {
|
|
|
|
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
findLeaveGroupBtn().trigger('click');
|
2017-10-04 14:10:24 +00:00
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('showLeaveGroupModal', group, parentGroup);
|
|
|
|
});
|
2017-10-04 14:10:24 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|