Commit a534e64d authored by Brandon Labuschagne's avatar Brandon Labuschagne Committed by Kushal Pandya

Change path to full_path on CA API call

As well as remove the flash error message when refreshing data.

Including tests for the flash error.
parent 8d12d307
......@@ -106,7 +106,7 @@ export default {
'setDateRange',
]),
onGroupSelect(group) {
this.setCycleAnalyticsDataEndpoint(group.path);
this.setCycleAnalyticsDataEndpoint(group.full_path);
this.setSelectedGroup(group);
this.fetchCycleAnalyticsData();
},
......
import dateFormat from 'dateformat';
import axios from '~/lib/utils/axios_utils';
import createFlash from '~/flash';
import createFlash, { hideFlash } from '~/flash';
import { __ } from '~/locale';
import Api from '~/api';
import httpStatus from '~/lib/utils/http_status';
import * as types from './mutation_types';
import { dateFormats } from '../../shared/constants';
const removeError = () => {
const flashEl = document.querySelector('.flash-alert');
if (flashEl) {
hideFlash(flashEl);
}
};
export const setCycleAnalyticsDataEndpoint = ({ commit }, groupPath) =>
commit(types.SET_CYCLE_ANALYTICS_DATA_ENDPOINT, groupPath);
......@@ -58,6 +65,8 @@ export const receiveCycleAnalyticsDataSuccess = ({ state, commit, dispatch }, da
commit(types.RECEIVE_CYCLE_ANALYTICS_DATA_SUCCESS, data);
const { stages = [] } = state;
if (stages && stages.length) {
removeError();
const { slug } = stages[0];
dispatch('setStageDataEndpoint', slug);
dispatch('fetchStageData');
......
......@@ -2,6 +2,7 @@ import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import testAction from 'helpers/vuex_action_helper';
import { TEST_HOST } from 'helpers/test_constants';
import createFlash from '~/flash';
import * as actions from 'ee/analytics/cycle_analytics/store/actions';
import * as types from 'ee/analytics/cycle_analytics/store/mutation_types';
import {
......@@ -17,12 +18,13 @@ const stageData = { events: [] };
const error = new Error('Request failed with status code 404');
const groupPath = 'cool-group';
const groupLabelsEndpoint = `/groups/${groupPath}/-/labels`;
const flashErrorMessage = 'There was an error while fetching cycle analytics data.';
describe('Cycle analytics actions', () => {
let state;
let mock;
function shouldFlashAnError(msg = 'There was an error while fetching cycle analytics data.') {
function shouldFlashAnError(msg = flashErrorMessage) {
expect(document.querySelector('.flash-container .flash-text').innerText.trim()).toBe(msg);
}
......@@ -303,6 +305,24 @@ describe('Cycle analytics actions', () => {
);
});
it('removes an existing flash error if present', () => {
const commit = jest.fn();
const dispatch = jest.fn();
const stateWithStages = {
...state,
stages,
};
createFlash(flashErrorMessage);
const flashAlert = document.querySelector('.flash-alert');
expect(flashAlert).toBeVisible();
actions.receiveCycleAnalyticsDataSuccess({ commit, dispatch, state: stateWithStages });
expect(flashAlert.style.opacity).toBe('0');
});
it("dispatches the 'setStageDataEndpoint' and 'fetchStageData' actions", done => {
const { slug } = stages[0];
const stateWithStages = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment