1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
// eslint-disable-next-line no-restricted-imports
import Vuex from 'vuex';
import {
SEARCH_TYPE_ZOEKT,
SEARCH_TYPE_ADVANCED,
SEARCH_TYPE_BASIC,
} from '~/search/sidebar/constants';
import { MOCK_QUERY } from 'jest/search/mock_data';
import { toggleSuperSidebarCollapsed } from '~/super_sidebar/super_sidebar_collapsed_state_manager';
import GlobalSearchSidebar from '~/search/sidebar/components/app.vue';
import IssuesFilters from '~/search/sidebar/components/issues_filters.vue';
import MergeRequestsFilters from '~/search/sidebar/components/merge_requests_filters.vue';
import BlobsFilters from '~/search/sidebar/components/blobs_filters.vue';
import ProjectsFilters from '~/search/sidebar/components/projects_filters.vue';
import NotesFilters from '~/search/sidebar/components/notes_filters.vue';
import CommitsFilters from '~/search/sidebar/components/commits_filters.vue';
import MilestonesFilters from '~/search/sidebar/components/milestones_filters.vue';
import ScopeLegacyNavigation from '~/search/sidebar/components/scope_legacy_navigation.vue';
import SmallScreenDrawerNavigation from '~/search/sidebar/components/small_screen_drawer_navigation.vue';
import ScopeSidebarNavigation from '~/search/sidebar/components/scope_sidebar_navigation.vue';
import DomElementListener from '~/vue_shared/components/dom_element_listener.vue';
jest.mock('~/super_sidebar/super_sidebar_collapsed_state_manager');
Vue.use(Vuex);
describe('GlobalSearchSidebar', () => {
let wrapper;
const getterSpies = {
currentScope: jest.fn(() => 'issues'),
};
const createComponent = (initialState = {}) => {
const store = new Vuex.Store({
state: {
urlQuery: MOCK_QUERY,
...initialState,
},
getters: getterSpies,
});
wrapper = shallowMount(GlobalSearchSidebar, {
store,
});
};
const findSidebarSection = () => wrapper.find('section');
const findIssuesFilters = () => wrapper.findComponent(IssuesFilters);
const findMergeRequestsFilters = () => wrapper.findComponent(MergeRequestsFilters);
const findBlobsFilters = () => wrapper.findComponent(BlobsFilters);
const findProjectsFilters = () => wrapper.findComponent(ProjectsFilters);
const findNotesFilters = () => wrapper.findComponent(NotesFilters);
const findCommitsFilters = () => wrapper.findComponent(CommitsFilters);
const findMilestonesFilters = () => wrapper.findComponent(MilestonesFilters);
const findScopeLegacyNavigation = () => wrapper.findComponent(ScopeLegacyNavigation);
const findSmallScreenDrawerNavigation = () => wrapper.findComponent(SmallScreenDrawerNavigation);
const findScopeSidebarNavigation = () => wrapper.findComponent(ScopeSidebarNavigation);
const findDomElementListener = () => wrapper.findComponent(DomElementListener);
describe('renders properly', () => {
describe('always', () => {
beforeEach(() => {
createComponent();
});
it(`shows section`, () => {
expect(findSidebarSection().exists()).toBe(true);
});
});
describe.each`
scope | filter | searchType | isShown
${'issues'} | ${findIssuesFilters} | ${SEARCH_TYPE_BASIC} | ${true}
${'merge_requests'} | ${findMergeRequestsFilters} | ${SEARCH_TYPE_BASIC} | ${true}
${'projects'} | ${findProjectsFilters} | ${SEARCH_TYPE_BASIC} | ${true}
${'blobs'} | ${findBlobsFilters} | ${SEARCH_TYPE_BASIC} | ${false}
${'blobs'} | ${findBlobsFilters} | ${SEARCH_TYPE_ADVANCED} | ${true}
${'blobs'} | ${findBlobsFilters} | ${SEARCH_TYPE_ZOEKT} | ${false}
${'notes'} | ${findNotesFilters} | ${SEARCH_TYPE_BASIC} | ${true}
${'notes'} | ${findNotesFilters} | ${SEARCH_TYPE_ADVANCED} | ${true}
${'commits'} | ${findCommitsFilters} | ${SEARCH_TYPE_BASIC} | ${true}
${'commits'} | ${findCommitsFilters} | ${SEARCH_TYPE_ADVANCED} | ${true}
${'milestones'} | ${findMilestonesFilters} | ${SEARCH_TYPE_BASIC} | ${true}
${'milestones'} | ${findMilestonesFilters} | ${SEARCH_TYPE_ADVANCED} | ${true}
`('with sidebar $scope scope:', ({ scope, filter, searchType, isShown }) => {
beforeEach(() => {
getterSpies.currentScope = jest.fn(() => scope);
createComponent({ urlQuery: { scope }, searchType });
});
it(`renders correctly filter ${filter.name.replace(
'find',
'',
)} when search_type ${searchType}`, () => {
expect(filter().exists()).toBe(isShown);
});
});
describe('filters for blobs will not load if zoekt is enabled', () => {
beforeEach(() => {
createComponent({ urlQuery: { scope: 'blobs' }, searchType: SEARCH_TYPE_ZOEKT });
});
it("doesn't render blobs filters", () => {
expect(findBlobsFilters().exists()).toBe(false);
});
});
describe('with sidebar scope: projects', () => {
beforeEach(() => {
getterSpies.currentScope = jest.fn(() => 'projects');
createComponent({ urlQuery: { scope: 'projects' } });
});
it(`shows filter ProjectsFilters`, () => {
expect(findProjectsFilters().exists()).toBe(true);
});
});
describe.each`
currentScope | sidebarNavShown | legacyNavShown
${'issues'} | ${false} | ${true}
${'test'} | ${false} | ${true}
${'issues'} | ${true} | ${false}
${'test'} | ${true} | ${false}
`(
'renders navigation for scope $currentScope',
({ currentScope, sidebarNavShown, legacyNavShown }) => {
beforeEach(() => {
getterSpies.currentScope = jest.fn(() => currentScope);
createComponent({ useSidebarNavigation: sidebarNavShown });
});
it(`renders navigation correctly with legacyNavShown ${legacyNavShown}`, () => {
expect(findScopeLegacyNavigation().exists()).toBe(legacyNavShown);
expect(findSmallScreenDrawerNavigation().exists()).toBe(legacyNavShown);
});
it(`renders navigation correctly with sidebarNavShown ${sidebarNavShown}`, () => {
expect(findScopeSidebarNavigation().exists()).toBe(sidebarNavShown);
});
},
);
});
describe('when useSidebarNavigation=true', () => {
beforeEach(() => {
createComponent({ useSidebarNavigation: true });
});
it('toggles super sidebar when button is clicked', () => {
const elListener = findDomElementListener();
expect(toggleSuperSidebarCollapsed).not.toHaveBeenCalled();
elListener.vm.$emit('click');
expect(toggleSuperSidebarCollapsed).toHaveBeenCalledTimes(1);
expect(elListener.props('selector')).toBe('#js-open-mobile-filters');
});
});
});
|