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.

102 lines
3.1 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-04-23 21:23:45 +05:30
import LanguageFilter from '~/search/sidebar/components/language_filter.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
});
};
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`
scope | showFilters | ShowsLanguage
${'issues'} | ${true} | ${false}
${'merge_requests'} | ${true} | ${false}
${'projects'} | ${false} | ${false}
${'blobs'} | ${false} | ${true}
`('sidebar scope: $scope', ({ scope, showFilters, ShowsLanguage }) => {
2022-11-25 23:54:43 +05:30
beforeEach(() => {
2023-04-23 21:23:45 +05:30
createComponent({ urlQuery: { scope } }, { searchBlobsLanguageAggregation: true });
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-04-23 21:23:45 +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
});
});
});
2023-04-23 21:23:45 +05:30
describe('when search_blobs_language_aggregation is enabled', () => {
2023-01-13 00:05:48 +05:30
beforeEach(() => {
2023-04-23 21:23:45 +05:30
createComponent({ urlQuery: { scope: 'blobs' } }, { searchBlobsLanguageAggregation: true });
2021-12-11 22:18:48 +05:30
});
2023-04-23 21:23:45 +05:30
it('shows the language filter', () => {
expect(findLanguageAggregation().exists()).toBe(true);
2021-01-29 00:20:46 +05:30
});
});
2023-04-23 21:23:45 +05:30
describe('when search_blobs_language_aggregation is disabled', () => {
2021-01-29 00:20:46 +05:30
beforeEach(() => {
2023-04-23 21:23:45 +05:30
createComponent({ urlQuery: { scope: 'blobs' } }, { searchBlobsLanguageAggregation: false });
2021-01-29 00:20:46 +05:30
});
2023-04-23 21:23:45 +05:30
it('hides the language filter', () => {
expect(findLanguageAggregation().exists()).toBe(false);
2021-01-29 00:20:46 +05:30
});
});
});