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

ci_icon_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: cbb725bf9e63e11c0ed87d7bb3f5cae5b30722d4 (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
import { GlIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import CiIcon from '~/vue_shared/components/ci_icon.vue';

const mockStatus = {
  group: 'success',
  icon: 'status_success',
  text: 'Success',
};

describe('CI Icon component', () => {
  let wrapper;

  const createComponent = ({ props = {} } = {}) => {
    wrapper = shallowMount(CiIcon, {
      propsData: {
        status: mockStatus,
        ...props,
      },
    });
  };

  const findIcon = () => wrapper.findComponent(GlIcon);

  it('should render a span element and an icon', () => {
    createComponent();

    expect(wrapper.attributes('size')).toBe('md');
    expect(findIcon().exists()).toBe(true);
  });

  describe.each`
    showStatusText | showTooltip | expectedText | expectedTooltip | expectedAriaLabel
    ${true}        | ${true}     | ${'Success'} | ${undefined}    | ${undefined}
    ${true}        | ${false}    | ${'Success'} | ${undefined}    | ${undefined}
    ${false}       | ${true}     | ${''}        | ${'Success'}    | ${'Success'}
    ${false}       | ${false}    | ${''}        | ${undefined}    | ${'Success'}
  `(
    'when showStatusText is %{showStatusText} and showTooltip is %{showTooltip}',
    ({ showStatusText, showTooltip, expectedText, expectedTooltip, expectedAriaLabel }) => {
      beforeEach(() => {
        createComponent({
          props: {
            showStatusText,
            showTooltip,
          },
        });
      });

      it(`aria-label is ${expectedAriaLabel}`, () => {
        expect(wrapper.attributes('aria-label')).toBe(expectedAriaLabel);
      });

      it(`text shown is ${expectedAriaLabel}`, () => {
        expect(wrapper.text()).toBe(expectedText);
      });

      it(`tooltip shown is ${expectedAriaLabel}`, () => {
        expect(wrapper.attributes('title')).toBe(expectedTooltip);
      });
    },
  );

  describe('when appearing as a link', () => {
    it('shows a GraphQL path', () => {
      createComponent({
        props: {
          status: {
            ...mockStatus,
            detailsPath: '/path',
          },
          useLink: true,
        },
      });

      expect(wrapper.attributes('href')).toBe('/path');
    });

    it('shows a REST API path', () => {
      createComponent({
        props: {
          status: {
            ...mockStatus,
            details_path: '/path',
          },
          useLink: true,
        },
      });

      expect(wrapper.attributes('href')).toBe('/path');
    });

    it('shows no path', () => {
      createComponent({
        status: {
          detailsPath: '/path',
          details_path: '/path',
        },
        props: {
          useLink: false,
        },
      });

      expect(wrapper.attributes('href')).toBe(undefined);
    });
  });

  describe('rendering a status icon and class', () => {
    it.each`
      icon                 | variant
      ${'status_success'}  | ${'success'}
      ${'status_warning'}  | ${'warning'}
      ${'status_pending'}  | ${'warning'}
      ${'status_failed'}   | ${'danger'}
      ${'status_running'}  | ${'info'}
      ${'status_created'}  | ${'neutral'}
      ${'status_skipped'}  | ${'neutral'}
      ${'status_canceled'} | ${'neutral'}
      ${'status_manual'}   | ${'neutral'}
    `('should render a $group status', ({ icon, variant }) => {
      createComponent({
        props: {
          status: {
            ...mockStatus,
            icon,
          },
          showStatusText: true,
        },
      });
      expect(wrapper.attributes('variant')).toBe(variant);
      expect(wrapper.classes(`ci-icon-variant-${variant}`)).toBe(true);

      expect(findIcon().props('name')).toBe(`${icon}_borderless`);
    });
  });
});