summaryrefslogtreecommitdiff
path: root/spec/frontend/reports/codequality_report/components/codequality_issue_body_spec.js
blob: 17f07ac2b8f73c53dd83bef703a092b37f51413c (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
import { GlIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import component from '~/reports/codequality_report/components/codequality_issue_body.vue';
import { STATUS_FAILED, STATUS_NEUTRAL, STATUS_SUCCESS } from '~/reports/constants';

describe('code quality issue body issue body', () => {
  let wrapper;

  const findSeverityIcon = () => wrapper.findByTestId('codequality-severity-icon');
  const findGlIcon = () => wrapper.find(GlIcon);

  const codequalityIssue = {
    name:
      'rubygem-rest-client: session fixation vulnerability via Set-Cookie headers in 30x redirection responses',
    path: 'Gemfile.lock',
    severity: 'normal',
    type: 'Issue',
    urlPath: '/Gemfile.lock#L22',
  };

  const createComponent = (initialStatus, issue = codequalityIssue) => {
    wrapper = extendedWrapper(
      shallowMount(component, {
        propsData: {
          issue,
          status: initialStatus,
        },
      }),
    );
  };

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

  describe('severity rating', () => {
    it.each`
      severity      | iconClass               | iconName
      ${'INFO'}     | ${'text-primary-400'}   | ${'severity-info'}
      ${'MINOR'}    | ${'text-warning-200'}   | ${'severity-low'}
      ${'CRITICAL'} | ${'text-danger-600'}    | ${'severity-high'}
      ${'BLOCKER'}  | ${'text-danger-800'}    | ${'severity-critical'}
      ${'UNKNOWN'}  | ${'text-secondary-400'} | ${'severity-unknown'}
      ${'INVALID'}  | ${'text-secondary-400'} | ${'severity-unknown'}
      ${'info'}     | ${'text-primary-400'}   | ${'severity-info'}
      ${'minor'}    | ${'text-warning-200'}   | ${'severity-low'}
      ${'major'}    | ${'text-warning-400'}   | ${'severity-medium'}
      ${'critical'} | ${'text-danger-600'}    | ${'severity-high'}
      ${'blocker'}  | ${'text-danger-800'}    | ${'severity-critical'}
      ${'unknown'}  | ${'text-secondary-400'} | ${'severity-unknown'}
      ${'invalid'}  | ${'text-secondary-400'} | ${'severity-unknown'}
      ${undefined}  | ${'text-secondary-400'} | ${'severity-unknown'}
    `(
      'renders correct icon for "$severity" severity rating',
      ({ severity, iconClass, iconName }) => {
        createComponent(STATUS_FAILED, {
          ...codequalityIssue,
          severity,
        });
        const icon = findGlIcon();

        expect(findSeverityIcon().classes()).toContain(iconClass);
        expect(icon.exists()).toBe(true);
        expect(icon.props('name')).toBe(iconName);
      },
    );
  });

  describe('with success', () => {
    it('renders fixed label', () => {
      createComponent(STATUS_SUCCESS);

      expect(wrapper.text()).toContain('Fixed');
    });
  });

  describe('without success', () => {
    it('does not render fixed label', () => {
      createComponent(STATUS_FAILED);

      expect(wrapper.text()).not.toContain('Fixed');
    });
  });

  describe('name', () => {
    it('renders name', () => {
      createComponent(STATUS_NEUTRAL);

      expect(wrapper.text()).toContain(codequalityIssue.name);
    });
  });

  describe('path', () => {
    it('renders the report-link path using the correct code quality issue', () => {
      createComponent(STATUS_NEUTRAL);

      expect(wrapper.find('report-link-stub').props('issue')).toBe(codequalityIssue);
    });
  });
});