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

label_item_spec.js « 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: ad3f073fdf9a201252922839e80b4076be8baa9e (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { shallowMount } from '@vue/test-utils';

import { GlIcon, GlLink } from '@gitlab/ui';
import LabelItem from '~/vue_shared/components/sidebar/labels_select_vue/label_item.vue';
import { mockRegularLabel } from './mock_data';

const mockLabel = { ...mockRegularLabel, set: true };

const createComponent = ({ label = mockLabel, highlight = true } = {}) =>
  shallowMount(LabelItem, {
    propsData: {
      label,
      isLabelSet: label.set,
      highlight,
    },
  });

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

  beforeEach(() => {
    wrapper = createComponent();
  });

  afterEach(() => {
    wrapper.destroy();
  });

  describe('computed', () => {
    describe('labelBoxStyle', () => {
      it('returns an object containing `backgroundColor` based on `label` prop', () => {
        expect(wrapper.vm.labelBoxStyle).toEqual(
          expect.objectContaining({
            backgroundColor: mockLabel.color,
          }),
        );
      });
    });
  });

  describe('watchers', () => {
    describe('isLabelSet', () => {
      it('sets value of `isLabelSet` to `isSet` data prop', () => {
        expect(wrapper.vm.isSet).toBe(true);

        wrapper.setProps({
          isLabelSet: false,
        });

        return wrapper.vm.$nextTick(() => {
          expect(wrapper.vm.isSet).toBe(false);
        });
      });
    });
  });

  describe('methods', () => {
    describe('handleClick', () => {
      it('sets value of `isSet` data prop to opposite of its current value', () => {
        wrapper.setData({
          isSet: true,
        });

        wrapper.vm.handleClick();
        expect(wrapper.vm.isSet).toBe(false);
        wrapper.vm.handleClick();
        expect(wrapper.vm.isSet).toBe(true);
      });

      it('emits event `clickLabel` on component with `label` prop as param', () => {
        wrapper.vm.handleClick();

        expect(wrapper.emitted('clickLabel')).toBeTruthy();
        expect(wrapper.emitted('clickLabel')[0]).toEqual([mockLabel]);
      });
    });
  });

  describe('template', () => {
    it('renders gl-link component', () => {
      expect(wrapper.find(GlLink).exists()).toBe(true);
    });

    it('renders gl-link component with class `is-focused` when `highlight` prop is true', () => {
      wrapper.setProps({
        highlight: true,
      });

      return wrapper.vm.$nextTick(() => {
        expect(wrapper.find(GlLink).classes()).toContain('is-focused');
      });
    });

    it('renders visible gl-icon component when `isSet` prop is true', () => {
      wrapper.setData({
        isSet: true,
      });

      return wrapper.vm.$nextTick(() => {
        const iconEl = wrapper.find(GlIcon);

        expect(iconEl.isVisible()).toBe(true);
        expect(iconEl.props('name')).toBe('mobile-issue-close');
      });
    });

    it('renders visible span element as placeholder instead of gl-icon when `isSet` prop is false', () => {
      wrapper.setData({
        isSet: false,
      });

      return wrapper.vm.$nextTick(() => {
        const placeholderEl = wrapper.find('[data-testid="no-icon"]');

        expect(placeholderEl.isVisible()).toBe(true);
      });
    });

    it('renders label color element', () => {
      const colorEl = wrapper.find('[data-testid="label-color-box"]');

      expect(colorEl.exists()).toBe(true);
      expect(colorEl.attributes('style')).toBe('background-color: rgb(186, 218, 85);');
    });

    it('renders label title', () => {
      expect(wrapper.text()).toContain(mockLabel.title);
    });
  });
});