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

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

107 lines
2.8 KiB
JavaScript
Raw Normal View History

2021-12-11 22:18:48 +05:30
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
2021-03-11 19:13:27 +05:30
import Vuex from 'vuex';
2021-01-29 00:20:46 +05:30
import { MOCK_QUERY } from 'jest/search/mock_data';
import GlobalSearchSidebar from '~/search/sidebar/components/app.vue';
2023-01-13 00:05:48 +05:30
import ResultsFilters from '~/search/sidebar/components/results_filters.vue';
import ScopeNavigation from '~/search/sidebar/components/scope_navigation.vue';
2021-01-29 00:20:46 +05:30
2021-12-11 22:18:48 +05:30
Vue.use(Vuex);
2021-01-29 00:20:46 +05:30
describe('GlobalSearchSidebar', () => {
let wrapper;
const actionSpies = {
applyQuery: jest.fn(),
resetQuery: jest.fn(),
};
2023-01-13 00:05:48 +05:30
const createComponent = (initialState, featureFlags) => {
2021-01-29 00:20:46 +05:30
const store = new Vuex.Store({
state: {
2021-12-11 22:18:48 +05:30
urlQuery: MOCK_QUERY,
2021-01-29 00:20:46 +05:30
...initialState,
},
actions: actionSpies,
});
wrapper = shallowMount(GlobalSearchSidebar, {
store,
2023-01-13 00:05:48 +05:30
provide: {
glFeatures: {
...featureFlags,
},
},
2021-01-29 00:20:46 +05:30
});
};
afterEach(() => {
wrapper.destroy();
});
2023-01-13 00:05:48 +05:30
const findSidebarSection = () => wrapper.find('section');
const findFilters = () => wrapper.findComponent(ResultsFilters);
const findSidebarNavigation = () => wrapper.findComponent(ScopeNavigation);
2021-01-29 00:20:46 +05:30
2023-01-13 00:05:48 +05:30
describe('renders properly', () => {
2022-11-25 23:54:43 +05:30
describe('scope=projects', () => {
beforeEach(() => {
createComponent({ urlQuery: { ...MOCK_QUERY, scope: 'projects' } });
});
2021-01-29 00:20:46 +05:30
2023-01-13 00:05:48 +05:30
it('shows section', () => {
expect(findSidebarSection().exists()).toBe(true);
2022-11-25 23:54:43 +05:30
});
2021-01-29 00:20:46 +05:30
2023-01-13 00:05:48 +05:30
it("doesn't shows filters", () => {
expect(findFilters().exists()).toBe(false);
2022-11-25 23:54:43 +05:30
});
2021-01-29 00:20:46 +05:30
});
2023-01-13 00:05:48 +05:30
describe('scope=merge_requests', () => {
2022-11-25 23:54:43 +05:30
beforeEach(() => {
2023-01-13 00:05:48 +05:30
createComponent({ urlQuery: { ...MOCK_QUERY, scope: 'merge_requests' } });
2022-11-25 23:54:43 +05:30
});
2023-01-13 00:05:48 +05:30
it('shows section', () => {
expect(findSidebarSection().exists()).toBe(true);
2022-11-25 23:54:43 +05:30
});
2023-01-13 00:05:48 +05:30
it('shows filters', () => {
expect(findFilters().exists()).toBe(true);
2022-11-25 23:54:43 +05:30
});
2021-01-29 00:20:46 +05:30
});
2023-01-13 00:05:48 +05:30
describe('scope=issues', () => {
2021-12-11 22:18:48 +05:30
beforeEach(() => {
2023-01-13 00:05:48 +05:30
createComponent({ urlQuery: MOCK_QUERY });
2021-12-11 22:18:48 +05:30
});
2023-01-13 00:05:48 +05:30
it('shows section', () => {
expect(findSidebarSection().exists()).toBe(true);
2021-12-11 22:18:48 +05:30
});
2023-01-13 00:05:48 +05:30
it('shows filters', () => {
expect(findFilters().exists()).toBe(true);
2021-12-11 22:18:48 +05:30
});
});
});
2023-01-13 00:05:48 +05:30
describe('when search_page_vertical_nav is enabled', () => {
beforeEach(() => {
createComponent({}, { searchPageVerticalNav: true });
2021-12-11 22:18:48 +05:30
});
2023-01-13 00:05:48 +05:30
it('shows the vertical navigation', () => {
expect(findSidebarNavigation().exists()).toBe(true);
2021-01-29 00:20:46 +05:30
});
});
2023-01-13 00:05:48 +05:30
describe('when search_page_vertical_nav is disabled', () => {
2021-01-29 00:20:46 +05:30
beforeEach(() => {
2023-01-13 00:05:48 +05:30
createComponent({}, { searchPageVerticalNav: false });
2021-01-29 00:20:46 +05:30
});
2023-01-13 00:05:48 +05:30
it('hides the vertical navigation', () => {
expect(findSidebarNavigation().exists()).toBe(false);
2021-01-29 00:20:46 +05:30
});
});
});