2020-07-28 23:09:34 +05:30
|
|
|
import { GlLoadingIcon, GlSearchBoxByType } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import AxiosMockAdapter from 'axios-mock-adapter';
|
2020-07-28 23:09:34 +05:30
|
|
|
import { nextTick } from 'vue';
|
2020-10-24 23:57:45 +05:30
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2021-09-04 01:27:46 +05:30
|
|
|
import createFlash from '~/flash';
|
2021-03-11 19:13:27 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2020-07-28 23:09:34 +05:30
|
|
|
import ForkGroupsList from '~/pages/projects/forks/new/components/fork_groups_list.vue';
|
|
|
|
import ForkGroupsListItem from '~/pages/projects/forks/new/components/fork_groups_list_item.vue';
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
jest.mock('~/flash');
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
describe('Fork groups list component', () => {
|
|
|
|
let wrapper;
|
|
|
|
let axiosMock;
|
|
|
|
|
|
|
|
const DEFAULT_PROPS = {
|
|
|
|
endpoint: '/dummy',
|
|
|
|
};
|
|
|
|
|
|
|
|
const replyWith = (...args) => axiosMock.onGet(DEFAULT_PROPS.endpoint).reply(...args);
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const createWrapper = (propsData) => {
|
2020-07-28 23:09:34 +05:30
|
|
|
wrapper = shallowMount(ForkGroupsList, {
|
|
|
|
propsData: {
|
|
|
|
...DEFAULT_PROPS,
|
|
|
|
...propsData,
|
|
|
|
},
|
|
|
|
stubs: {
|
|
|
|
GlTabs: {
|
|
|
|
template: '<div><slot></slot><slot name="tabs-end"></slot></div>',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
axiosMock = new AxiosMockAdapter(axios);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
axiosMock.reset();
|
|
|
|
|
|
|
|
if (wrapper) {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it('fires load groups request on mount', async () => {
|
|
|
|
replyWith(200, { namespaces: [] });
|
|
|
|
createWrapper();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(axiosMock.history.get[0].url).toBe(DEFAULT_PROPS.endpoint);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays flash if loading groups fails', async () => {
|
|
|
|
replyWith(500);
|
|
|
|
createWrapper();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(createFlash).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays loading indicator while loading groups', () => {
|
|
|
|
replyWith(() => new Promise(() => {}));
|
|
|
|
createWrapper();
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(wrapper.find(GlLoadingIcon).exists()).toBe(true);
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('displays empty text if no groups are available', async () => {
|
|
|
|
const EMPTY_TEXT = 'No available groups to fork the project.';
|
|
|
|
replyWith(200, { namespaces: [] });
|
|
|
|
createWrapper();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(wrapper.text()).toContain(EMPTY_TEXT);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays filter field when groups are available', async () => {
|
|
|
|
replyWith(200, { namespaces: [{ name: 'dummy1' }, { name: 'dummy2' }] });
|
|
|
|
createWrapper();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(wrapper.find(GlSearchBoxByType).exists()).toBe(true);
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders list items for each available group', async () => {
|
|
|
|
const namespaces = [{ name: 'dummy1' }, { name: 'dummy2' }, { name: 'otherdummy' }];
|
|
|
|
|
|
|
|
replyWith(200, { namespaces });
|
2021-03-11 19:13:27 +05:30
|
|
|
createWrapper();
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(wrapper.findAll(ForkGroupsListItem)).toHaveLength(namespaces.length);
|
|
|
|
|
|
|
|
namespaces.forEach((namespace, idx) => {
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(wrapper.findAll(ForkGroupsListItem).at(idx).props()).toStrictEqual({
|
|
|
|
group: namespace,
|
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('filters repositories on the fly', async () => {
|
|
|
|
replyWith(200, {
|
|
|
|
namespaces: [{ name: 'dummy1' }, { name: 'dummy2' }, { name: 'otherdummy' }],
|
|
|
|
});
|
|
|
|
createWrapper();
|
|
|
|
await waitForPromises();
|
|
|
|
wrapper.find(GlSearchBoxByType).vm.$emit('input', 'other');
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
expect(wrapper.findAll(ForkGroupsListItem)).toHaveLength(1);
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(wrapper.findAll(ForkGroupsListItem).at(0).props().group.name).toBe('otherdummy');
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
|
|
|
});
|