diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-14 00:11:27 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-14 00:11:27 +0300 |
commit | 79ccfc9873583adba5ef73a36e9183176c9a0530 (patch) | |
tree | ef616803b9292d2f562f12f538eddef14348595a /spec/frontend/search | |
parent | a5c9ef1929e2b7c1b1beb964d36f9e782ed01e8b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/search')
-rw-r--r-- | spec/frontend/search/sidebar/components/merge_requests_filters_spec.js | 123 |
1 files changed, 113 insertions, 10 deletions
diff --git a/spec/frontend/search/sidebar/components/merge_requests_filters_spec.js b/spec/frontend/search/sidebar/components/merge_requests_filters_spec.js index 0932f8e47d2..72f93680675 100644 --- a/spec/frontend/search/sidebar/components/merge_requests_filters_spec.js +++ b/spec/frontend/search/sidebar/components/merge_requests_filters_spec.js @@ -1,28 +1,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 FiltersTemplate from '~/search/sidebar/components/filters_template.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 findStatusFilter = () => wrapper.findComponent(StatusFilter); - const findFiltersTemplate = () => wrapper.findComponent(FiltersTemplate); + const defaultGetters = { + currentScope: () => 'merge_requests', + }; - const createComponent = () => { - wrapper = shallowMount(MergeRequestsFilters); + 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, + }, + }, + }); }; - describe('Renders correctly', () => { + 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(); + 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 ConfidentialityFilter', () => { + + 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 FiltersTemplate', () => { - expect(findFiltersTemplate().exists()).toBe(true); + it("doesn't render ArchivedFilter", () => { + expect(findArchivedFilter().exists()).toBe(false); + }); + + it('renders 1 divider', () => { + expect(findDividers()).toHaveLength(0); + }); + }); + + 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 = () => 'blobs'; + 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); }); }); }); |