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

69 lines
2 KiB
JavaScript
Raw Normal View History

2022-08-13 15:12:31 +05:30
import Vue from 'vue';
2022-11-25 23:54:43 +05:30
import { GlEmptyState } from '@gitlab/ui';
2018-03-17 18:26:18 +05:30
2022-08-13 15:12:31 +05:30
import { mountExtended } from 'helpers/vue_test_utils_helper';
import GroupFolderComponent from '~/groups/components/group_folder.vue';
import GroupItemComponent from '~/groups/components/group_item.vue';
import PaginationLinks from '~/vue_shared/components/pagination_links.vue';
import GroupsComponent from '~/groups/components/groups.vue';
2018-03-17 18:26:18 +05:30
import eventHub from '~/groups/event_hub';
2022-10-11 01:57:18 +05:30
import { VISIBILITY_LEVEL_PRIVATE_STRING } from '~/visibility_level/constants';
2018-03-17 18:26:18 +05:30
import { mockGroups, mockPageInfo } from '../mock_data';
2022-08-13 15:12:31 +05:30
describe('GroupsComponent', () => {
let wrapper;
2018-03-17 18:26:18 +05:30
2022-08-13 15:12:31 +05:30
const defaultPropsData = {
2018-03-17 18:26:18 +05:30
groups: mockGroups,
pageInfo: mockPageInfo,
2022-08-13 15:12:31 +05:30
};
2018-03-17 18:26:18 +05:30
2022-08-13 15:12:31 +05:30
const createComponent = ({ propsData } = {}) => {
wrapper = mountExtended(GroupsComponent, {
propsData: {
...defaultPropsData,
...propsData,
},
provide: {
2022-10-11 01:57:18 +05:30
currentGroupVisibility: VISIBILITY_LEVEL_PRIVATE_STRING,
2022-08-13 15:12:31 +05:30
},
});
};
2018-03-17 18:26:18 +05:30
2022-08-13 15:12:31 +05:30
const findPaginationLinks = () => wrapper.findComponent(PaginationLinks);
2018-03-17 18:26:18 +05:30
2023-06-20 00:43:36 +05:30
beforeEach(() => {
2022-08-13 15:12:31 +05:30
Vue.component('GroupFolder', GroupFolderComponent);
Vue.component('GroupItem', GroupItemComponent);
2018-03-17 18:26:18 +05:30
});
describe('methods', () => {
describe('change', () => {
it('should emit `fetchPage` event when page is changed via pagination', () => {
2022-08-13 15:12:31 +05:30
createComponent();
2020-05-24 23:13:21 +05:30
jest.spyOn(eventHub, '$emit').mockImplementation();
2018-03-17 18:26:18 +05:30
2022-08-13 15:12:31 +05:30
findPaginationLinks().props('change')(2);
2018-12-13 13:39:08 +05:30
2021-11-11 11:23:49 +05:30
expect(eventHub.$emit).toHaveBeenCalledWith('fetchPage', {
page: 2,
archived: null,
filterGroupsBy: null,
sortBy: null,
});
2018-03-17 18:26:18 +05:30
});
});
});
describe('template', () => {
2022-08-13 15:12:31 +05:30
it('should render component template correctly', () => {
createComponent();
expect(wrapper.findComponent(GroupFolderComponent).exists()).toBe(true);
expect(findPaginationLinks().exists()).toBe(true);
2022-11-25 23:54:43 +05:30
expect(wrapper.findComponent(GlEmptyState).exists()).toBe(false);
2018-03-17 18:26:18 +05:30
});
});
});