debian-mirror-gitlab/spec/frontend/prometheus_metrics/custom_metrics_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

124 lines
5.3 KiB
JavaScript
Raw Normal View History

2020-04-22 19:07:51 +05:30
import MockAdapter from 'axios-mock-adapter';
2022-07-16 23:28:13 +05:30
import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
2020-04-22 19:07:51 +05:30
import axios from '~/lib/utils/axios_utils';
import PANEL_STATE from '~/prometheus_metrics/constants';
2021-03-11 19:13:27 +05:30
import CustomMetrics from '~/prometheus_metrics/custom_metrics';
2020-05-24 23:13:21 +05:30
import { metrics1 as metrics } from './mock_data';
2020-04-22 19:07:51 +05:30
describe('PrometheusMetrics', () => {
2022-07-23 23:45:48 +05:30
const FIXTURE = 'integrations/prometheus/prometheus_integration.html';
2020-04-22 19:07:51 +05:30
const customMetricsEndpoint =
2022-07-23 23:45:48 +05:30
'http://test.host/frontend-fixtures/integrations-project/prometheus/metrics';
2020-04-22 19:07:51 +05:30
let mock;
beforeEach(() => {
mock = new MockAdapter(axios);
mock.onGet(customMetricsEndpoint).reply(200, {
metrics,
});
2022-07-16 23:28:13 +05:30
loadHTMLFixture(FIXTURE);
2020-04-22 19:07:51 +05:30
});
afterEach(() => {
mock.restore();
2022-07-16 23:28:13 +05:30
resetHTMLFixture();
2020-04-22 19:07:51 +05:30
});
describe('Custom Metrics', () => {
let customMetrics;
beforeEach(() => {
customMetrics = new CustomMetrics('.js-prometheus-metrics-monitoring');
});
it('should initialize wrapper element refs on the class object', () => {
expect(customMetrics.$wrapperCustomMetrics).not.toBeNull();
expect(customMetrics.$monitoredCustomMetricsPanel).not.toBeNull();
expect(customMetrics.$monitoredCustomMetricsCount).not.toBeNull();
expect(customMetrics.$monitoredCustomMetricsLoading).not.toBeNull();
expect(customMetrics.$monitoredCustomMetricsEmpty).not.toBeNull();
expect(customMetrics.$monitoredCustomMetricsList).not.toBeNull();
expect(customMetrics.$newCustomMetricButton).not.toBeNull();
expect(customMetrics.$flashCustomMetricsContainer).not.toBeNull();
});
it('should contain api endpoints', () => {
expect(customMetrics.activeCustomMetricsEndpoint).toEqual(customMetricsEndpoint);
});
it('should show loading state when called with `loading`', () => {
customMetrics.showMonitoringCustomMetricsPanelState(PANEL_STATE.LOADING);
expect(customMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toEqual(false);
expect(customMetrics.$monitoredCustomMetricsEmpty.hasClass('hidden')).toBeTruthy();
expect(customMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toBeTruthy();
expect(
customMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden'),
).toBeTruthy();
expect(customMetrics.$newCustomMetricButton.hasClass('hidden')).toBeTruthy();
expect(customMetrics.$newCustomMetricText.hasClass('hidden')).toBeTruthy();
});
it('should show metrics list when called with `list`', () => {
customMetrics.showMonitoringCustomMetricsPanelState(PANEL_STATE.LIST);
expect(customMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toBeTruthy();
expect(customMetrics.$monitoredCustomMetricsEmpty.hasClass('hidden')).toBeTruthy();
expect(customMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toEqual(false);
expect(
customMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden'),
).toBeTruthy();
expect(customMetrics.$newCustomMetricButton.hasClass('hidden')).toEqual(false);
expect(customMetrics.$newCustomMetricText.hasClass('hidden')).toBeTruthy();
});
it('should show empty state when called with `empty`', () => {
customMetrics.showMonitoringCustomMetricsPanelState(PANEL_STATE.EMPTY);
expect(customMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toBeTruthy();
expect(customMetrics.$monitoredCustomMetricsEmpty.hasClass('hidden')).toEqual(false);
expect(customMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toBeTruthy();
expect(
customMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden'),
).toBeTruthy();
expect(customMetrics.$newCustomMetricButton.hasClass('hidden')).toEqual(false);
expect(customMetrics.$newCustomMetricText.hasClass('hidden')).toEqual(false);
});
it('should show monitored metrics list', () => {
customMetrics.customMetrics = metrics;
customMetrics.populateCustomMetrics();
const $metricsListLi = customMetrics.$monitoredCustomMetricsList.find('li');
expect(customMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toBeTruthy();
expect(customMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toEqual(false);
expect(
customMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden'),
).toBeTruthy();
expect(customMetrics.$newCustomMetricButton.hasClass('hidden')).toEqual(false);
expect(customMetrics.$newCustomMetricText.hasClass('hidden')).toBeTruthy();
expect($metricsListLi.length).toEqual(metrics.length);
});
it('should show the NO-INTEGRATION empty state', () => {
customMetrics.setNoIntegrationActiveState();
expect(customMetrics.$monitoredCustomMetricsEmpty.hasClass('hidden')).toEqual(false);
expect(customMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden')).toEqual(
false,
);
expect(customMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toBeTruthy();
expect(customMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toBeTruthy();
expect(customMetrics.$newCustomMetricButton.hasClass('hidden')).toBeTruthy();
expect(customMetrics.$newCustomMetricText.hasClass('hidden')).toBeTruthy();
});
});
});