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
|
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
// eslint-disable-next-line no-restricted-imports
import Vuex from 'vuex';
import { MOCK_QUERY } from 'jest/search/mock_data';
import MergeRequestsFilters from '~/search/sidebar/components/merge_requests_filters.vue';
import StatusFilter from '~/search/sidebar/components/status_filter/index.vue';
import ArchivedFilter from '~/search/sidebar/components/archived_filter/index.vue';
import { SEARCH_TYPE_ADVANCED, SEARCH_TYPE_BASIC } from '~/search/sidebar/constants';
Vue.use(Vuex);
describe('GlobalSearch MergeRequestsFilters', () => {
let wrapper;
const defaultGetters = {
currentScope: () => 'merge_requests',
};
const createComponent = ({
initialState = {},
searchMergeRequestsHideArchivedProjects = true,
} = {}) => {
const store = new Vuex.Store({
state: {
urlQuery: MOCK_QUERY,
useSidebarNavigation: false,
searchType: SEARCH_TYPE_ADVANCED,
...initialState,
},
getters: defaultGetters,
});
wrapper = shallowMount(MergeRequestsFilters, {
store,
provide: {
glFeatures: {
searchMergeRequestsHideArchivedProjects,
},
},
});
};
const findStatusFilter = () => wrapper.findComponent(StatusFilter);
const findArchivedFilter = () => wrapper.findComponent(ArchivedFilter);
const findDividers = () => wrapper.findAll('hr');
describe.each`
description | searchMergeRequestsHideArchivedProjects
${'Renders correctly with Archived Filter disabled'} | ${false}
${'Renders correctly with Archived Filter enabled'} | ${true}
`('$description', ({ searchMergeRequestsHideArchivedProjects }) => {
beforeEach(() => {
createComponent({
searchMergeRequestsHideArchivedProjects,
});
});
it('renders StatusFilter', () => {
expect(findStatusFilter().exists()).toBe(true);
});
it(`renders correctly ArchivedFilter when searchMergeRequestsHideArchivedProjects is ${searchMergeRequestsHideArchivedProjects}`, () => {
expect(findArchivedFilter().exists()).toBe(searchMergeRequestsHideArchivedProjects);
});
it('renders divider correctly', () => {
const dividersCount = searchMergeRequestsHideArchivedProjects ? 1 : 0;
expect(findDividers()).toHaveLength(dividersCount);
});
});
describe('Renders correctly with basic search', () => {
beforeEach(() => {
createComponent({ initialState: { searchType: SEARCH_TYPE_BASIC } });
});
it('renders StatusFilter', () => {
expect(findStatusFilter().exists()).toBe(true);
});
it('renders render ArchivedFilter', () => {
expect(findArchivedFilter().exists()).toBe(true);
});
it('renders 1 divider', () => {
expect(findDividers()).toHaveLength(1);
});
});
describe('Renders correctly in new nav', () => {
beforeEach(() => {
createComponent({
initialState: {
searchType: SEARCH_TYPE_ADVANCED,
useSidebarNavigation: true,
},
searchMergeRequestsHideArchivedProjects: true,
});
});
it('renders StatusFilter', () => {
expect(findStatusFilter().exists()).toBe(true);
});
it('renders ArchivedFilter', () => {
expect(findArchivedFilter().exists()).toBe(true);
});
it("doesn't render divider", () => {
expect(findDividers()).toHaveLength(0);
});
});
describe('Renders correctly with wrong scope', () => {
beforeEach(() => {
defaultGetters.currentScope = () => 'test';
createComponent();
});
it("doesn't render StatusFilter", () => {
expect(findStatusFilter().exists()).toBe(false);
});
it("doesn't render ArchivedFilter", () => {
expect(findArchivedFilter().exists()).toBe(false);
});
it("doesn't render dividers", () => {
expect(findDividers()).toHaveLength(0);
});
});
});
|