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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

80 lines
2.3 KiB
JavaScript
Raw Normal View History

2022-08-13 15:12:31 +05:30
import Vue from 'vue';
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-08-27 11:52:29 +05:30
import { VISIBILITY_LEVEL_PRIVATE } 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,
searchEmptyMessage: 'No matching results',
2022-08-13 15:12:31 +05:30
searchEmpty: false,
};
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-08-27 11:52:29 +05:30
currentGroupVisibility: VISIBILITY_LEVEL_PRIVATE,
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
2022-08-13 15:12:31 +05:30
beforeEach(async () => {
Vue.component('GroupFolder', GroupFolderComponent);
Vue.component('GroupItem', GroupItemComponent);
2018-03-17 18:26:18 +05:30
});
afterEach(() => {
2022-08-13 15:12:31 +05:30
wrapper.destroy();
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);
expect(wrapper.findByText(defaultPropsData.searchEmptyMessage).exists()).toBe(false);
2018-03-17 18:26:18 +05:30
});
2022-08-13 15:12:31 +05:30
it('should render empty search message when `searchEmpty` is `true`', () => {
createComponent({ propsData: { searchEmpty: true } });
expect(wrapper.findByText(defaultPropsData.searchEmptyMessage).exists()).toBe(true);
2018-03-17 18:26:18 +05:30
});
});
});