Commit 3a0b5f4d authored by Illya Klymov's avatar Illya Klymov

Merge branch 'himkp-jest-prometheus-metrics' into 'master'

Migrate spec/javascripts/prometheus_metrics/ to Jest

Closes #194252

See merge request gitlab-org/gitlab!32509
parents c88627bb 866a0673
......@@ -2,7 +2,7 @@ import MockAdapter from 'axios-mock-adapter';
import CustomMetrics from '~/prometheus_metrics/custom_metrics';
import axios from '~/lib/utils/axios_utils';
import PANEL_STATE from '~/prometheus_metrics/constants';
import metrics from './mock_data';
import { metrics1 as metrics } from './mock_data';
describe('PrometheusMetrics', () => {
const FIXTURE = 'services/prometheus/prometheus_service.html';
......
const metrics = [
export const metrics1 = [
{
edit_path: '/root/prometheus-test/prometheus/metrics/3/edit',
id: 3,
......@@ -19,4 +19,44 @@ const metrics = [
},
];
export default metrics;
export const metrics2 = [
{
group: 'Kubernetes',
priority: 1,
active_metrics: 4,
metrics_missing_requirements: 0,
},
{
group: 'HAProxy',
priority: 2,
active_metrics: 3,
metrics_missing_requirements: 0,
},
{
group: 'Apache',
priority: 3,
active_metrics: 5,
metrics_missing_requirements: 0,
},
];
export const missingVarMetrics = [
{
group: 'Kubernetes',
priority: 1,
active_metrics: 4,
metrics_missing_requirements: 0,
},
{
group: 'HAProxy',
priority: 2,
active_metrics: 3,
metrics_missing_requirements: 1,
},
{
group: 'Apache',
priority: 3,
active_metrics: 5,
metrics_missing_requirements: 3,
},
];
......@@ -2,7 +2,7 @@ import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import PrometheusMetrics from '~/prometheus_metrics/prometheus_metrics';
import PANEL_STATE from '~/prometheus_metrics/constants';
import { metrics, missingVarMetrics } from './mock_data';
import { metrics2 as metrics, missingVarMetrics } from './mock_data';
describe('PrometheusMetrics', () => {
const FIXTURE = 'services/prometheus/prometheus_service.html';
......@@ -126,7 +126,7 @@ describe('PrometheusMetrics', () => {
}
beforeEach(() => {
spyOn(axios, 'get').and.callThrough();
jest.spyOn(axios, 'get');
prometheusMetrics = new PrometheusMetrics('.js-prometheus-metrics-monitoring');
......@@ -145,7 +145,7 @@ describe('PrometheusMetrics', () => {
expect(prometheusMetrics.$monitoredMetricsLoading.hasClass('hidden')).toBeFalsy();
expect(axios.get).toHaveBeenCalledWith(prometheusMetrics.activeMetricsEndpoint);
setTimeout(() => {
setImmediate(() => {
expect(prometheusMetrics.$monitoredMetricsLoading.hasClass('hidden')).toBeTruthy();
done();
});
......@@ -156,7 +156,7 @@ describe('PrometheusMetrics', () => {
prometheusMetrics.loadActiveMetrics();
setTimeout(() => {
setImmediate(() => {
expect(prometheusMetrics.$monitoredMetricsLoading.hasClass('hidden')).toBeTruthy();
expect(prometheusMetrics.$monitoredMetricsEmpty.hasClass('hidden')).toBeFalsy();
done();
......@@ -164,12 +164,12 @@ describe('PrometheusMetrics', () => {
});
it('should populate metrics list once response is loaded', done => {
spyOn(prometheusMetrics, 'populateActiveMetrics');
jest.spyOn(prometheusMetrics, 'populateActiveMetrics').mockImplementation();
mockSuccess();
prometheusMetrics.loadActiveMetrics();
setTimeout(() => {
setImmediate(() => {
expect(prometheusMetrics.populateActiveMetrics).toHaveBeenCalledWith(metrics);
done();
});
......
export const metrics = [
{
group: 'Kubernetes',
priority: 1,
active_metrics: 4,
metrics_missing_requirements: 0,
},
{
group: 'HAProxy',
priority: 2,
active_metrics: 3,
metrics_missing_requirements: 0,
},
{
group: 'Apache',
priority: 3,
active_metrics: 5,
metrics_missing_requirements: 0,
},
];
export const missingVarMetrics = [
{
group: 'Kubernetes',
priority: 1,
active_metrics: 4,
metrics_missing_requirements: 0,
},
{
group: 'HAProxy',
priority: 2,
active_metrics: 3,
metrics_missing_requirements: 1,
},
{
group: 'Apache',
priority: 3,
active_metrics: 5,
metrics_missing_requirements: 3,
},
];
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment