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

73 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-03-17 18:26:18 +05:30
import Vue from 'vue';
2020-05-24 23:13:21 +05:30
import mountComponent from 'helpers/vue_mount_component_helper';
2018-03-17 18:26:18 +05:30
import groupFolderComponent from '~/groups/components/group_folder.vue';
import groupItemComponent from '~/groups/components/group_item.vue';
2021-03-11 19:13:27 +05:30
import groupsComponent from '~/groups/components/groups.vue';
2018-03-17 18:26:18 +05:30
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-05-24 23:13:21 +05:30
beforeEach(() => {
2021-03-11 19:13:27 +05:30
Vue.component('GroupFolder', groupFolderComponent);
Vue.component('GroupItem', groupItemComponent);
2018-03-17 18:26:18 +05:30
vm = createComponent();
2020-05-24 23:13:21 +05:30
return vm.$nextTick();
2018-03-17 18:26:18 +05:30
});
afterEach(() => {
vm.$destroy();
});
describe('methods', () => {
describe('change', () => {
it('should emit `fetchPage` event when page is changed via pagination', () => {
2020-05-24 23:13:21 +05:30
jest.spyOn(eventHub, '$emit').mockImplementation();
2018-03-17 18:26:18 +05:30
vm.change(2);
2018-12-13 13:39:08 +05:30
expect(eventHub.$emit).toHaveBeenCalledWith(
'fetchPage',
2,
2020-05-24 23:13:21 +05:30
expect.any(Object),
expect.any(Object),
expect.any(Object),
2018-12-13 13:39:08 +05:30
);
2018-03-17 18:26:18 +05:30
});
});
});
describe('template', () => {
2020-05-24 23:13:21 +05:30
it('should render component template correctly', () => {
return vm.$nextTick().then(() => {
2018-03-17 18:26:18 +05:30
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-12-13 13:39:08 +05:30
expect(vm.$el.querySelectorAll('.has-no-search-results').length).toBe(0);
2018-03-17 18:26:18 +05:30
});
});
2020-05-24 23:13:21 +05:30
it('should render empty search message when `searchEmpty` is `true`', () => {
2018-03-17 18:26:18 +05:30
vm.searchEmpty = true;
2020-05-24 23:13:21 +05:30
return vm.$nextTick().then(() => {
2018-03-17 18:26:18 +05:30
expect(vm.$el.querySelector('.has-no-search-results')).toBeDefined();
});
});
});
});