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/getters_spec.js')
-rw-r--r--spec/frontend/monitoring/store/getters_spec.js99
1 files changed, 99 insertions, 0 deletions
diff --git a/spec/frontend/monitoring/store/getters_spec.js b/spec/frontend/monitoring/store/getters_spec.js
new file mode 100644
index 00000000000..066f927dce7
--- /dev/null
+++ b/spec/frontend/monitoring/store/getters_spec.js
@@ -0,0 +1,99 @@
+import * as getters from '~/monitoring/stores/getters';
+
+import mutations from '~/monitoring/stores/mutations';
+import * as types from '~/monitoring/stores/mutation_types';
+import {
+ metricsGroupsAPIResponse,
+ mockedEmptyResult,
+ mockedQueryResultPayload,
+ mockedQueryResultPayloadCoresTotal,
+} from '../mock_data';
+
+describe('Monitoring store Getters', () => {
+ describe('metricsWithData', () => {
+ let metricsWithData;
+ let setupState;
+ let state;
+
+ beforeEach(() => {
+ setupState = (initState = {}) => {
+ state = initState;
+ metricsWithData = getters.metricsWithData(state);
+ };
+ });
+
+ afterEach(() => {
+ state = null;
+ });
+
+ it('has method-style access', () => {
+ setupState();
+
+ expect(metricsWithData).toEqual(expect.any(Function));
+ });
+
+ it('when dashboard has no panel groups, returns empty', () => {
+ setupState({
+ dashboard: {
+ panel_groups: [],
+ },
+ });
+
+ expect(metricsWithData()).toEqual([]);
+ });
+
+ describe('when the dashboard is set', () => {
+ beforeEach(() => {
+ setupState({
+ dashboard: { panel_groups: [] },
+ });
+ });
+
+ it('no loaded metric returns empty', () => {
+ mutations[types.RECEIVE_METRICS_DATA_SUCCESS](state, metricsGroupsAPIResponse);
+
+ expect(metricsWithData()).toEqual([]);
+ });
+
+ it('an empty metric, returns empty', () => {
+ mutations[types.RECEIVE_METRICS_DATA_SUCCESS](state, metricsGroupsAPIResponse);
+ mutations[types.SET_QUERY_RESULT](state, mockedEmptyResult);
+
+ expect(metricsWithData()).toEqual([]);
+ });
+
+ it('a metric with results, it returns a metric', () => {
+ mutations[types.RECEIVE_METRICS_DATA_SUCCESS](state, metricsGroupsAPIResponse);
+ mutations[types.SET_QUERY_RESULT](state, mockedQueryResultPayload);
+
+ expect(metricsWithData()).toEqual([mockedQueryResultPayload.metricId]);
+ });
+
+ it('multiple metrics with results, it return multiple metrics', () => {
+ mutations[types.RECEIVE_METRICS_DATA_SUCCESS](state, metricsGroupsAPIResponse);
+ mutations[types.SET_QUERY_RESULT](state, mockedQueryResultPayload);
+ mutations[types.SET_QUERY_RESULT](state, mockedQueryResultPayloadCoresTotal);
+
+ expect(metricsWithData()).toEqual([
+ mockedQueryResultPayload.metricId,
+ mockedQueryResultPayloadCoresTotal.metricId,
+ ]);
+ });
+
+ it('multiple metrics with results, it returns metrics filtered by group', () => {
+ mutations[types.RECEIVE_METRICS_DATA_SUCCESS](state, metricsGroupsAPIResponse);
+ mutations[types.SET_QUERY_RESULT](state, mockedQueryResultPayload);
+ mutations[types.SET_QUERY_RESULT](state, mockedQueryResultPayloadCoresTotal);
+
+ // First group has no metrics
+ expect(metricsWithData(state.dashboard.panel_groups[0].key)).toEqual([]);
+
+ // Second group has metrics
+ expect(metricsWithData(state.dashboard.panel_groups[1].key)).toEqual([
+ mockedQueryResultPayload.metricId,
+ mockedQueryResultPayloadCoresTotal.metricId,
+ ]);
+ });
+ });
+ });
+});