summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_shared/components/sidebar/labels_select_vue/store/getters_spec.js
blob: b866117efcf760a4c8c5cf007a446715b6506180 (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
import * as getters from '~/vue_shared/components/sidebar/labels_select_vue/store/getters';

describe('LabelsSelect Getters', () => {
  describe('dropdownButtonText', () => {
    it('returns string "Label" when state.labels has no selected labels', () => {
      const labels = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }];

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

    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);
    });
  });
});