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

archived_filter_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: a4c1f3b758f8e1d6149c46ef75c9416c1c69e491 (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
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
// eslint-disable-next-line no-restricted-imports
import Vuex from 'vuex';
import { GlFormCheckboxGroup } from '@gitlab/ui';
import ArchivedFilter from '~/search/sidebar/components/archived_filter/index.vue';

import { archivedFilterData } from '~/search/sidebar/components/archived_filter/data';

Vue.use(Vuex);

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

  const defaultActions = {
    setQuery: jest.fn(),
  };

  const createComponent = (state) => {
    const store = new Vuex.Store({
      state,
      actions: defaultActions,
    });

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

  const findCheckboxFilter = () => wrapper.findComponent(GlFormCheckboxGroup);
  const findH5 = () => wrapper.findComponent('h5');

  describe('old sidebar', () => {
    beforeEach(() => {
      createComponent({ useNewNavigation: false });
    });

    it('renders the component', () => {
      expect(findCheckboxFilter().exists()).toBe(true);
    });

    it('renders the divider', () => {
      expect(findH5().exists()).toBe(true);
      expect(findH5().text()).toBe(archivedFilterData.headerLabel);
    });
  });

  describe('new sidebar', () => {
    beforeEach(() => {
      createComponent({ useNewNavigation: true });
    });

    it('renders the component', () => {
      expect(findCheckboxFilter().exists()).toBe(true);
    });

    it("doesn't render the divider", () => {
      expect(findH5().exists()).toBe(true);
      expect(findH5().text()).toBe(archivedFilterData.headerLabel);
    });
  });

  describe.each`
    include_archived | checkboxState
    ${''}            | ${'false'}
    ${'false'}       | ${'false'}
    ${'true'}        | ${'true'}
    ${'sdfsdf'}      | ${'false'}
  `('selectedFilter', ({ include_archived, checkboxState }) => {
    beforeEach(() => {
      createComponent({ urlQuery: { include_archived } });
    });

    it('renders the component', () => {
      expect(findCheckboxFilter().attributes('checked')).toBe(checkboxState);
    });
  });

  describe('selectedFilter logic', () => {
    beforeEach(() => {
      createComponent();
    });

    it('correctly executes setQuery without mutating the input', () => {
      const selectedFilter = [false];
      findCheckboxFilter().vm.$emit('input', selectedFilter);
      expect(defaultActions.setQuery).toHaveBeenCalledWith(expect.any(Object), {
        key: 'include_archived',
        value: 'false',
      });
      expect(selectedFilter).toEqual([false]);
    });
  });
});