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

highlight_bar_spec.js « incidents « components « issue_show « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 112cb4d4c3a60cc2084c250b519bedf1d94978e1 (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
import { shallowMount } from '@vue/test-utils';
import merge from 'lodash/merge';
import { GlLink } from '@gitlab/ui';
import HighlightBar from '~/issue_show/components/incidents/highlight_bar.vue';
import { formatDate } from '~/lib/utils/datetime_utility';

jest.mock('~/lib/utils/datetime_utility');

describe('Highlight Bar', () => {
  let wrapper;

  const alert = {
    iid: 1,
    startedAt: '2020-05-29T10:39:22Z',
    detailsUrl: 'http://127.0.0.1:3000/root/unique-alerts/-/alert_management/1/details',
    eventCount: 1,
    title: 'Alert 1',
  };

  const mountComponent = (options) => {
    wrapper = shallowMount(
      HighlightBar,
      merge(
        {
          propsData: { alert },
          provide: { fullPath: 'test', iid: 1, slaFeatureAvailable: true },
        },
        options,
      ),
    );
  };

  beforeEach(() => {
    mountComponent();
  });

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

  const findLink = () => wrapper.find(GlLink);

  describe('empty state', () => {
    beforeEach(() => {
      mountComponent({ propsData: { alert: null } });
    });

    it('renders a empty component', () => {
      expect(wrapper.isVisible()).toBe(false);
    });
  });

  describe('alert present', () => {
    beforeEach(() => {
      mountComponent();
    });

    it('renders a link to the alert page', () => {
      expect(findLink().exists()).toBe(true);
      expect(findLink().attributes('href')).toBe(alert.detailsUrl);
      expect(findLink().attributes('title')).toBe(alert.title);
      expect(findLink().text()).toBe(`#${alert.iid}`);
    });

    it('renders formatted start time of the alert', () => {
      const formattedDate = '2020-05-29 UTC';
      formatDate.mockReturnValueOnce(formattedDate);
      mountComponent();
      expect(formatDate).toHaveBeenCalledWith(alert.startedAt, 'yyyy-mm-dd Z');
      expect(wrapper.text()).toContain(formattedDate);
    });

    it('renders a number of alert events', () => {
      expect(wrapper.text()).toContain(alert.eventCount);
    });
  });

  describe('when child data is present', () => {
    beforeEach(() => {
      mountComponent({
        data() {
          return { hasChildData: true };
        },
      });
    });

    it('renders the highlight bar component', () => {
      expect(wrapper.isVisible()).toBe(true);
    });
  });
});