2019-05-27 18:30:36 -04:00
|
|
|
import mutations from '~/monitoring/stores/mutations';
|
|
|
|
import * as types from '~/monitoring/stores/mutation_types';
|
|
|
|
import state from '~/monitoring/stores/state';
|
2019-06-26 18:14:41 -04:00
|
|
|
import {
|
|
|
|
metricsGroupsAPIResponse,
|
|
|
|
deploymentData,
|
|
|
|
metricsDashboardResponse,
|
|
|
|
dashboardGitResponse,
|
|
|
|
} from '../mock_data';
|
2019-09-20 17:06:18 -04:00
|
|
|
import { uniqMetricsId } from '~/monitoring/stores/utils';
|
2019-05-27 18:30:36 -04:00
|
|
|
|
|
|
|
describe('Monitoring mutations', () => {
|
|
|
|
let stateCopy;
|
|
|
|
beforeEach(() => {
|
|
|
|
stateCopy = state();
|
|
|
|
});
|
2019-11-18 07:06:03 -05:00
|
|
|
describe('RECEIVE_METRICS_DATA_SUCCESS', () => {
|
2019-06-05 18:03:30 -04:00
|
|
|
let groups;
|
2019-05-27 18:30:36 -04:00
|
|
|
beforeEach(() => {
|
2019-11-04 04:06:21 -05:00
|
|
|
stateCopy.dashboard.panel_groups = [];
|
2019-11-13 13:06:51 -05:00
|
|
|
groups = metricsGroupsAPIResponse;
|
2019-05-27 18:30:36 -04:00
|
|
|
});
|
2019-11-04 04:06:21 -05:00
|
|
|
it('adds a key to the group', () => {
|
|
|
|
mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, groups);
|
2019-11-13 13:06:51 -05:00
|
|
|
expect(stateCopy.dashboard.panel_groups[0].key).toBe('system-metrics-kubernetes--0');
|
2019-11-04 04:06:21 -05:00
|
|
|
});
|
2019-05-27 18:30:36 -04:00
|
|
|
it('normalizes values', () => {
|
2019-06-05 18:03:30 -04:00
|
|
|
mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, groups);
|
2019-11-13 13:06:51 -05:00
|
|
|
const expectedLabel = 'Pod average';
|
2019-11-28 10:06:57 -05:00
|
|
|
const { label, query_range } = stateCopy.dashboard.panel_groups[0].panels[0].metrics[0];
|
2019-11-13 13:06:51 -05:00
|
|
|
expect(label).toEqual(expectedLabel);
|
|
|
|
expect(query_range.length).toBeGreaterThan(0);
|
2019-05-27 18:30:36 -04:00
|
|
|
});
|
2019-11-13 13:06:51 -05:00
|
|
|
it('contains one group, which it has two panels and one metrics property', () => {
|
2019-06-05 18:03:30 -04:00
|
|
|
mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, groups);
|
2019-11-04 04:06:21 -05:00
|
|
|
expect(stateCopy.dashboard.panel_groups).toBeDefined();
|
2019-11-13 13:06:51 -05:00
|
|
|
expect(stateCopy.dashboard.panel_groups.length).toEqual(1);
|
|
|
|
expect(stateCopy.dashboard.panel_groups[0].panels.length).toEqual(2);
|
|
|
|
expect(stateCopy.dashboard.panel_groups[0].panels[0].metrics.length).toEqual(1);
|
|
|
|
expect(stateCopy.dashboard.panel_groups[0].panels[1].metrics.length).toEqual(1);
|
2019-05-27 18:30:36 -04:00
|
|
|
});
|
2019-11-28 10:06:57 -05:00
|
|
|
it('assigns metrics a metric id', () => {
|
2019-06-05 18:03:30 -04:00
|
|
|
mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, groups);
|
2019-11-28 10:06:57 -05:00
|
|
|
expect(stateCopy.dashboard.panel_groups[0].panels[0].metrics[0].metricId).toEqual(
|
2019-11-13 13:06:51 -05:00
|
|
|
'17_system_metrics_kubernetes_container_memory_average',
|
|
|
|
);
|
2019-05-27 18:30:36 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-11-18 07:06:03 -05:00
|
|
|
describe('RECEIVE_DEPLOYMENTS_DATA_SUCCESS', () => {
|
2019-05-27 18:30:36 -04:00
|
|
|
it('stores the deployment data', () => {
|
|
|
|
stateCopy.deploymentData = [];
|
|
|
|
mutations[types.RECEIVE_DEPLOYMENTS_DATA_SUCCESS](stateCopy, deploymentData);
|
|
|
|
expect(stateCopy.deploymentData).toBeDefined();
|
|
|
|
expect(stateCopy.deploymentData.length).toEqual(3);
|
|
|
|
expect(typeof stateCopy.deploymentData[0]).toEqual('object');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('SET_ENDPOINTS', () => {
|
|
|
|
it('should set all the endpoints', () => {
|
|
|
|
mutations[types.SET_ENDPOINTS](stateCopy, {
|
|
|
|
metricsEndpoint: 'additional_metrics.json',
|
|
|
|
environmentsEndpoint: 'environments.json',
|
|
|
|
deploymentsEndpoint: 'deployments.json',
|
2019-06-05 18:03:30 -04:00
|
|
|
dashboardEndpoint: 'dashboard.json',
|
2019-09-18 10:02:45 -04:00
|
|
|
projectPath: '/gitlab-org/gitlab-foss',
|
2019-05-27 18:30:36 -04:00
|
|
|
});
|
|
|
|
expect(stateCopy.metricsEndpoint).toEqual('additional_metrics.json');
|
|
|
|
expect(stateCopy.environmentsEndpoint).toEqual('environments.json');
|
|
|
|
expect(stateCopy.deploymentsEndpoint).toEqual('deployments.json');
|
2019-06-05 18:03:30 -04:00
|
|
|
expect(stateCopy.dashboardEndpoint).toEqual('dashboard.json');
|
2019-09-18 10:02:45 -04:00
|
|
|
expect(stateCopy.projectPath).toEqual('/gitlab-org/gitlab-foss');
|
2019-05-27 18:30:36 -04:00
|
|
|
});
|
|
|
|
});
|
2019-06-05 18:03:30 -04:00
|
|
|
describe('SET_QUERY_RESULT', () => {
|
|
|
|
const metricId = 12;
|
2019-09-20 17:06:18 -04:00
|
|
|
const id = 'system_metrics_kubernetes_container_memory_total';
|
2019-11-18 07:06:03 -05:00
|
|
|
const result = [
|
|
|
|
{
|
|
|
|
values: [[0, 1], [1, 1], [1, 3]],
|
|
|
|
},
|
|
|
|
];
|
2019-06-05 18:03:30 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
const dashboardGroups = metricsDashboardResponse.dashboard.panel_groups;
|
|
|
|
mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, dashboardGroups);
|
|
|
|
});
|
|
|
|
it('clears empty state', () => {
|
|
|
|
mutations[types.SET_QUERY_RESULT](stateCopy, {
|
|
|
|
metricId,
|
|
|
|
result,
|
|
|
|
});
|
|
|
|
expect(stateCopy.showEmptyState).toBe(false);
|
|
|
|
});
|
|
|
|
it('sets metricsWithData value', () => {
|
2019-11-18 07:06:03 -05:00
|
|
|
const uniqId = uniqMetricsId({
|
|
|
|
metric_id: metricId,
|
|
|
|
id,
|
|
|
|
});
|
2019-06-05 18:03:30 -04:00
|
|
|
mutations[types.SET_QUERY_RESULT](stateCopy, {
|
2019-09-20 17:06:18 -04:00
|
|
|
metricId: uniqId,
|
2019-06-05 18:03:30 -04:00
|
|
|
result,
|
|
|
|
});
|
2019-09-20 17:06:18 -04:00
|
|
|
expect(stateCopy.metricsWithData).toEqual([uniqId]);
|
2019-06-05 18:03:30 -04:00
|
|
|
});
|
|
|
|
it('does not store empty results', () => {
|
|
|
|
mutations[types.SET_QUERY_RESULT](stateCopy, {
|
|
|
|
metricId,
|
|
|
|
result: [],
|
|
|
|
});
|
|
|
|
expect(stateCopy.metricsWithData).toEqual([]);
|
|
|
|
});
|
|
|
|
});
|
2019-06-26 18:14:41 -04:00
|
|
|
describe('SET_ALL_DASHBOARDS', () => {
|
2019-11-15 07:06:12 -05:00
|
|
|
it('stores `undefined` dashboards as an empty array', () => {
|
|
|
|
mutations[types.SET_ALL_DASHBOARDS](stateCopy, undefined);
|
|
|
|
|
|
|
|
expect(stateCopy.allDashboards).toEqual([]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('stores `null` dashboards as an empty array', () => {
|
|
|
|
mutations[types.SET_ALL_DASHBOARDS](stateCopy, null);
|
|
|
|
|
|
|
|
expect(stateCopy.allDashboards).toEqual([]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('stores dashboards loaded from the git repository', () => {
|
2019-06-26 18:14:41 -04:00
|
|
|
mutations[types.SET_ALL_DASHBOARDS](stateCopy, dashboardGitResponse);
|
|
|
|
expect(stateCopy.allDashboards).toEqual(dashboardGitResponse);
|
|
|
|
});
|
|
|
|
});
|
2019-05-27 18:30:36 -04:00
|
|
|
});
|