2020-11-06 06:08:51 +00:00
|
|
|
import { createLocalVue, shallowMount } from '@vue/test-utils';
|
2021-02-14 18:09:20 +00:00
|
|
|
import Vuex from 'vuex';
|
2020-11-06 06:08:51 +00:00
|
|
|
import { MOCK_QUERY } from 'jest/search/mock_data';
|
|
|
|
import ConfidentialityFilter from '~/search/sidebar/components/confidentiality_filter.vue';
|
|
|
|
import RadioFilter from '~/search/sidebar/components/radio_filter.vue';
|
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(Vuex);
|
|
|
|
|
|
|
|
describe('ConfidentialityFilter', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const actionSpies = {
|
|
|
|
applyQuery: jest.fn(),
|
|
|
|
resetQuery: jest.fn(),
|
|
|
|
};
|
|
|
|
|
2020-12-24 00:10:25 +00:00
|
|
|
const createComponent = (initialState) => {
|
2020-11-06 06:08:51 +00:00
|
|
|
const store = new Vuex.Store({
|
|
|
|
state: {
|
|
|
|
query: MOCK_QUERY,
|
|
|
|
...initialState,
|
|
|
|
},
|
|
|
|
actions: actionSpies,
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper = shallowMount(ConfidentialityFilter, {
|
|
|
|
localVue,
|
|
|
|
store,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
const findRadioFilter = () => wrapper.find(RadioFilter);
|
|
|
|
|
|
|
|
describe('template', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe.each`
|
|
|
|
scope | showFilter
|
|
|
|
${'issues'} | ${true}
|
|
|
|
${'merge_requests'} | ${false}
|
|
|
|
${'projects'} | ${false}
|
|
|
|
${'milestones'} | ${false}
|
|
|
|
${'users'} | ${false}
|
|
|
|
${'notes'} | ${false}
|
|
|
|
${'wiki_blobs'} | ${false}
|
|
|
|
${'blobs'} | ${false}
|
|
|
|
`(`dropdown`, ({ scope, showFilter }) => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({ query: { scope } });
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`does${showFilter ? '' : ' not'} render when scope is ${scope}`, () => {
|
|
|
|
expect(findRadioFilter().exists()).toBe(showFilter);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|