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

getters_spec.js « store « labels_select_vue « sidebar « components « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 52116f757c5b28aa727ff058a138ae51f377f40c (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
import * as getters from '~/vue_shared/components/sidebar/labels_select_vue/store/getters';

describe('LabelsSelect Getters', () => {
  describe('dropdownButtonText', () => {
    it.each`
      labelType    | dropdownButtonText | expected
      ${'default'} | ${''}              | ${'Label'}
      ${'custom'}  | ${'Custom label'}  | ${'Custom label'}
    `(
      'returns $labelType text when state.labels has no selected labels',
      ({ dropdownButtonText, expected }) => {
        const labels = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }];
        const selectedLabels = [];
        const state = { labels, selectedLabels, dropdownButtonText };

        expect(getters.dropdownButtonText(state, {})).toBe(expected);
      },
    );

    it('returns label title when state.labels has only 1 label', () => {
      const labels = [{ id: 1, title: 'Foobar', set: true }];

      expect(getters.dropdownButtonText({ labels }, { isDropdownVariantSidebar: true })).toBe(
        'Foobar',
      );
    });

    it('returns first label title and remaining labels count when state.labels has more than 1 label', () => {
      const labels = [{ id: 1, title: 'Foo', set: true }, { id: 2, title: 'Bar', set: true }];

      expect(getters.dropdownButtonText({ labels }, { isDropdownVariantSidebar: true })).toBe(
        'Foo +1 more',
      );
    });
  });

  describe('selectedLabelsList', () => {
    it('returns array of IDs of all labels within `state.selectedLabels`', () => {
      const selectedLabels = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }];

      expect(getters.selectedLabelsList({ selectedLabels })).toEqual([1, 2, 3, 4]);
    });
  });

  describe('isDropdownVariantSidebar', () => {
    it('returns `true` when `state.variant` is "sidebar"', () => {
      expect(getters.isDropdownVariantSidebar({ variant: 'sidebar' })).toBe(true);
    });
  });

  describe('isDropdownVariantStandalone', () => {
    it('returns `true` when `state.variant` is "standalone"', () => {
      expect(getters.isDropdownVariantStandalone({ variant: 'standalone' })).toBe(true);
    });
  });
});