Welcome to mirror list, hosted at ThFree Co, Russian Federation.

filters_spec.js « components « sidebar « search « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d3c774929f52cdd167bdae7bec5f5c97ba9135a1 (plain)
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
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 IssuesFilters from '~/search/sidebar/components/issues_filters.vue';
import ConfidentialityFilter from '~/search/sidebar/components/confidentiality_filter/index.vue';
import StatusFilter from '~/search/sidebar/components/status_filter/index.vue';

Vue.use(Vuex);

describe('GlobalSearchSidebarFilters', () => {
  let wrapper;

  const actionSpies = {
    applyQuery: jest.fn(),
    resetQuery: jest.fn(),
  };

  const defaultGetters = {
    currentScope: () => 'issues',
  };

  const createComponent = (initialState) => {
    const store = new Vuex.Store({
      state: {
        urlQuery: MOCK_QUERY,
        ...initialState,
      },
      actions: actionSpies,
      getters: defaultGetters,
    });

    wrapper = shallowMount(IssuesFilters, {
      store,
    });
  };

  const findStatusFilter = () => wrapper.findComponent(StatusFilter);
  const findConfidentialityFilter = () => wrapper.findComponent(ConfidentialityFilter);

  describe('Renders correctly', () => {
    beforeEach(() => {
      createComponent({ urlQuery: MOCK_QUERY });
    });
    it('renders StatusFilter', () => {
      expect(findStatusFilter().exists()).toBe(true);
    });

    it('renders ConfidentialityFilter', () => {
      expect(findConfidentialityFilter().exists()).toBe(true);
    });
  });

  describe.each`
    scope               | showFilter
    ${'issues'}         | ${true}
    ${'merge_requests'} | ${false}
    ${'projects'}       | ${false}
    ${'milestones'}     | ${false}
    ${'users'}          | ${false}
    ${'notes'}          | ${false}
    ${'wiki_blobs'}     | ${false}
    ${'blobs'}          | ${false}
  `(`ConfidentialityFilter`, ({ scope, showFilter }) => {
    beforeEach(() => {
      defaultGetters.currentScope = () => scope;
      createComponent();
    });
    afterEach(() => {
      defaultGetters.currentScope = () => 'issues';
    });

    it(`does${showFilter ? '' : ' not'} render when scope is ${scope}`, () => {
      expect(findConfidentialityFilter().exists()).toBe(showFilter);
    });
  });

  describe.each`
    scope               | showFilter
    ${'issues'}         | ${true}
    ${'merge_requests'} | ${true}
    ${'projects'}       | ${false}
    ${'milestones'}     | ${false}
    ${'users'}          | ${false}
    ${'notes'}          | ${false}
    ${'wiki_blobs'}     | ${false}
    ${'blobs'}          | ${false}
  `(`StatusFilter`, ({ scope, showFilter }) => {
    beforeEach(() => {
      defaultGetters.currentScope = () => scope;
      createComponent();
    });
    afterEach(() => {
      defaultGetters.currentScope = () => 'issues';
    });

    it(`does${showFilter ? '' : ' not'} render when scope is ${scope}`, () => {
      expect(findStatusFilter().exists()).toBe(showFilter);
    });
  });
});