diff options
Diffstat (limited to 'app/assets/javascripts/reports/store')
-rw-r--r-- | app/assets/javascripts/reports/store/actions.js | 82 | ||||
-rw-r--r-- | app/assets/javascripts/reports/store/getters.js | 13 | ||||
-rw-r--r-- | app/assets/javascripts/reports/store/index.js | 17 | ||||
-rw-r--r-- | app/assets/javascripts/reports/store/mutation_types.js | 7 | ||||
-rw-r--r-- | app/assets/javascripts/reports/store/mutations.js | 70 | ||||
-rw-r--r-- | app/assets/javascripts/reports/store/state.js | 71 | ||||
-rw-r--r-- | app/assets/javascripts/reports/store/utils.js | 102 |
7 files changed, 0 insertions, 362 deletions
diff --git a/app/assets/javascripts/reports/store/actions.js b/app/assets/javascripts/reports/store/actions.js deleted file mode 100644 index c9b8ee64930..00000000000 --- a/app/assets/javascripts/reports/store/actions.js +++ /dev/null @@ -1,82 +0,0 @@ -import Visibility from 'visibilityjs'; -import axios from '../../lib/utils/axios_utils'; -import httpStatusCodes from '../../lib/utils/http_status'; -import Poll from '../../lib/utils/poll'; -import * as types from './mutation_types'; - -export const setEndpoint = ({ commit }, endpoint) => commit(types.SET_ENDPOINT, endpoint); - -export const requestReports = ({ commit }) => commit(types.REQUEST_REPORTS); - -let eTagPoll; - -export const clearEtagPoll = () => { - eTagPoll = null; -}; - -export const stopPolling = () => { - if (eTagPoll) eTagPoll.stop(); -}; - -export const restartPolling = () => { - if (eTagPoll) eTagPoll.restart(); -}; - -/** - * We need to poll the reports endpoint while they are being parsed in the Backend. - * This can take up to one minute. - * - * Poll.js will handle etag response. - * While http status code is 204, it means it's parsing, and we'll keep polling - * When http status code is 200, it means parsing is done, we can show the results & stop polling - * When http status code is 500, it means parsing went wrong and we stop polling - */ -export const fetchReports = ({ state, dispatch }) => { - dispatch('requestReports'); - - eTagPoll = new Poll({ - resource: { - getReports(endpoint) { - return axios.get(endpoint); - }, - }, - data: state.endpoint, - method: 'getReports', - successCallback: ({ data, status }) => - dispatch('receiveReportsSuccess', { - data, - status, - }), - errorCallback: () => dispatch('receiveReportsError'), - }); - - if (!Visibility.hidden()) { - eTagPoll.makeRequest(); - } else { - axios - .get(state.endpoint) - .then(({ data, status }) => dispatch('receiveReportsSuccess', { data, status })) - .catch(() => dispatch('receiveReportsError')); - } - - Visibility.change(() => { - if (!Visibility.hidden()) { - dispatch('restartPolling'); - } else { - dispatch('stopPolling'); - } - }); -}; - -export const receiveReportsSuccess = ({ commit }, response) => { - // With 204 we keep polling and don't update the state - if (response.status === httpStatusCodes.OK) { - commit(types.RECEIVE_REPORTS_SUCCESS, response.data); - } -}; - -export const receiveReportsError = ({ commit }) => commit(types.RECEIVE_REPORTS_ERROR); - -export const openModal = ({ commit }, payload) => commit(types.SET_ISSUE_MODAL_DATA, payload); - -export const closeModal = ({ commit }, payload) => commit(types.RESET_ISSUE_MODAL_DATA, payload); diff --git a/app/assets/javascripts/reports/store/getters.js b/app/assets/javascripts/reports/store/getters.js deleted file mode 100644 index cc8c4cc446c..00000000000 --- a/app/assets/javascripts/reports/store/getters.js +++ /dev/null @@ -1,13 +0,0 @@ -import { LOADING, ERROR, SUCCESS, STATUS_FAILED } from '../constants'; - -export const summaryStatus = (state) => { - if (state.isLoading) { - return LOADING; - } - - if (state.hasError || state.status === STATUS_FAILED) { - return ERROR; - } - - return SUCCESS; -}; diff --git a/app/assets/javascripts/reports/store/index.js b/app/assets/javascripts/reports/store/index.js deleted file mode 100644 index a2edfa94a48..00000000000 --- a/app/assets/javascripts/reports/store/index.js +++ /dev/null @@ -1,17 +0,0 @@ -import Vue from 'vue'; -import Vuex from 'vuex'; -import * as actions from './actions'; -import * as getters from './getters'; -import mutations from './mutations'; -import state from './state'; - -Vue.use(Vuex); - -export const getStoreConfig = () => ({ - actions, - mutations, - getters, - state: state(), -}); - -export default () => new Vuex.Store(getStoreConfig()); diff --git a/app/assets/javascripts/reports/store/mutation_types.js b/app/assets/javascripts/reports/store/mutation_types.js deleted file mode 100644 index 337085f9bf0..00000000000 --- a/app/assets/javascripts/reports/store/mutation_types.js +++ /dev/null @@ -1,7 +0,0 @@ -export const SET_ENDPOINT = 'SET_ENDPOINT'; - -export const REQUEST_REPORTS = 'REQUEST_REPORTS'; -export const RECEIVE_REPORTS_SUCCESS = 'RECEIVE_REPORTS_SUCCESS'; -export const RECEIVE_REPORTS_ERROR = 'RECEIVE_REPORTS_ERROR'; -export const SET_ISSUE_MODAL_DATA = 'SET_ISSUE_MODAL_DATA'; -export const RESET_ISSUE_MODAL_DATA = 'RESET_ISSUE_MODAL_DATA'; diff --git a/app/assets/javascripts/reports/store/mutations.js b/app/assets/javascripts/reports/store/mutations.js deleted file mode 100644 index 3bb31d71d8f..00000000000 --- a/app/assets/javascripts/reports/store/mutations.js +++ /dev/null @@ -1,70 +0,0 @@ -import * as types from './mutation_types'; -import { countRecentlyFailedTests } from './utils'; - -export default { - [types.SET_ENDPOINT](state, endpoint) { - state.endpoint = endpoint; - }, - [types.REQUEST_REPORTS](state) { - state.isLoading = true; - }, - [types.RECEIVE_REPORTS_SUCCESS](state, response) { - state.hasError = response.suites.some((suite) => suite.status === 'error'); - - state.isLoading = false; - - state.summary.total = response.summary.total; - state.summary.resolved = response.summary.resolved; - state.summary.failed = response.summary.failed; - state.summary.errored = response.summary.errored; - state.summary.recentlyFailed = countRecentlyFailedTests(response.suites); - - state.status = response.status; - state.reports = response.suites; - - state.reports.forEach((report, i) => { - if (!state.reports[i].summary) return; - state.reports[i].summary.recentlyFailed = countRecentlyFailedTests(report); - }); - }, - [types.RECEIVE_REPORTS_ERROR](state) { - state.isLoading = false; - state.hasError = true; - - state.reports = []; - state.summary = { - total: 0, - resolved: 0, - failed: 0, - errored: 0, - recentlyFailed: 0, - }; - state.status = null; - }, - [types.SET_ISSUE_MODAL_DATA](state, payload) { - state.modal.title = payload.issue.name; - - Object.keys(payload.issue).forEach((key) => { - if (Object.prototype.hasOwnProperty.call(state.modal.data, key)) { - state.modal.data[key] = { - ...state.modal.data[key], - value: payload.issue[key], - }; - } - }); - - state.modal.open = true; - }, - [types.RESET_ISSUE_MODAL_DATA](state) { - state.modal.open = false; - - // Resetting modal data - state.modal.title = null; - Object.keys(state.modal.data).forEach((key) => { - state.modal.data[key] = { - ...state.modal.data[key], - value: null, - }; - }); - }, -}; diff --git a/app/assets/javascripts/reports/store/state.js b/app/assets/javascripts/reports/store/state.js deleted file mode 100644 index e8a0db2e1a8..00000000000 --- a/app/assets/javascripts/reports/store/state.js +++ /dev/null @@ -1,71 +0,0 @@ -import { s__ } from '~/locale'; -import { fieldTypes } from '../constants'; - -export default () => ({ - endpoint: null, - - isLoading: false, - hasError: false, - - status: null, - - summary: { - total: 0, - resolved: 0, - failed: 0, - errored: 0, - }, - - /** - * Each report will have the following format: - * { - * name: {String}, - * summary: { - * total: {Number}, - * resolved: {Number}, - * failed: {Number}, - * errored: {Number}, - * }, - * new_failures: {Array.<Object>}, - * resolved_failures: {Array.<Object>}, - * existing_failures: {Array.<Object>}, - * new_errors: {Array.<Object>}, - * resolved_errors: {Array.<Object>}, - * existing_errors: {Array.<Object>}, - * } - */ - reports: [], - - modal: { - title: null, - open: false, - - data: { - class: { - value: null, - text: s__('Reports|Class'), - type: fieldTypes.link, - }, - classname: { - value: null, - text: s__('Reports|Classname'), - type: fieldTypes.text, - }, - execution_time: { - value: null, - text: s__('Reports|Execution time'), - type: fieldTypes.seconds, - }, - failure: { - value: null, - text: s__('Reports|Failure'), - type: fieldTypes.codeBock, - }, - system_output: { - value: null, - text: s__('Reports|System output'), - type: fieldTypes.codeBock, - }, - }, - }, -}); diff --git a/app/assets/javascripts/reports/store/utils.js b/app/assets/javascripts/reports/store/utils.js deleted file mode 100644 index d89833032a0..00000000000 --- a/app/assets/javascripts/reports/store/utils.js +++ /dev/null @@ -1,102 +0,0 @@ -import { sprintf, n__, s__, __ } from '~/locale'; -import { - STATUS_FAILED, - STATUS_SUCCESS, - ICON_WARNING, - ICON_SUCCESS, - ICON_NOTFOUND, -} from '../constants'; - -const textBuilder = (results) => { - const { failed, errored, resolved, total } = results; - - const failedOrErrored = (failed || 0) + (errored || 0); - const failedString = failed ? n__('%d failed', '%d failed', failed) : null; - const erroredString = errored ? n__('%d error', '%d errors', errored) : null; - const combinedString = - failed && errored ? `${failedString}, ${erroredString}` : failedString || erroredString; - const resolvedString = resolved - ? n__('%d fixed test result', '%d fixed test results', resolved) - : null; - const totalString = total ? n__('out of %d total test', 'out of %d total tests', total) : null; - - let resultsString = s__('Reports|no changed test results'); - - if (failedOrErrored) { - if (resolved) { - resultsString = sprintf(s__('Reports|%{combinedString} and %{resolvedString}'), { - combinedString, - resolvedString, - }); - } else { - resultsString = combinedString; - } - } else if (resolved) { - resultsString = resolvedString; - } - - return `${resultsString} ${totalString}`; -}; - -export const summaryTextBuilder = (name = '', results = {}) => { - const resultsString = textBuilder(results); - return sprintf(__('%{name} contained %{resultsString}'), { name, resultsString }); -}; - -export const reportTextBuilder = (name = '', results = {}) => { - const resultsString = textBuilder(results); - return sprintf(__('%{name} found %{resultsString}'), { name, resultsString }); -}; - -export const recentFailuresTextBuilder = (summary = {}) => { - const { failed, recentlyFailed } = summary; - if (!failed || !recentlyFailed) return ''; - - if (failed < 2) { - return sprintf( - s__( - 'Reports|%{recentlyFailed} out of %{failed} failed test has failed more than once in the last 14 days', - ), - { recentlyFailed, failed }, - ); - } - return sprintf( - n__( - 'Reports|%{recentlyFailed} out of %{failed} failed tests has failed more than once in the last 14 days', - 'Reports|%{recentlyFailed} out of %{failed} failed tests have failed more than once in the last 14 days', - recentlyFailed, - ), - { recentlyFailed, failed }, - ); -}; - -export const countRecentlyFailedTests = (subject) => { - // handle either a single report or an array of reports - const reports = !subject.length ? [subject] : subject; - - return reports - .map((report) => { - return ( - [report.new_failures, report.existing_failures, report.resolved_failures] - // only count tests which have failed more than once - .map( - (failureArray) => - failureArray.filter((failure) => failure.recent_failures?.count > 1).length, - ) - .reduce((total, count) => total + count, 0) - ); - }) - .reduce((total, count) => total + count, 0); -}; - -export const statusIcon = (status) => { - if (status === STATUS_FAILED) { - return ICON_WARNING; - } - - if (status === STATUS_SUCCESS) { - return ICON_SUCCESS; - } - - return ICON_NOTFOUND; -}; |