diff options
Diffstat (limited to 'spec/frontend/monitoring/store/mutations_spec.js')
-rw-r--r-- | spec/frontend/monitoring/store/mutations_spec.js | 154 |
1 files changed, 103 insertions, 51 deletions
diff --git a/spec/frontend/monitoring/store/mutations_spec.js b/spec/frontend/monitoring/store/mutations_spec.js index 0283f1a86a4..14b38d79aa2 100644 --- a/spec/frontend/monitoring/store/mutations_spec.js +++ b/spec/frontend/monitoring/store/mutations_spec.js @@ -3,9 +3,9 @@ import httpStatusCodes from '~/lib/utils/http_status'; import mutations from '~/monitoring/stores/mutations'; import * as types from '~/monitoring/stores/mutation_types'; import state from '~/monitoring/stores/state'; -import { metricStates } from '~/monitoring/constants'; +import { dashboardEmptyStates, metricStates } from '~/monitoring/constants'; -import { deploymentData, dashboardGitResponse } from '../mock_data'; +import { deploymentData, dashboardGitResponse, storeTextVariables } from '../mock_data'; import { metricsDashboardPayload } from '../fixture_data'; describe('Monitoring mutations', () => { @@ -15,6 +15,14 @@ describe('Monitoring mutations', () => { stateCopy = state(); }); + describe('REQUEST_METRICS_DASHBOARD', () => { + it('sets an empty loading state', () => { + mutations[types.REQUEST_METRICS_DASHBOARD](stateCopy); + + expect(stateCopy.emptyState).toBe(dashboardEmptyStates.LOADING); + }); + }); + describe('RECEIVE_METRICS_DASHBOARD_SUCCESS', () => { let payload; const getGroups = () => stateCopy.dashboard.panelGroups; @@ -23,6 +31,18 @@ describe('Monitoring mutations', () => { stateCopy.dashboard.panelGroups = []; payload = metricsDashboardPayload; }); + it('sets an empty noData state when the dashboard is empty', () => { + const emptyDashboardPayload = { + ...payload, + panel_groups: [], + }; + + mutations[types.RECEIVE_METRICS_DASHBOARD_SUCCESS](stateCopy, emptyDashboardPayload); + const groups = getGroups(); + + expect(groups).toEqual([]); + expect(stateCopy.emptyState).toBe(dashboardEmptyStates.NO_DATA); + }); it('adds a key to the group', () => { mutations[types.RECEIVE_METRICS_DASHBOARD_SUCCESS](stateCopy, payload); const groups = getGroups(); @@ -72,6 +92,20 @@ describe('Monitoring mutations', () => { }); }); + describe('RECEIVE_METRICS_DASHBOARD_FAILURE', () => { + it('sets an empty noData state when an empty error occurs', () => { + mutations[types.RECEIVE_METRICS_DASHBOARD_FAILURE](stateCopy); + + expect(stateCopy.emptyState).toBe(dashboardEmptyStates.NO_DATA); + }); + + it('sets an empty unableToConnect state when an error occurs', () => { + mutations[types.RECEIVE_METRICS_DASHBOARD_FAILURE](stateCopy, 'myerror'); + + expect(stateCopy.emptyState).toBe(dashboardEmptyStates.UNABLE_TO_CONNECT); + }); + }); + describe('Dashboard starring mutations', () => { it('REQUEST_DASHBOARD_STARRING', () => { stateCopy = { isUpdatingStarredValue: false }; @@ -225,11 +259,28 @@ describe('Monitoring mutations', () => { describe('Individual panel/metric results', () => { const metricId = 'NO_DB_response_metrics_nginx_ingress_throughput_status_code'; - const result = [ - { - values: [[0, 1], [1, 1], [1, 3]], - }, - ]; + const data = { + resultType: 'matrix', + result: [ + { + metric: { + __name__: 'up', + job: 'prometheus', + instance: 'localhost:9090', + }, + values: [[1435781430.781, '1'], [1435781445.781, '1'], [1435781460.781, '1']], + }, + { + metric: { + __name__: 'up', + job: 'node', + instance: 'localhost:9091', + }, + values: [[1435781430.781, '0'], [1435781445.781, '0'], [1435781460.781, '1']], + }, + ], + }; + const dashboard = metricsDashboardPayload; const getMetric = () => stateCopy.dashboard.panelGroups[1].panels[0].metrics[0]; @@ -238,13 +289,10 @@ describe('Monitoring mutations', () => { mutations[types.RECEIVE_METRICS_DASHBOARD_SUCCESS](stateCopy, dashboard); }); it('stores a loading state on a metric', () => { - expect(stateCopy.showEmptyState).toBe(true); - mutations[types.REQUEST_METRIC_RESULT](stateCopy, { metricId, }); - expect(stateCopy.showEmptyState).toBe(true); expect(getMetric()).toEqual( expect.objectContaining({ loading: true, @@ -257,26 +305,16 @@ describe('Monitoring mutations', () => { beforeEach(() => { mutations[types.RECEIVE_METRICS_DASHBOARD_SUCCESS](stateCopy, dashboard); }); - it('clears empty state', () => { - expect(stateCopy.showEmptyState).toBe(true); - - mutations[types.RECEIVE_METRIC_RESULT_SUCCESS](stateCopy, { - metricId, - result, - }); - - expect(stateCopy.showEmptyState).toBe(false); - }); it('adds results to the store', () => { expect(getMetric().result).toBe(null); mutations[types.RECEIVE_METRIC_RESULT_SUCCESS](stateCopy, { metricId, - result, + data, }); - expect(getMetric().result).toHaveLength(result.length); + expect(getMetric().result).toHaveLength(data.result.length); expect(getMetric()).toEqual( expect.objectContaining({ loading: false, @@ -290,16 +328,6 @@ describe('Monitoring mutations', () => { beforeEach(() => { mutations[types.RECEIVE_METRICS_DASHBOARD_SUCCESS](stateCopy, dashboard); }); - it('maintains the loading state when a metric fails', () => { - expect(stateCopy.showEmptyState).toBe(true); - - mutations[types.RECEIVE_METRIC_RESULT_FAILURE](stateCopy, { - metricId, - error: 'an error', - }); - - expect(stateCopy.showEmptyState).toBe(true); - }); it('stores a timeout error in a metric', () => { mutations[types.RECEIVE_METRIC_RESULT_FAILURE](stateCopy, { @@ -369,6 +397,7 @@ describe('Monitoring mutations', () => { }); }); }); + describe('SET_ALL_DASHBOARDS', () => { it('stores `undefined` dashboards as an empty array', () => { mutations[types.SET_ALL_DASHBOARDS](stateCopy, undefined); @@ -410,30 +439,53 @@ describe('Monitoring mutations', () => { }); }); - describe('SET_VARIABLES', () => { - it('stores an empty variables array when no custom variables are given', () => { - mutations[types.SET_VARIABLES](stateCopy, {}); - - expect(stateCopy.variables).toEqual({}); - }); - - it('stores variables in the key key_value format in the array', () => { - mutations[types.SET_VARIABLES](stateCopy, { pod: 'POD', stage: 'main ops' }); + describe('UPDATE_VARIABLE_VALUE', () => { + it('updates only the value of the variable in variables', () => { + stateCopy.variables = storeTextVariables; + mutations[types.UPDATE_VARIABLE_VALUE](stateCopy, { name: 'textSimple', value: 'New Value' }); - expect(stateCopy.variables).toEqual({ pod: 'POD', stage: 'main ops' }); + expect(stateCopy.variables[0].value).toEqual('New Value'); }); }); - describe('UPDATE_VARIABLES', () => { - afterEach(() => { - mutations[types.SET_VARIABLES](stateCopy, {}); - }); - - it('updates only the value of the variable in variables', () => { - mutations[types.SET_VARIABLES](stateCopy, { environment: { value: 'prod', type: 'text' } }); - mutations[types.UPDATE_VARIABLES](stateCopy, { key: 'environment', value: 'new prod' }); + describe('UPDATE_VARIABLE_METRIC_LABEL_VALUES', () => { + it('updates options in a variable', () => { + const data = [ + { + __name__: 'up', + job: 'prometheus', + env: 'prd', + }, + { + __name__: 'up', + job: 'prometheus', + env: 'stg', + }, + { + __name__: 'up', + job: 'node', + env: 'prod', + }, + { + __name__: 'up', + job: 'node', + env: 'stg', + }, + ]; + + const variable = { + options: {}, + }; + + mutations[types.UPDATE_VARIABLE_METRIC_LABEL_VALUES](stateCopy, { + variable, + label: 'job', + data, + }); - expect(stateCopy.variables).toEqual({ environment: { value: 'new prod', type: 'text' } }); + expect(variable.options).toEqual({ + values: [{ text: 'prometheus', value: 'prometheus' }, { text: 'node', value: 'node' }], + }); }); }); }); |