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

ci_badge_link_spec.js « components « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8c860c9b06f6d00459e435cba1f2cbcad19a0d65 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import { GlBadge } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import CiBadgeLink from '~/vue_shared/components/ci_badge_link.vue';
import CiIcon from '~/vue_shared/components/ci_icon.vue';

jest.mock('~/lib/utils/url_utility', () => ({
  visitUrl: jest.fn(),
}));

describe('CI Badge Link Component', () => {
  let wrapper;

  const statuses = {
    canceled: {
      text: 'canceled',
      label: 'canceled',
      group: 'canceled',
      icon: 'status_canceled',
      details_path: 'status/canceled',
    },
    created: {
      text: 'created',
      label: 'created',
      group: 'created',
      icon: 'status_created',
      details_path: 'status/created',
    },
    failed: {
      text: 'failed',
      label: 'failed',
      group: 'failed',
      icon: 'status_failed',
      details_path: 'status/failed',
    },
    manual: {
      text: 'manual',
      label: 'manual action',
      group: 'manual',
      icon: 'status_manual',
      details_path: 'status/manual',
    },
    pending: {
      text: 'pending',
      label: 'pending',
      group: 'pending',
      icon: 'status_pending',
      details_path: 'status/pending',
    },
    preparing: {
      text: 'preparing',
      label: 'preparing',
      group: 'preparing',
      icon: 'status_preparing',
      details_path: 'status/preparing',
    },
    running: {
      text: 'running',
      label: 'running',
      group: 'running',
      icon: 'status_running',
      details_path: 'status/running',
    },
    scheduled: {
      text: 'scheduled',
      label: 'scheduled',
      group: 'scheduled',
      icon: 'status_scheduled',
      details_path: 'status/scheduled',
    },
    skipped: {
      text: 'skipped',
      label: 'skipped',
      group: 'skipped',
      icon: 'status_skipped',
      details_path: 'status/skipped',
    },
    success_warining: {
      text: 'warning',
      label: 'passed with warnings',
      group: 'success-with-warnings',
      icon: 'status_warning',
      details_path: 'status/warning',
    },
    success: {
      text: 'passed',
      label: 'passed',
      group: 'passed',
      icon: 'status_success',
      details_path: 'status/passed',
    },
  };

  const findIcon = () => wrapper.findComponent(CiIcon);
  const findBadge = () => wrapper.findComponent(GlBadge);
  const findBadgeText = () => wrapper.find('[data-testid="ci-badge-text"');

  const createComponent = (propsData) => {
    wrapper = shallowMount(CiBadgeLink, { propsData });
  };

  it.each(Object.keys(statuses))('should render badge for status: %s', (status) => {
    createComponent({ status: statuses[status] });

    expect(wrapper.attributes('href')).toBe(statuses[status].details_path);
    expect(wrapper.text()).toBe(statuses[status].text);
    expect(findBadge().props('size')).toBe('md');
    expect(findIcon().exists()).toBe(true);
  });

  it.each`
    status                       | textColor               | variant
    ${statuses.success}          | ${'gl-text-green-700'}  | ${'success'}
    ${statuses.success_warining} | ${'gl-text-orange-700'} | ${'warning'}
    ${statuses.failed}           | ${'gl-text-red-700'}    | ${'danger'}
    ${statuses.running}          | ${'gl-text-blue-700'}   | ${'info'}
    ${statuses.pending}          | ${'gl-text-orange-700'} | ${'warning'}
    ${statuses.preparing}        | ${'gl-text-gray-600'}   | ${'muted'}
    ${statuses.canceled}         | ${'gl-text-gray-700'}   | ${'neutral'}
    ${statuses.scheduled}        | ${'gl-text-gray-600'}   | ${'muted'}
    ${statuses.skipped}          | ${'gl-text-gray-600'}   | ${'muted'}
    ${statuses.manual}           | ${'gl-text-gray-700'}   | ${'neutral'}
    ${statuses.created}          | ${'gl-text-gray-600'}   | ${'muted'}
  `(
    'should contain correct badge class and variant for status: $status.text',
    ({ status, textColor, variant }) => {
      createComponent({ status });

      expect(findBadgeText().classes()).toContain(textColor);
      expect(findBadge().props('variant')).toBe(variant);
    },
  );

  it('should not render label', () => {
    createComponent({ status: statuses.canceled, showText: false });

    expect(wrapper.text()).toBe('');
  });

  it('should emit ciStatusBadgeClick event', () => {
    createComponent({ status: statuses.success });

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

    expect(wrapper.emitted('ciStatusBadgeClick')).toEqual([[]]);
  });

  it('should render dynamic badge size', () => {
    createComponent({ status: statuses.success, badgeSize: 'lg' });

    expect(findBadge().props('size')).toBe('lg');
  });
});