2020-05-24 23:13:21 +05:30
|
|
|
import { GlFilteredSearchToken, GlFilteredSearchSuggestion, GlLoadingIcon } from '@gitlab/ui';
|
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-10-24 23:57:45 +05:30
|
|
|
import Api from '~/api';
|
2020-07-28 23:09:34 +05:30
|
|
|
import PipelineBranchNameToken from '~/pipelines/components/pipelines_list/tokens/pipeline_branch_name_token.vue';
|
2020-06-23 00:09:42 +05:30
|
|
|
import { branches, mockBranchesAfterMap } from '../mock_data';
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
describe('Pipeline Branch Name Token', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const findFilteredSearchToken = () => wrapper.find(GlFilteredSearchToken);
|
|
|
|
const findAllFilteredSearchSuggestions = () => wrapper.findAll(GlFilteredSearchSuggestion);
|
|
|
|
const findLoadingIcon = () => wrapper.find(GlLoadingIcon);
|
|
|
|
|
|
|
|
const stubs = {
|
|
|
|
GlFilteredSearchToken: {
|
|
|
|
template: `<div><slot name="suggestions"></slot></div>`,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
config: {
|
|
|
|
type: 'ref',
|
|
|
|
icon: 'branch',
|
|
|
|
title: 'Branch name',
|
|
|
|
unique: true,
|
|
|
|
projectId: '21',
|
2020-06-23 00:09:42 +05:30
|
|
|
disabled: false,
|
2020-05-24 23:13:21 +05:30
|
|
|
},
|
|
|
|
value: {
|
|
|
|
data: '',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const createComponent = (options, data) => {
|
|
|
|
wrapper = shallowMount(PipelineBranchNameToken, {
|
|
|
|
propsData: {
|
|
|
|
...defaultProps,
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
...data,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
...options,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.spyOn(Api, 'branches').mockResolvedValue({ data: branches });
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('passes config correctly', () => {
|
|
|
|
expect(findFilteredSearchToken().props('config')).toEqual(defaultProps.config);
|
|
|
|
});
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
it('fetches and sets project branches', () => {
|
|
|
|
expect(Api.branches).toHaveBeenCalled();
|
|
|
|
|
|
|
|
expect(wrapper.vm.branches).toEqual(mockBranchesAfterMap);
|
|
|
|
expect(findLoadingIcon().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
describe('displays loading icon correctly', () => {
|
|
|
|
it('shows loading icon', () => {
|
|
|
|
createComponent({ stubs }, { loading: true });
|
|
|
|
|
|
|
|
expect(findLoadingIcon().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show loading icon', () => {
|
|
|
|
createComponent({ stubs }, { loading: false });
|
|
|
|
|
|
|
|
expect(findLoadingIcon().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('shows branches correctly', () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
it('renders all branches', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
createComponent({ stubs }, { branches, loading: false });
|
|
|
|
|
|
|
|
expect(findAllFilteredSearchSuggestions()).toHaveLength(branches.length);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders only the branch searched for', () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
const mockBranches = ['main'];
|
2020-05-24 23:13:21 +05:30
|
|
|
createComponent({ stubs }, { branches: mockBranches, loading: false });
|
|
|
|
|
|
|
|
expect(findAllFilteredSearchSuggestions()).toHaveLength(mockBranches.length);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|