2017-10-04 10:10:24 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
|
|
|
|
import itemActionsComponent from '~/groups/components/item_actions.vue';
|
|
|
|
import eventHub from '~/groups/event_hub';
|
2018-02-26 14:43:34 -05:00
|
|
|
import mountComponent from 'spec/helpers/vue_mount_component_helper';
|
2017-10-04 10:10:24 -04:00
|
|
|
import { mockParentGroupItem, mockChildren } from '../mock_data';
|
|
|
|
|
|
|
|
const createComponent = (group = mockParentGroupItem, parentGroup = mockChildren[0]) => {
|
|
|
|
const Component = Vue.extend(itemActionsComponent);
|
|
|
|
|
|
|
|
return mountComponent(Component, {
|
|
|
|
group,
|
|
|
|
parentGroup,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('ItemActionsComponent', () => {
|
|
|
|
let vm;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
vm = createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('methods', () => {
|
|
|
|
describe('onLeaveGroup', () => {
|
2018-01-10 02:25:52 -05:00
|
|
|
it('emits `showLeaveGroupModal` event with `group` and `parentGroup` props', () => {
|
2017-10-04 10:10:24 -04:00
|
|
|
spyOn(eventHub, '$emit');
|
2018-01-10 02:25:52 -05:00
|
|
|
vm.onLeaveGroup();
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith(
|
|
|
|
'showLeaveGroupModal',
|
|
|
|
vm.group,
|
|
|
|
vm.parentGroup,
|
|
|
|
);
|
2017-10-04 10:10:24 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('template', () => {
|
|
|
|
it('should render component template correctly', () => {
|
|
|
|
expect(vm.$el.classList.contains('controls')).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render Edit Group button with correct attribute values', () => {
|
|
|
|
const group = Object.assign({}, mockParentGroupItem);
|
|
|
|
group.canEdit = true;
|
|
|
|
const newVm = createComponent(group);
|
|
|
|
|
|
|
|
const editBtn = newVm.$el.querySelector('a.edit-group');
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-10-04 10:10:24 -04:00
|
|
|
expect(editBtn).toBeDefined();
|
|
|
|
expect(editBtn.classList.contains('no-expand')).toBeTruthy();
|
|
|
|
expect(editBtn.getAttribute('href')).toBe(group.editPath);
|
|
|
|
expect(editBtn.getAttribute('aria-label')).toBe('Edit group');
|
|
|
|
expect(editBtn.dataset.originalTitle).toBe('Edit group');
|
2018-01-10 02:25:52 -05:00
|
|
|
expect(editBtn.querySelectorAll('svg use').length).not.toBe(0);
|
|
|
|
expect(editBtn.querySelector('svg use').getAttribute('xlink:href')).toContain('#settings');
|
2017-10-04 10:10:24 -04:00
|
|
|
|
|
|
|
newVm.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render Leave Group button with correct attribute values', () => {
|
|
|
|
const group = Object.assign({}, mockParentGroupItem);
|
|
|
|
group.canLeave = true;
|
|
|
|
const newVm = createComponent(group);
|
|
|
|
|
|
|
|
const leaveBtn = newVm.$el.querySelector('a.leave-group');
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-10-04 10:10:24 -04:00
|
|
|
expect(leaveBtn).toBeDefined();
|
|
|
|
expect(leaveBtn.classList.contains('no-expand')).toBeTruthy();
|
|
|
|
expect(leaveBtn.getAttribute('href')).toBe(group.leavePath);
|
|
|
|
expect(leaveBtn.getAttribute('aria-label')).toBe('Leave this group');
|
|
|
|
expect(leaveBtn.dataset.originalTitle).toBe('Leave this group');
|
2018-01-10 02:25:52 -05:00
|
|
|
expect(leaveBtn.querySelectorAll('svg use').length).not.toBe(0);
|
|
|
|
expect(leaveBtn.querySelector('svg use').getAttribute('xlink:href')).toContain('#leave');
|
2017-10-04 10:10:24 -04:00
|
|
|
|
|
|
|
newVm.$destroy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|