2017-10-04 10:10:24 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
|
|
|
|
import groupsComponent from '~/groups/components/groups.vue';
|
|
|
|
import groupFolderComponent from '~/groups/components/group_folder.vue';
|
|
|
|
import groupItemComponent from '~/groups/components/group_item.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 { mockGroups, mockPageInfo } from '../mock_data';
|
|
|
|
|
|
|
|
const createComponent = (searchEmpty = false) => {
|
|
|
|
const Component = Vue.extend(groupsComponent);
|
|
|
|
|
|
|
|
return mountComponent(Component, {
|
|
|
|
groups: mockGroups,
|
|
|
|
pageInfo: mockPageInfo,
|
|
|
|
searchEmptyMessage: 'No matching results',
|
|
|
|
searchEmpty,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('GroupsComponent', () => {
|
|
|
|
let vm;
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
beforeEach(done => {
|
2017-10-04 10:10:24 -04:00
|
|
|
Vue.component('group-folder', groupFolderComponent);
|
|
|
|
Vue.component('group-item', groupItemComponent);
|
|
|
|
|
|
|
|
vm = createComponent();
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('methods', () => {
|
|
|
|
describe('change', () => {
|
|
|
|
it('should emit `fetchPage` event when page is changed via pagination', () => {
|
|
|
|
spyOn(eventHub, '$emit').and.stub();
|
|
|
|
|
|
|
|
vm.change(2);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith(
|
|
|
|
'fetchPage',
|
|
|
|
2,
|
|
|
|
jasmine.any(Object),
|
|
|
|
jasmine.any(Object),
|
|
|
|
jasmine.any(Object),
|
|
|
|
);
|
2017-10-04 10:10:24 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('template', () => {
|
2018-10-17 03:13:26 -04:00
|
|
|
it('should render component template correctly', done => {
|
2017-10-04 10:10:24 -04:00
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(vm.$el.querySelector('.groups-list-tree-container')).toBeDefined();
|
|
|
|
expect(vm.$el.querySelector('.group-list-tree')).toBeDefined();
|
|
|
|
expect(vm.$el.querySelector('.gl-pagination')).toBeDefined();
|
2018-10-09 14:30:03 -04:00
|
|
|
expect(vm.$el.querySelectorAll('.has-no-search-results').length).toBe(0);
|
2017-10-04 10:10:24 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('should render empty search message when `searchEmpty` is `true`', done => {
|
2017-10-04 10:10:24 -04:00
|
|
|
vm.searchEmpty = true;
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(vm.$el.querySelector('.has-no-search-results')).toBeDefined();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|