summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_shared/alert_details/alert_metrics_spec.js
blob: c75909651d7984cdbb068cfda369b753168eb347 (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
import { shallowMount } from '@vue/test-utils';
import MockAdapter from 'axios-mock-adapter';
import axios from 'axios';
import waitForPromises from 'helpers/wait_for_promises';
import AlertMetrics from '~/vue_shared/alert_details/components/alert_metrics.vue';
import MetricEmbed from '~/monitoring/components/embeds/metric_embed.vue';

jest.mock('~/monitoring/stores', () => ({
  monitoringDashboard: {},
}));

jest.mock('~/monitoring/components/embeds/metric_embed.vue', () => ({
  render(h) {
    return h('div');
  },
}));

describe('Alert Metrics', () => {
  let wrapper;
  const mock = new MockAdapter(axios);

  function mountComponent({ props } = {}) {
    wrapper = shallowMount(AlertMetrics, {
      propsData: {
        ...props,
      },
    });
  }

  const findChart = () => wrapper.find(MetricEmbed);
  const findEmptyState = () => wrapper.find({ ref: 'emptyState' });

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

  afterAll(() => {
    mock.restore();
  });

  describe('Empty state', () => {
    it('should display a message when metrics dashboard url is not provided ', () => {
      mountComponent();
      expect(findChart().exists()).toBe(false);
      expect(findEmptyState().text()).toBe("Metrics weren't available in the alerts payload.");
    });
  });

  describe('Chart', () => {
    it('should be rendered when dashboard url is provided', async () => {
      mountComponent({ props: { dashboardUrl: 'metrics.url' } });

      await waitForPromises();
      await wrapper.vm.$nextTick();

      expect(findEmptyState().exists()).toBe(false);
      expect(findChart().exists()).toBe(true);
    });
  });
});