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

summary_row_spec.js « components « reports « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 778660d9e446467574a667778098165316bdbeba (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
import { mount } from '@vue/test-utils';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import HelpPopover from '~/vue_shared/components/help_popover.vue';
import SummaryRow from '~/reports/components/summary_row.vue';

describe('Summary row', () => {
  let wrapper;

  const summary = 'SAST detected 1 new vulnerability and 1 fixed vulnerability';
  const popoverOptions = {
    title: 'Static Application Security Testing (SAST)',
    content: '<a>Learn more about SAST</a>',
  };
  const statusIcon = 'warning';

  const createComponent = ({ props = {}, slots = {} } = {}) => {
    wrapper = extendedWrapper(
      mount(SummaryRow, {
        propsData: {
          summary,
          popoverOptions,
          statusIcon,
          ...props,
        },
        slots,
      }),
    );
  };

  const findSummary = () => wrapper.findByTestId('summary-row-description');
  const findStatusIcon = () => wrapper.findByTestId('summary-row-icon');
  const findHelpPopover = () => wrapper.findComponent(HelpPopover);

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

  it('renders provided summary', () => {
    createComponent();
    expect(findSummary().text()).toContain(summary);
  });

  it('renders provided icon', () => {
    createComponent();
    expect(findStatusIcon().classes()).toContain('js-ci-status-icon-warning');
  });

  it('renders help popover if popoverOptions are provided', () => {
    createComponent();
    expect(findHelpPopover().props('options')).toEqual(popoverOptions);
  });

  it('does not render help popover if popoverOptions are not provided', () => {
    createComponent({ props: { popoverOptions: null } });
    expect(findHelpPopover().exists()).toBe(false);
  });

  describe('summary slot', () => {
    it('replaces the summary prop', () => {
      const summarySlotContent = 'Summary slot content';
      createComponent({ slots: { summary: summarySlotContent } });

      expect(wrapper.text()).not.toContain(summary);
      expect(findSummary().text()).toContain(summarySlotContent);
    });
  });
});