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

diff_code_quality_spec.js « components « diffs « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b5dce4fc924c32653ea5bf80190bee57a745f6be (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
import { GlIcon } from '@gitlab/ui';
import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper';
import DiffCodeQuality from '~/diffs/components/diff_code_quality.vue';
import { SEVERITY_CLASSES, SEVERITY_ICONS } from '~/reports/codequality_report/constants';
import { multipleFindingsArr } from '../mock_data/diff_code_quality';

let wrapper;

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

describe('DiffCodeQuality', () => {
  afterEach(() => {
    wrapper.destroy();
  });

  const createWrapper = (codeQuality, mountFunction = mountExtended) => {
    return mountFunction(DiffCodeQuality, {
      propsData: {
        expandedLines: [],
        codeQuality,
      },
    });
  };

  it('hides details and throws hideCodeQualityFindings event on close click', async () => {
    wrapper = createWrapper(multipleFindingsArr);
    expect(wrapper.findByTestId('diff-codequality').exists()).toBe(true);

    await wrapper.findByTestId('diff-codequality-close').trigger('click');
    expect(wrapper.emitted('hideCodeQualityFindings').length).toBe(1);
  });

  it('renders correct amount of list items for codequality array and their description', async () => {
    wrapper = createWrapper(multipleFindingsArr);
    const listItems = wrapper.findAll('li');

    expect(wrapper.findAll('li').length).toBe(3);

    listItems.wrappers.map((e, i) => {
      return expect(e.text()).toEqual(multipleFindingsArr[i].description);
    });
  });

  it.each`
    severity
    ${'info'}
    ${'minor'}
    ${'major'}
    ${'critical'}
    ${'blocker'}
    ${'unknown'}
  `('shows icon for $severity degradation', ({ severity }) => {
    wrapper = createWrapper([{ severity }], shallowMountExtended);

    expect(findIcon().exists()).toBe(true);

    expect(findIcon().attributes()).toMatchObject({
      class: `codequality-severity-icon ${SEVERITY_CLASSES[severity]}`,
      name: SEVERITY_ICONS[severity],
      size: '12',
    });
  });
});