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

search_and_sort_bar_spec.js « search_and_sort_bar « components « usage_quotas « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2b3e04b329acec8ae46c11ea0c540451a0edcfd8 (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
import { shallowMount } from '@vue/test-utils';
import SearchAndSortBar from '~/usage_quotas/components/search_and_sort_bar/search_and_sort_bar.vue';
import { FILTERED_SEARCH_TERM } from '~/vue_shared/components/filtered_search_bar/constants';
import FilteredSortContainerRoot from '~/vue_shared/components/filtered_search_bar/filtered_search_bar_root.vue';

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

  const defaultProps = {
    namespace: '42',
    searchInputPlaceholder: 'Search term',
  };

  const findFilteredSortContainerRoot = () => wrapper.findComponent(FilteredSortContainerRoot);

  const createComponent = (config) => {
    const { props = {}, listeners = {} } = config;

    wrapper = shallowMount(SearchAndSortBar, {
      propsData: { ...defaultProps, ...props },
      listeners,
    });
  };

  describe('onFilter', () => {
    const onFilter = jest.fn();

    beforeEach(() => {
      createComponent({
        listeners: { onFilter },
      });
    });

    it('parses and propagates emitted search event', () => {
      const filteredSortContainerRoot = findFilteredSortContainerRoot();
      filteredSortContainerRoot.vm.$emit('onFilter', [
        {
          id: 'token-1',
          type: FILTERED_SEARCH_TERM,
          value: {
            data: 'abc',
          },
        },
        {
          id: 'token-2',
          type: FILTERED_SEARCH_TERM,
          value: {
            data: 'def',
          },
        },
        {
          id: 'token-3',
          type: FILTERED_SEARCH_TERM,
          value: {
            data: '123',
          },
        },
      ]);

      expect(onFilter).toHaveBeenCalledTimes(1);
      expect(onFilter).toHaveBeenCalledWith('abc def 123');
    });
  });

  describe('onSort', () => {
    const onSort = jest.fn();

    beforeEach(() => {
      createComponent({
        listeners: { onSort },
      });
    });

    it('propagates emitted sorting value', () => {
      const SORTING_VALUE = 'name_desc';
      const filteredSortContainerRoot = findFilteredSortContainerRoot();
      filteredSortContainerRoot.vm.$emit('onSort', SORTING_VALUE);

      expect(onSort).toHaveBeenCalledTimes(1);
      expect(onSort).toHaveBeenCalledWith(SORTING_VALUE);
    });
  });
});