diff options
Diffstat (limited to 'spec/frontend/jobs/components/filtered_search')
-rw-r--r-- | spec/frontend/jobs/components/filtered_search/jobs_filtered_search_spec.js | 34 | ||||
-rw-r--r-- | spec/frontend/jobs/components/filtered_search/utils_spec.js | 19 |
2 files changed, 47 insertions, 6 deletions
diff --git a/spec/frontend/jobs/components/filtered_search/jobs_filtered_search_spec.js b/spec/frontend/jobs/components/filtered_search/jobs_filtered_search_spec.js index 322cfa3ba1f..98bdfc3fcbc 100644 --- a/spec/frontend/jobs/components/filtered_search/jobs_filtered_search_spec.js +++ b/spec/frontend/jobs/components/filtered_search/jobs_filtered_search_spec.js @@ -15,23 +15,27 @@ describe('Jobs filtered search', () => { const findStatusToken = () => getSearchToken('status'); - const createComponent = () => { - wrapper = shallowMount(JobsFilteredSearch); + const createComponent = (props) => { + wrapper = shallowMount(JobsFilteredSearch, { + propsData: { + ...props, + }, + }); }; - beforeEach(() => { - createComponent(); - }); - 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', @@ -42,8 +46,26 @@ describe('Jobs filtered search', () => { }); 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: '=' } }, + ]); + }); }); diff --git a/spec/frontend/jobs/components/filtered_search/utils_spec.js b/spec/frontend/jobs/components/filtered_search/utils_spec.js new file mode 100644 index 00000000000..8440ab42b86 --- /dev/null +++ b/spec/frontend/jobs/components/filtered_search/utils_spec.js @@ -0,0 +1,19 @@ +import { validateQueryString } from '~/jobs/components/filtered_search/utils'; + +describe('Filtered search utils', () => { + describe('validateQueryString', () => { + it.each` + queryStringObject | expected + ${{ statuses: 'SUCCESS' }} | ${{ statuses: 'SUCCESS' }} + ${{ statuses: 'failed' }} | ${{ statuses: 'FAILED' }} + ${{ wrong: 'SUCCESS' }} | ${null} + ${{ statuses: 'wrong' }} | ${null} + ${{ wrong: 'wrong' }} | ${null} + `( + 'when provided $queryStringObject, the expected result is $expected', + ({ queryStringObject, expected }) => { + expect(validateQueryString(queryStringObject)).toEqual(expected); + }, + ); + }); +}); |