2017-10-04 10:10:24 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
|
2020-04-29 08:10:00 -04:00
|
|
|
import mountComponent from 'helpers/vue_mount_component_helper';
|
2017-10-04 10:10:24 -04:00
|
|
|
import groupFolderComponent from '~/groups/components/group_folder.vue';
|
|
|
|
import groupItemComponent from '~/groups/components/group_item.vue';
|
2021-02-14 13:09:20 -05:00
|
|
|
import groupsComponent from '~/groups/components/groups.vue';
|
2017-10-04 10:10:24 -04:00
|
|
|
import eventHub from '~/groups/event_hub';
|
|
|
|
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;
|
|
|
|
|
2020-04-29 08:10:00 -04:00
|
|
|
beforeEach(() => {
|
2021-01-19 22:11:13 -05:00
|
|
|
Vue.component('GroupFolder', groupFolderComponent);
|
|
|
|
Vue.component('GroupItem', groupItemComponent);
|
2017-10-04 10:10:24 -04:00
|
|
|
|
|
|
|
vm = createComponent();
|
|
|
|
|
2020-04-29 08:10:00 -04:00
|
|
|
return vm.$nextTick();
|
2017-10-04 10:10:24 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('methods', () => {
|
|
|
|
describe('change', () => {
|
|
|
|
it('should emit `fetchPage` event when page is changed via pagination', () => {
|
2020-04-29 08:10:00 -04:00
|
|
|
jest.spyOn(eventHub, '$emit').mockImplementation();
|
2017-10-04 10:10:24 -04:00
|
|
|
|
|
|
|
vm.change(2);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2021-08-30 14:10:36 -04:00
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('fetchPage', {
|
|
|
|
page: 2,
|
|
|
|
archived: null,
|
|
|
|
filterGroupsBy: null,
|
|
|
|
sortBy: null,
|
|
|
|
});
|
2017-10-04 10:10:24 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('template', () => {
|
2020-04-29 08:10:00 -04:00
|
|
|
it('should render component template correctly', () => {
|
|
|
|
return vm.$nextTick().then(() => {
|
2017-10-04 10:10:24 -04:00
|
|
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-29 08:10:00 -04:00
|
|
|
it('should render empty search message when `searchEmpty` is `true`', () => {
|
2017-10-04 10:10:24 -04:00
|
|
|
vm.searchEmpty = true;
|
2020-04-29 08:10:00 -04:00
|
|
|
return vm.$nextTick().then(() => {
|
2017-10-04 10:10:24 -04:00
|
|
|
expect(vm.$el.querySelector('.has-no-search-results')).toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|