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.

90 lines
2.6 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';
2023-06-20 00:43:36 +05:30
import LanguageFilter from '~/search/sidebar/components/language_filter/index.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-05-27 22:25:52 +05:30
const getterSpies = {
currentScope: jest.fn(() => 'issues'),
};
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,
2023-05-27 22:25:52 +05:30
getters: getterSpies,
2021-01-29 00:20:46 +05:30
});
wrapper = shallowMount(GlobalSearchSidebar, {
store,
2023-01-13 00:05:48 +05:30
provide: {
glFeatures: {
...featureFlags,
},
},
2021-01-29 00:20:46 +05:30
});
};
2023-01-13 00:05:48 +05:30
const findSidebarSection = () => wrapper.find('section');
const findFilters = () => wrapper.findComponent(ResultsFilters);
const findSidebarNavigation = () => wrapper.findComponent(ScopeNavigation);
2023-04-23 21:23:45 +05:30
const findLanguageAggregation = () => wrapper.findComponent(LanguageFilter);
2021-01-29 00:20:46 +05:30
2023-01-13 00:05:48 +05:30
describe('renders properly', () => {
2023-04-23 21:23:45 +05:30
describe('always', () => {
2022-11-25 23:54:43 +05:30
beforeEach(() => {
2023-04-23 21:23:45 +05:30
createComponent({});
2022-11-25 23:54:43 +05:30
});
2023-04-23 21:23:45 +05:30
it(`shows section`, () => {
2023-01-13 00:05:48 +05:30
expect(findSidebarSection().exists()).toBe(true);
2022-11-25 23:54:43 +05:30
});
2021-01-29 00:20:46 +05:30
});
2023-04-23 21:23:45 +05:30
describe.each`
2023-05-27 22:25:52 +05:30
scope | showFilters | showsLanguage
2023-04-23 21:23:45 +05:30
${'issues'} | ${true} | ${false}
${'merge_requests'} | ${true} | ${false}
${'projects'} | ${false} | ${false}
${'blobs'} | ${false} | ${true}
2023-05-27 22:25:52 +05:30
`('sidebar scope: $scope', ({ scope, showFilters, showsLanguage }) => {
2022-11-25 23:54:43 +05:30
beforeEach(() => {
2023-05-27 22:25:52 +05:30
getterSpies.currentScope = jest.fn(() => scope);
createComponent({ urlQuery: { scope } });
2022-11-25 23:54:43 +05:30
});
2023-04-23 21:23:45 +05:30
it(`${!showFilters ? "doesn't" : ''} shows filters`, () => {
expect(findFilters().exists()).toBe(showFilters);
2022-11-25 23:54:43 +05:30
});
2023-05-27 22:25:52 +05:30
it(`${!showsLanguage ? "doesn't" : ''} shows language filters`, () => {
expect(findLanguageAggregation().exists()).toBe(showsLanguage);
2022-11-25 23:54:43 +05:30
});
2021-01-29 00:20:46 +05:30
});
2023-04-23 21:23:45 +05:30
describe('renders navigation', () => {
2021-12-11 22:18:48 +05:30
beforeEach(() => {
2023-04-23 21:23:45 +05:30
createComponent({});
2021-12-11 22:18:48 +05:30
});
2023-04-23 21:23:45 +05:30
it('shows the vertical navigation', () => {
expect(findSidebarNavigation().exists()).toBe(true);
2021-12-11 22:18:48 +05:30
});
});
});
2021-01-29 00:20:46 +05:30
});