2020-04-10 11:09:50 -04:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2022-05-13 08:08:49 -04:00
|
|
|
import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
2020-04-10 11:09:50 -04:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import PANEL_STATE from '~/prometheus_metrics/constants';
|
2021-02-14 13:09:20 -05:00
|
|
|
import CustomMetrics from '~/prometheus_metrics/custom_metrics';
|
2020-05-19 20:08:20 -04:00
|
|
|
import { metrics1 as metrics } from './mock_data';
|
2020-04-10 11:09:50 -04:00
|
|
|
|
|
|
|
describe('PrometheusMetrics', () => {
|
2022-05-25 14:08:15 -04:00
|
|
|
const FIXTURE = 'integrations/prometheus/prometheus_integration.html';
|
2020-04-10 11:09:50 -04:00
|
|
|
const customMetricsEndpoint =
|
2022-05-25 14:08:15 -04:00
|
|
|
'http://test.host/frontend-fixtures/integrations-project/prometheus/metrics';
|
2020-04-10 11:09:50 -04:00
|
|
|
let mock;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
mock.onGet(customMetricsEndpoint).reply(200, {
|
|
|
|
metrics,
|
|
|
|
});
|
2022-05-13 08:08:49 -04:00
|
|
|
loadHTMLFixture(FIXTURE);
|
2020-04-10 11:09:50 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
2022-05-13 08:08:49 -04:00
|
|
|
resetHTMLFixture();
|
2020-04-10 11:09:50 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Custom Metrics', () => {
|
2020-04-13 05:09:51 -04:00
|
|
|
let customMetrics;
|
2020-04-10 11:09:50 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-04-13 05:09:51 -04:00
|
|
|
customMetrics = new CustomMetrics('.js-prometheus-metrics-monitoring');
|
2020-04-10 11:09:50 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should initialize wrapper element refs on the class object', () => {
|
2020-04-13 05:09:51 -04:00
|
|
|
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();
|
2020-04-10 11:09:50 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should contain api endpoints', () => {
|
2020-04-13 05:09:51 -04:00
|
|
|
expect(customMetrics.activeCustomMetricsEndpoint).toEqual(customMetricsEndpoint);
|
2020-04-10 11:09:50 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should show loading state when called with `loading`', () => {
|
2020-04-13 05:09:51 -04:00
|
|
|
customMetrics.showMonitoringCustomMetricsPanelState(PANEL_STATE.LOADING);
|
2020-04-10 11:09:50 -04:00
|
|
|
|
2020-04-13 05:09:51 -04:00
|
|
|
expect(customMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toEqual(false);
|
2022-08-12 11:11:42 -04:00
|
|
|
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-10 11:09:50 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should show metrics list when called with `list`', () => {
|
2020-04-13 05:09:51 -04:00
|
|
|
customMetrics.showMonitoringCustomMetricsPanelState(PANEL_STATE.LIST);
|
2020-04-10 11:09:50 -04:00
|
|
|
|
2022-08-12 11:11:42 -04:00
|
|
|
expect(customMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toBe(true);
|
|
|
|
expect(customMetrics.$monitoredCustomMetricsEmpty.hasClass('hidden')).toBe(true);
|
2020-04-13 05:09:51 -04:00
|
|
|
expect(customMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toEqual(false);
|
2022-08-12 11:11:42 -04:00
|
|
|
expect(customMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden')).toBe(true);
|
2020-04-10 11:09:50 -04:00
|
|
|
|
2020-04-13 05:09:51 -04:00
|
|
|
expect(customMetrics.$newCustomMetricButton.hasClass('hidden')).toEqual(false);
|
2022-08-12 11:11:42 -04:00
|
|
|
expect(customMetrics.$newCustomMetricText.hasClass('hidden')).toBe(true);
|
2020-04-10 11:09:50 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should show empty state when called with `empty`', () => {
|
2020-04-13 05:09:51 -04:00
|
|
|
customMetrics.showMonitoringCustomMetricsPanelState(PANEL_STATE.EMPTY);
|
2020-04-10 11:09:50 -04:00
|
|
|
|
2022-08-12 11:11:42 -04:00
|
|
|
expect(customMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toBe(true);
|
2020-04-13 05:09:51 -04:00
|
|
|
expect(customMetrics.$monitoredCustomMetricsEmpty.hasClass('hidden')).toEqual(false);
|
2022-08-12 11:11:42 -04:00
|
|
|
expect(customMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toBe(true);
|
|
|
|
expect(customMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden')).toBe(true);
|
2020-04-10 11:09:50 -04:00
|
|
|
|
2020-04-13 05:09:51 -04:00
|
|
|
expect(customMetrics.$newCustomMetricButton.hasClass('hidden')).toEqual(false);
|
|
|
|
expect(customMetrics.$newCustomMetricText.hasClass('hidden')).toEqual(false);
|
2020-04-10 11:09:50 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should show monitored metrics list', () => {
|
2020-04-13 05:09:51 -04:00
|
|
|
customMetrics.customMetrics = metrics;
|
|
|
|
customMetrics.populateCustomMetrics();
|
2020-04-10 11:09:50 -04:00
|
|
|
|
2020-04-13 05:09:51 -04:00
|
|
|
const $metricsListLi = customMetrics.$monitoredCustomMetricsList.find('li');
|
2020-04-10 11:09:50 -04:00
|
|
|
|
2022-08-12 11:11:42 -04:00
|
|
|
expect(customMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toBe(true);
|
2020-04-13 05:09:51 -04:00
|
|
|
expect(customMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toEqual(false);
|
2022-08-12 11:11:42 -04:00
|
|
|
expect(customMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden')).toBe(true);
|
2020-04-10 11:09:50 -04:00
|
|
|
|
2020-04-13 05:09:51 -04:00
|
|
|
expect(customMetrics.$newCustomMetricButton.hasClass('hidden')).toEqual(false);
|
2022-08-12 11:11:42 -04:00
|
|
|
expect(customMetrics.$newCustomMetricText.hasClass('hidden')).toBe(true);
|
2020-04-10 11:09:50 -04:00
|
|
|
|
|
|
|
expect($metricsListLi.length).toEqual(metrics.length);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show the NO-INTEGRATION empty state', () => {
|
2020-04-13 05:09:51 -04:00
|
|
|
customMetrics.setNoIntegrationActiveState();
|
2020-04-10 11:09:50 -04:00
|
|
|
|
2020-04-13 05:09:51 -04:00
|
|
|
expect(customMetrics.$monitoredCustomMetricsEmpty.hasClass('hidden')).toEqual(false);
|
|
|
|
expect(customMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden')).toEqual(
|
2020-04-10 11:09:50 -04:00
|
|
|
false,
|
|
|
|
);
|
|
|
|
|
2022-08-12 11:11:42 -04:00
|
|
|
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-10 11:09:50 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|