1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
import { GlFilteredSearch } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { OPERATORS_IS } from '~/vue_shared/components/filtered_search_bar/constants';
import JobsFilteredSearch from '~/jobs/components/filtered_search/jobs_filtered_search.vue';
import { mockFailedSearchToken } from '../../mock_data';
describe('Jobs filtered search', () => {
let wrapper;
const findFilteredSearch = () => wrapper.findComponent(GlFilteredSearch);
const getSearchToken = (type) =>
findFilteredSearch()
.props('availableTokens')
.find((token) => token.type === type);
const findStatusToken = () => getSearchToken('status');
const createComponent = (props) => {
wrapper = shallowMount(JobsFilteredSearch, {
propsData: {
...props,
},
});
};
afterEach(() => {
wrapper.destroy();
});
it('displays filtered search', () => {
createComponent();
expect(findFilteredSearch().exists()).toBe(true);
});
it('displays status token', () => {
createComponent();
expect(findStatusToken()).toMatchObject({
type: 'status',
icon: 'status',
title: 'Status',
unique: true,
operators: OPERATORS_IS,
});
});
it('emits filter token to parent component', () => {
createComponent();
findFilteredSearch().vm.$emit('submit', mockFailedSearchToken);
expect(wrapper.emitted('filterJobsBySearch')).toEqual([[mockFailedSearchToken]]);
});
it('filtered search value is empty array when no query string is passed', () => {
createComponent();
expect(findFilteredSearch().props('value')).toEqual([]);
});
it('filtered search returns correct data shape when passed query string', () => {
const value = 'SUCCESS';
createComponent({ queryString: { statuses: value } });
expect(findFilteredSearch().props('value')).toEqual([
{ type: 'status', value: { data: value, operator: '=' } },
]);
});
});
|