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

sort_dropdown_spec.js « components « tags « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e0ff370d31341574b45327c107bc0de347b181dd (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
import { GlDropdownItem, GlSearchBoxByClick } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import * as urlUtils from '~/lib/utils/url_utility';
import SortDropdown from '~/tags/components/sort_dropdown.vue';

describe('Tags sort dropdown', () => {
  let wrapper;

  const createWrapper = (props = {}) => {
    return extendedWrapper(
      mount(SortDropdown, {
        provide: {
          filterTagsPath: '/root/ci-cd-project-demo/-/tags',
          sortOptions: {
            name_asc: 'Name',
            updated_asc: 'Oldest updated',
            updated_desc: 'Last updated',
          },
          ...props,
        },
      }),
    );
  };

  const findSearchBox = () => wrapper.findComponent(GlSearchBoxByClick);
  const findTagsDropdown = () => wrapper.findByTestId('tags-dropdown');

  describe('default state', () => {
    beforeEach(() => {
      wrapper = createWrapper();
    });

    it('should have a search box with a placeholder', () => {
      const searchBox = findSearchBox();

      expect(searchBox.exists()).toBe(true);
      expect(searchBox.find('input').attributes('placeholder')).toBe('Filter by tag name');
    });

    it('should have a sort order dropdown', () => {
      const branchesDropdown = findTagsDropdown();

      expect(branchesDropdown.exists()).toBe(true);
    });
  });

  describe('when submitting a search term', () => {
    beforeEach(() => {
      urlUtils.visitUrl = jest.fn();

      wrapper = createWrapper();
    });

    it('should call visitUrl', () => {
      const searchBox = findSearchBox();

      searchBox.vm.$emit('submit');

      expect(urlUtils.visitUrl).toHaveBeenCalledWith(
        '/root/ci-cd-project-demo/-/tags?sort=updated_desc',
      );
    });

    it('should send a sort parameter', () => {
      const sortDropdownItems = findTagsDropdown().findAllComponents(GlDropdownItem).at(0);

      sortDropdownItems.vm.$emit('click');

      expect(urlUtils.visitUrl).toHaveBeenCalledWith(
        '/root/ci-cd-project-demo/-/tags?sort=name_asc',
      );
    });
  });
});