summaryrefslogtreecommitdiff
path: root/spec/frontend/monitoring/store_utils.js
blob: d764a79ccc300ef5c6f5e3ec35536ef41241dde5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import * as types from '~/monitoring/stores/mutation_types';
import { metricsResult, environmentData } from './mock_data';
import { metricsDashboardPayload } from './fixture_data';

export const setMetricResult = ({ $store, result, group = 0, panel = 0, metric = 0 }) => {
  const { dashboard } = $store.state.monitoringDashboard;
  const { metricId } = dashboard.panelGroups[group].panels[panel].metrics[metric];

  $store.commit(`monitoringDashboard/${types.RECEIVE_METRIC_RESULT_SUCCESS}`, {
    metricId,
    result,
  });
};

const setEnvironmentData = $store => {
  $store.commit(`monitoringDashboard/${types.RECEIVE_ENVIRONMENTS_DATA_SUCCESS}`, environmentData);
};

export const setupStoreWithDashboard = $store => {
  $store.commit(
    `monitoringDashboard/${types.RECEIVE_METRICS_DASHBOARD_SUCCESS}`,
    metricsDashboardPayload,
  );
};

export const setupStoreWithData = $store => {
  setupStoreWithDashboard($store);

  setMetricResult({ $store, result: [], panel: 0 });
  setMetricResult({ $store, result: metricsResult, panel: 1 });
  setMetricResult({ $store, result: metricsResult, panel: 2 });

  setEnvironmentData($store);
};