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

actions.js « test_reports « stores « pipelines « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 34f5130a3e71729db7f14fd10defb9be78c89902 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import axios from '~/lib/utils/axios_utils';
import * as types from './mutation_types';
import createFlash from '~/flash';
import { s__ } from '~/locale';

export const fetchSummary = ({ state, commit, dispatch }) => {
  // If we do this without the build_report_summary feature flag enabled
  // it causes a race condition for toggleLoading and ruins the loading
  // state in the application
  if (state.useBuildSummaryReport) {
    dispatch('toggleLoading');
  }

  return axios
    .get(state.summaryEndpoint)
    .then(({ data }) => {
      commit(types.SET_SUMMARY, data);

      if (!state.useBuildSummaryReport) {
        // Set the tab counter badge to total_count
        // This is temporary until we can server-side render that count number
        // (see https://gitlab.com/gitlab-org/gitlab/-/issues/223134)
        document.querySelector('.js-test-report-badge-counter').innerHTML = data.total_count || 0;
      }
    })
    .catch(() => {
      createFlash(s__('TestReports|There was an error fetching the summary.'));
    })
    .finally(() => {
      if (state.useBuildSummaryReport) {
        dispatch('toggleLoading');
      }
    });
};

export const fetchTestSuite = ({ state, commit, dispatch }, index) => {
  const { hasFullSuite } = state.testReports?.test_suites?.[index] || {};
  // We don't need to fetch the suite if we have the information already
  if (state.hasFullReport || hasFullSuite) {
    return Promise.resolve();
  }

  dispatch('toggleLoading');

  const { name = '', build_ids = [] } = state.testReports?.test_suites?.[index] || {};
  // Replacing `/:suite_name.json` with the name of the suite. Including the extra characters
  // to ensure that we replace exactly the template part of the URL string
  const endpoint = state.suiteEndpoint?.replace(
    '/:suite_name.json',
    `/${encodeURIComponent(name)}.json`,
  );

  return axios
    .get(endpoint, { params: { build_ids } })
    .then(({ data }) => commit(types.SET_SUITE, { suite: data, index }))
    .catch(() => {
      createFlash(s__('TestReports|There was an error fetching the test suite.'));
    })
    .finally(() => {
      dispatch('toggleLoading');
    });
};

export const fetchFullReport = ({ state, commit, dispatch }) => {
  dispatch('toggleLoading');

  return axios
    .get(state.fullReportEndpoint)
    .then(({ data }) => commit(types.SET_REPORTS, data))
    .catch(() => {
      createFlash(s__('TestReports|There was an error fetching the test reports.'));
    })
    .finally(() => {
      dispatch('toggleLoading');
    });
};

export const setSelectedSuiteIndex = ({ commit }, data) =>
  commit(types.SET_SELECTED_SUITE_INDEX, data);
export const removeSelectedSuiteIndex = ({ commit }) =>
  commit(types.SET_SELECTED_SUITE_INDEX, null);
export const toggleLoading = ({ commit }) => commit(types.TOGGLE_LOADING);