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 PipelineTriggerAuthorToken from '~/pipelines/components/pipelines_list/tokens/pipeline_trigger_author_token.vue';
|
2020-05-24 23:13:21 +05:30
|
|
|
import { users } from '../mock_data';
|
|
|
|
|
|
|
|
describe('Pipeline Trigger Author Token', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const stubs = {
|
|
|
|
GlFilteredSearchToken: {
|
2020-11-24 15:15:51 +05:30
|
|
|
props: GlFilteredSearchToken.props,
|
2020-05-24 23:13:21 +05:30
|
|
|
template: `<div><slot name="suggestions"></slot></div>`,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
const findFilteredSearchToken = () => wrapper.find(stubs.GlFilteredSearchToken);
|
|
|
|
const findAllFilteredSearchSuggestions = () => wrapper.findAll(GlFilteredSearchSuggestion);
|
|
|
|
const findLoadingIcon = () => wrapper.find(GlLoadingIcon);
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
const defaultProps = {
|
|
|
|
config: {
|
|
|
|
type: 'username',
|
|
|
|
icon: 'user',
|
|
|
|
title: 'Trigger author',
|
|
|
|
dataType: 'username',
|
|
|
|
unique: true,
|
|
|
|
triggerAuthors: users,
|
|
|
|
},
|
|
|
|
value: {
|
|
|
|
data: '',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
const createComponent = data => {
|
2020-05-24 23:13:21 +05:30
|
|
|
wrapper = shallowMount(PipelineTriggerAuthorToken, {
|
|
|
|
propsData: {
|
|
|
|
...defaultProps,
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
...data,
|
|
|
|
};
|
|
|
|
},
|
2020-11-24 15:15:51 +05:30
|
|
|
stubs,
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.spyOn(Api, 'projectUsers').mockResolvedValue(users);
|
|
|
|
|
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 users', () => {
|
|
|
|
expect(Api.projectUsers).toHaveBeenCalled();
|
|
|
|
|
|
|
|
expect(wrapper.vm.users).toEqual(users);
|
|
|
|
expect(findLoadingIcon().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
describe('displays loading icon correctly', () => {
|
|
|
|
it('shows loading icon', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
createComponent({ loading: true });
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
expect(findLoadingIcon().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show loading icon', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
createComponent({ loading: false });
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
expect(findLoadingIcon().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('shows trigger authors correctly', () => {
|
|
|
|
beforeEach(() => {});
|
|
|
|
|
|
|
|
it('renders all trigger authors', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
createComponent({ users, loading: false });
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
// should have length of all users plus the static 'Any' option
|
|
|
|
expect(findAllFilteredSearchSuggestions()).toHaveLength(users.length + 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders only the trigger author searched for', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
createComponent({
|
|
|
|
users: [{ name: 'Arnold', username: 'admin', state: 'active', avatar_url: 'avatar-link' }],
|
|
|
|
loading: false,
|
|
|
|
});
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
expect(findAllFilteredSearchSuggestions()).toHaveLength(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|