debian-mirror-gitlab/spec/frontend/search/topbar/components/app_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

98 lines
2.6 KiB
JavaScript
Raw Normal View History

2022-05-07 20:08:51 +05:30
import { GlSearchBoxByClick } from '@gitlab/ui';
2021-10-27 15:23:28 +05:30
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
2021-03-11 19:13:27 +05:30
import Vuex from 'vuex';
import { MOCK_QUERY } from 'jest/search/mock_data';
import GlobalSearchTopbar from '~/search/topbar/components/app.vue';
import GroupFilter from '~/search/topbar/components/group_filter.vue';
import ProjectFilter from '~/search/topbar/components/project_filter.vue';
2021-10-27 15:23:28 +05:30
Vue.use(Vuex);
2021-03-11 19:13:27 +05:30
describe('GlobalSearchTopbar', () => {
let wrapper;
const actionSpies = {
applyQuery: jest.fn(),
setQuery: jest.fn(),
2021-10-27 15:23:28 +05:30
preloadStoredFrequentItems: jest.fn(),
2021-03-11 19:13:27 +05:30
};
const createComponent = (initialState) => {
const store = new Vuex.Store({
state: {
query: MOCK_QUERY,
...initialState,
},
actions: actionSpies,
});
wrapper = shallowMount(GlobalSearchTopbar, {
store,
});
};
afterEach(() => {
wrapper.destroy();
});
2022-05-07 20:08:51 +05:30
const findGlSearchBox = () => wrapper.find(GlSearchBoxByClick);
2021-03-11 19:13:27 +05:30
const findGroupFilter = () => wrapper.find(GroupFilter);
const findProjectFilter = () => wrapper.find(ProjectFilter);
describe('template', () => {
beforeEach(() => {
createComponent();
});
describe('Search box', () => {
it('renders always', () => {
expect(findGlSearchBox().exists()).toBe(true);
});
});
describe.each`
snippets | showFilters
${null} | ${true}
${{ query: { snippets: '' } }} | ${true}
${{ query: { snippets: false } }} | ${true}
${{ query: { snippets: true } }} | ${false}
${{ query: { snippets: 'false' } }} | ${true}
${{ query: { snippets: 'true' } }} | ${false}
`('topbar filters', ({ snippets, showFilters }) => {
beforeEach(() => {
createComponent(snippets);
});
it(`does${showFilters ? '' : ' not'} render when snippets is ${JSON.stringify(
snippets,
)}`, () => {
expect(findGroupFilter().exists()).toBe(showFilters);
expect(findProjectFilter().exists()).toBe(showFilters);
});
});
});
describe('actions', () => {
beforeEach(() => {
createComponent();
});
2022-05-07 20:08:51 +05:30
it('clicking search button inside search box calls applyQuery', () => {
findGlSearchBox().vm.$emit('submit', { preventDefault: () => {} });
2021-03-11 19:13:27 +05:30
expect(actionSpies.applyQuery).toHaveBeenCalled();
});
});
2021-10-27 15:23:28 +05:30
describe('onCreate', () => {
beforeEach(() => {
createComponent();
});
it('calls preloadStoredFrequentItems', () => {
expect(actionSpies.preloadStoredFrequentItems).toHaveBeenCalled();
});
});
2021-03-11 19:13:27 +05:30
});