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';
|
2023-04-23 21:23:45 +05:30
|
|
|
import { HTTP_STATUS_OK } from '~/lib/utils/http_status';
|
2020-04-22 19:07:51 +05:30
|
|
|
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);
|
2023-04-23 21:23:45 +05:30
|
|
|
mock.onGet(customMetricsEndpoint).reply(HTTP_STATUS_OK, {
|
2020-04-22 19:07:51 +05:30
|
|
|
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);
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(customMetrics.$monitoredCustomMetricsEmpty.hasClass('hidden')).toBe(true);
|
|
|
|
expect(customMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toBe(true);
|
|
|
|
expect(customMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden')).toBe(true);
|
|
|
|
|
|
|
|
expect(customMetrics.$newCustomMetricButton.hasClass('hidden')).toBe(true);
|
|
|
|
expect(customMetrics.$newCustomMetricText.hasClass('hidden')).toBe(true);
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should show metrics list when called with `list`', () => {
|
|
|
|
customMetrics.showMonitoringCustomMetricsPanelState(PANEL_STATE.LIST);
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(customMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toBe(true);
|
|
|
|
expect(customMetrics.$monitoredCustomMetricsEmpty.hasClass('hidden')).toBe(true);
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(customMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toEqual(false);
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(customMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden')).toBe(true);
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
expect(customMetrics.$newCustomMetricButton.hasClass('hidden')).toEqual(false);
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(customMetrics.$newCustomMetricText.hasClass('hidden')).toBe(true);
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should show empty state when called with `empty`', () => {
|
|
|
|
customMetrics.showMonitoringCustomMetricsPanelState(PANEL_STATE.EMPTY);
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(customMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toBe(true);
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(customMetrics.$monitoredCustomMetricsEmpty.hasClass('hidden')).toEqual(false);
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(customMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toBe(true);
|
|
|
|
expect(customMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden')).toBe(true);
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
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');
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(customMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toBe(true);
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(customMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toEqual(false);
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(customMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden')).toBe(true);
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
expect(customMetrics.$newCustomMetricButton.hasClass('hidden')).toEqual(false);
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(customMetrics.$newCustomMetricText.hasClass('hidden')).toBe(true);
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
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,
|
|
|
|
);
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(customMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toBe(true);
|
|
|
|
expect(customMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toBe(true);
|
|
|
|
expect(customMetrics.$newCustomMetricButton.hasClass('hidden')).toBe(true);
|
|
|
|
expect(customMetrics.$newCustomMetricText.hasClass('hidden')).toBe(true);
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|