Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/monitoring/store/mutations_spec.js')
-rw-r--r--spec/frontend/monitoring/store/mutations_spec.js83
1 files changed, 49 insertions, 34 deletions
diff --git a/spec/frontend/monitoring/store/mutations_spec.js b/spec/frontend/monitoring/store/mutations_spec.js
index 42031e01878..47177180aa1 100644
--- a/spec/frontend/monitoring/store/mutations_spec.js
+++ b/spec/frontend/monitoring/store/mutations_spec.js
@@ -7,41 +7,59 @@ import {
metricsDashboardResponse,
dashboardGitResponse,
} from '../mock_data';
-import { uniqMetricsId } from '~/monitoring/stores/utils';
describe('Monitoring mutations', () => {
let stateCopy;
+
beforeEach(() => {
stateCopy = state();
});
describe('RECEIVE_METRICS_DATA_SUCCESS', () => {
- let groups;
+ let payload;
+ const getGroups = () => stateCopy.dashboard.panel_groups;
+
beforeEach(() => {
stateCopy.dashboard.panel_groups = [];
- groups = metricsGroupsAPIResponse;
+ payload = metricsGroupsAPIResponse;
});
it('adds a key to the group', () => {
- mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, groups);
- expect(stateCopy.dashboard.panel_groups[0].key).toBe('system-metrics-kubernetes--0');
+ mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, payload);
+ const groups = getGroups();
+
+ expect(groups[0].key).toBe('response-metrics-nginx-ingress-vts--0');
+ expect(groups[1].key).toBe('system-metrics-kubernetes--1');
});
it('normalizes values', () => {
- mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, groups);
+ mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, payload);
const expectedLabel = 'Pod average';
- const { label, query_range } = stateCopy.dashboard.panel_groups[0].panels[0].metrics[0];
+ const { label, query_range } = getGroups()[1].panels[0].metrics[0];
expect(label).toEqual(expectedLabel);
expect(query_range.length).toBeGreaterThan(0);
});
- it('contains one group, which it has two panels and one metrics property', () => {
- mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, groups);
- expect(stateCopy.dashboard.panel_groups).toBeDefined();
- 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);
+ it('contains two groups, with panels with a metric each', () => {
+ mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, payload);
+
+ const groups = getGroups();
+
+ expect(groups).toBeDefined();
+ expect(groups).toHaveLength(2);
+
+ expect(groups[0].panels).toHaveLength(1);
+ expect(groups[0].panels[0].metrics).toHaveLength(1);
+
+ expect(groups[1].panels).toHaveLength(2);
+ expect(groups[1].panels[0].metrics).toHaveLength(1);
+ expect(groups[1].panels[1].metrics).toHaveLength(1);
});
it('assigns metrics a metric id', () => {
- mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, groups);
- expect(stateCopy.dashboard.panel_groups[0].panels[0].metrics[0].metricId).toEqual(
+ mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, payload);
+
+ const groups = getGroups();
+
+ expect(groups[0].panels[0].metrics[0].metricId).toEqual(
+ '1_response_metrics_nginx_ingress_throughput_status_code',
+ );
+ expect(groups[1].panels[0].metrics[0].metricId).toEqual(
'17_system_metrics_kubernetes_container_memory_average',
);
});
@@ -52,7 +70,7 @@ describe('Monitoring mutations', () => {
stateCopy.deploymentData = [];
mutations[types.RECEIVE_DEPLOYMENTS_DATA_SUCCESS](stateCopy, deploymentData);
expect(stateCopy.deploymentData).toBeDefined();
- expect(stateCopy.deploymentData.length).toEqual(3);
+ expect(stateCopy.deploymentData).toHaveLength(3);
expect(typeof stateCopy.deploymentData[0]).toEqual('object');
});
});
@@ -73,41 +91,38 @@ describe('Monitoring mutations', () => {
});
});
describe('SET_QUERY_RESULT', () => {
- const metricId = 12;
- const id = 'system_metrics_kubernetes_container_memory_total';
+ const metricId = '12_system_metrics_kubernetes_container_memory_total';
const result = [
{
values: [[0, 1], [1, 1], [1, 3]],
},
];
+ const dashboardGroups = metricsDashboardResponse.dashboard.panel_groups;
+ const getMetrics = () => stateCopy.dashboard.panel_groups[0].panels[0].metrics;
+
beforeEach(() => {
- const dashboardGroups = metricsDashboardResponse.dashboard.panel_groups;
mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, dashboardGroups);
});
it('clears empty state', () => {
+ expect(stateCopy.showEmptyState).toBe(true);
+
mutations[types.SET_QUERY_RESULT](stateCopy, {
metricId,
result,
});
+
expect(stateCopy.showEmptyState).toBe(false);
});
- it('sets metricsWithData value', () => {
- const uniqId = uniqMetricsId({
- metric_id: metricId,
- id,
- });
- mutations[types.SET_QUERY_RESULT](stateCopy, {
- metricId: uniqId,
- result,
- });
- expect(stateCopy.metricsWithData).toEqual([uniqId]);
- });
- it('does not store empty results', () => {
+
+ it('adds results to the store', () => {
+ expect(getMetrics()[0].result).toBe(undefined);
+
mutations[types.SET_QUERY_RESULT](stateCopy, {
metricId,
- result: [],
+ result,
});
- expect(stateCopy.metricsWithData).toEqual([]);
+
+ expect(getMetrics()[0].result).toHaveLength(result.length);
});
});
describe('SET_ALL_DASHBOARDS', () => {