diff options
Diffstat (limited to 'spec/frontend/ci/reports')
-rw-r--r-- | spec/frontend/ci/reports/codequality_report/store/actions_spec.js | 190 | ||||
-rw-r--r-- | spec/frontend/ci/reports/codequality_report/store/getters_spec.js | 94 | ||||
-rw-r--r-- | spec/frontend/ci/reports/codequality_report/store/mutations_spec.js | 100 | ||||
-rw-r--r-- | spec/frontend/ci/reports/codequality_report/utils/codequality_parser_spec.js (renamed from spec/frontend/ci/reports/codequality_report/store/utils/codequality_parser_spec.js) | 2 |
4 files changed, 1 insertions, 385 deletions
diff --git a/spec/frontend/ci/reports/codequality_report/store/actions_spec.js b/spec/frontend/ci/reports/codequality_report/store/actions_spec.js deleted file mode 100644 index a606bce3d78..00000000000 --- a/spec/frontend/ci/reports/codequality_report/store/actions_spec.js +++ /dev/null @@ -1,190 +0,0 @@ -import MockAdapter from 'axios-mock-adapter'; -import testAction from 'helpers/vuex_action_helper'; -import { TEST_HOST } from 'spec/test_constants'; -import axios from '~/lib/utils/axios_utils'; -import { - HTTP_STATUS_INTERNAL_SERVER_ERROR, - HTTP_STATUS_NO_CONTENT, - HTTP_STATUS_OK, -} from '~/lib/utils/http_status'; -import createStore from '~/ci/reports/codequality_report/store'; -import * as actions from '~/ci/reports/codequality_report/store/actions'; -import * as types from '~/ci/reports/codequality_report/store/mutation_types'; -import { STATUS_NOT_FOUND } from '~/ci/reports/constants'; -import { reportIssues, parsedReportIssues } from '../mock_data'; - -const pollInterval = 123; -const pollIntervalHeader = { - 'Poll-Interval': pollInterval, -}; - -describe('Codequality Reports actions', () => { - let localState; - let localStore; - - beforeEach(() => { - localStore = createStore(); - localState = localStore.state; - }); - - describe('setPaths', () => { - it('should commit SET_PATHS mutation', () => { - const paths = { - baseBlobPath: 'baseBlobPath', - headBlobPath: 'headBlobPath', - reportsPath: 'reportsPath', - }; - - return testAction( - actions.setPaths, - paths, - localState, - [{ type: types.SET_PATHS, payload: paths }], - [], - ); - }); - }); - - describe('fetchReports', () => { - const endpoint = `${TEST_HOST}/codequality_reports.json`; - let mock; - - beforeEach(() => { - localState.reportsPath = endpoint; - mock = new MockAdapter(axios); - }); - - afterEach(() => { - mock.restore(); - }); - - describe('on success', () => { - it('commits REQUEST_REPORTS and dispatches receiveReportsSuccess', () => { - mock.onGet(endpoint).reply(HTTP_STATUS_OK, reportIssues); - - return testAction( - actions.fetchReports, - null, - localState, - [{ type: types.REQUEST_REPORTS }], - [ - { - payload: parsedReportIssues, - type: 'receiveReportsSuccess', - }, - ], - ); - }); - }); - - describe('on error', () => { - it('commits REQUEST_REPORTS and dispatches receiveReportsError', () => { - mock.onGet(endpoint).reply(HTTP_STATUS_INTERNAL_SERVER_ERROR); - - return testAction( - actions.fetchReports, - null, - localState, - [{ type: types.REQUEST_REPORTS }], - [{ type: 'receiveReportsError', payload: expect.any(Error) }], - ); - }); - }); - - describe('when base report is not found', () => { - it('commits REQUEST_REPORTS and dispatches receiveReportsError', () => { - const data = { status: STATUS_NOT_FOUND }; - mock.onGet(`${TEST_HOST}/codequality_reports.json`).reply(HTTP_STATUS_OK, data); - - return testAction( - actions.fetchReports, - null, - localState, - [{ type: types.REQUEST_REPORTS }], - [{ type: 'receiveReportsError', payload: data }], - ); - }); - }); - - describe('while waiting for report results', () => { - it('continues polling until it receives data', () => { - mock - .onGet(endpoint) - .replyOnce(HTTP_STATUS_NO_CONTENT, undefined, pollIntervalHeader) - .onGet(endpoint) - .reply(HTTP_STATUS_OK, reportIssues); - - return Promise.all([ - testAction( - actions.fetchReports, - null, - localState, - [{ type: types.REQUEST_REPORTS }], - [ - { - payload: parsedReportIssues, - type: 'receiveReportsSuccess', - }, - ], - ), - axios - // wait for initial NO_CONTENT response to be fulfilled - .waitForAll() - .then(() => { - jest.advanceTimersByTime(pollInterval); - }), - ]); - }); - - it('continues polling until it receives an error', () => { - mock - .onGet(endpoint) - .replyOnce(HTTP_STATUS_NO_CONTENT, undefined, pollIntervalHeader) - .onGet(endpoint) - .reply(HTTP_STATUS_INTERNAL_SERVER_ERROR); - - return Promise.all([ - testAction( - actions.fetchReports, - null, - localState, - [{ type: types.REQUEST_REPORTS }], - [{ type: 'receiveReportsError', payload: expect.any(Error) }], - ), - axios - // wait for initial NO_CONTENT response to be fulfilled - .waitForAll() - .then(() => { - jest.advanceTimersByTime(pollInterval); - }), - ]); - }); - }); - }); - - describe('receiveReportsSuccess', () => { - it('commits RECEIVE_REPORTS_SUCCESS', () => { - const data = { issues: [] }; - - return testAction( - actions.receiveReportsSuccess, - data, - localState, - [{ type: types.RECEIVE_REPORTS_SUCCESS, payload: data }], - [], - ); - }); - }); - - describe('receiveReportsError', () => { - it('commits RECEIVE_REPORTS_ERROR', () => { - return testAction( - actions.receiveReportsError, - null, - localState, - [{ type: types.RECEIVE_REPORTS_ERROR, payload: null }], - [], - ); - }); - }); -}); diff --git a/spec/frontend/ci/reports/codequality_report/store/getters_spec.js b/spec/frontend/ci/reports/codequality_report/store/getters_spec.js deleted file mode 100644 index f4505204f67..00000000000 --- a/spec/frontend/ci/reports/codequality_report/store/getters_spec.js +++ /dev/null @@ -1,94 +0,0 @@ -import createStore from '~/ci/reports/codequality_report/store'; -import * as getters from '~/ci/reports/codequality_report/store/getters'; -import { LOADING, ERROR, SUCCESS, STATUS_NOT_FOUND } from '~/ci/reports/constants'; - -describe('Codequality reports store getters', () => { - let localState; - let localStore; - - beforeEach(() => { - localStore = createStore(); - localState = localStore.state; - }); - - describe('hasCodequalityIssues', () => { - describe('when there are issues', () => { - it('returns true', () => { - localState.newIssues = [{ reason: 'repetitive code' }]; - localState.resolvedIssues = []; - - expect(getters.hasCodequalityIssues(localState)).toEqual(true); - - localState.newIssues = []; - localState.resolvedIssues = [{ reason: 'repetitive code' }]; - - expect(getters.hasCodequalityIssues(localState)).toEqual(true); - }); - }); - - describe('when there are no issues', () => { - it('returns false when there are no issues', () => { - expect(getters.hasCodequalityIssues(localState)).toEqual(false); - }); - }); - }); - - describe('codequalityStatus', () => { - describe('when loading', () => { - it('returns loading status', () => { - localState.isLoading = true; - - expect(getters.codequalityStatus(localState)).toEqual(LOADING); - }); - }); - - describe('on error', () => { - it('returns error status', () => { - localState.hasError = true; - - expect(getters.codequalityStatus(localState)).toEqual(ERROR); - }); - }); - - describe('when successfully loaded', () => { - it('returns error status', () => { - expect(getters.codequalityStatus(localState)).toEqual(SUCCESS); - }); - }); - }); - - describe('codequalityText', () => { - it.each` - resolvedIssues | newIssues | expectedText - ${0} | ${0} | ${'No changes to code quality'} - ${0} | ${1} | ${'Code quality degraded due to 1 new issue'} - ${2} | ${0} | ${'Code quality improved due to 2 resolved issues'} - ${1} | ${2} | ${'Code quality scanning detected 3 changes in merged results'} - `( - 'returns a summary containing $resolvedIssues resolved issues and $newIssues new issues', - ({ newIssues, resolvedIssues, expectedText }) => { - localState.newIssues = new Array(newIssues).fill({ reason: 'Repetitive code' }); - localState.resolvedIssues = new Array(resolvedIssues).fill({ reason: 'Repetitive code' }); - - expect(getters.codequalityText(localState)).toEqual(expectedText); - }, - ); - }); - - describe('codequalityPopover', () => { - describe('when base report is not available', () => { - it('returns a popover with a documentation link', () => { - localState.status = STATUS_NOT_FOUND; - localState.helpPath = 'codequality_help.html'; - - expect(getters.codequalityPopover(localState).title).toEqual( - 'Base pipeline codequality artifact not found', - ); - expect(getters.codequalityPopover(localState).content).toContain( - 'Learn more about codequality reports', - 'href="codequality_help.html"', - ); - }); - }); - }); -}); diff --git a/spec/frontend/ci/reports/codequality_report/store/mutations_spec.js b/spec/frontend/ci/reports/codequality_report/store/mutations_spec.js deleted file mode 100644 index 22ff86b1040..00000000000 --- a/spec/frontend/ci/reports/codequality_report/store/mutations_spec.js +++ /dev/null @@ -1,100 +0,0 @@ -import createStore from '~/ci/reports/codequality_report/store'; -import mutations from '~/ci/reports/codequality_report/store/mutations'; -import { STATUS_NOT_FOUND } from '~/ci/reports/constants'; - -describe('Codequality Reports mutations', () => { - let localState; - let localStore; - - beforeEach(() => { - localStore = createStore(); - localState = localStore.state; - }); - - describe('SET_PATHS', () => { - it('sets paths to given values', () => { - const baseBlobPath = 'base/blob/path/'; - const headBlobPath = 'head/blob/path/'; - const reportsPath = 'reports.json'; - const helpPath = 'help.html'; - - mutations.SET_PATHS(localState, { - baseBlobPath, - headBlobPath, - reportsPath, - helpPath, - }); - - expect(localState.baseBlobPath).toEqual(baseBlobPath); - expect(localState.headBlobPath).toEqual(headBlobPath); - expect(localState.reportsPath).toEqual(reportsPath); - expect(localState.helpPath).toEqual(helpPath); - }); - }); - - describe('REQUEST_REPORTS', () => { - it('sets isLoading to true', () => { - mutations.REQUEST_REPORTS(localState); - - expect(localState.isLoading).toEqual(true); - }); - }); - - describe('RECEIVE_REPORTS_SUCCESS', () => { - it('sets isLoading to false', () => { - mutations.RECEIVE_REPORTS_SUCCESS(localState, {}); - - expect(localState.isLoading).toEqual(false); - }); - - it('sets hasError to false', () => { - mutations.RECEIVE_REPORTS_SUCCESS(localState, {}); - - expect(localState.hasError).toEqual(false); - }); - - it('clears status and statusReason', () => { - mutations.RECEIVE_REPORTS_SUCCESS(localState, {}); - - expect(localState.status).toEqual(''); - expect(localState.statusReason).toEqual(''); - }); - - it('sets newIssues and resolvedIssues from response data', () => { - const data = { newIssues: [{ id: 1 }], resolvedIssues: [{ id: 2 }] }; - mutations.RECEIVE_REPORTS_SUCCESS(localState, data); - - expect(localState.newIssues).toEqual(data.newIssues); - expect(localState.resolvedIssues).toEqual(data.resolvedIssues); - }); - }); - - describe('RECEIVE_REPORTS_ERROR', () => { - it('sets isLoading to false', () => { - mutations.RECEIVE_REPORTS_ERROR(localState); - - expect(localState.isLoading).toEqual(false); - }); - - it('sets hasError to true', () => { - mutations.RECEIVE_REPORTS_ERROR(localState); - - expect(localState.hasError).toEqual(true); - }); - - it('sets status based on error object', () => { - const error = { status: STATUS_NOT_FOUND }; - mutations.RECEIVE_REPORTS_ERROR(localState, error); - - expect(localState.status).toEqual(error.status); - }); - - it('sets statusReason to string from error response data', () => { - const data = { status_reason: 'This merge request does not have codequality reports' }; - const error = { response: { data } }; - mutations.RECEIVE_REPORTS_ERROR(localState, error); - - expect(localState.statusReason).toEqual(data.status_reason); - }); - }); -}); diff --git a/spec/frontend/ci/reports/codequality_report/store/utils/codequality_parser_spec.js b/spec/frontend/ci/reports/codequality_report/utils/codequality_parser_spec.js index f7d82d2b662..953e6173662 100644 --- a/spec/frontend/ci/reports/codequality_report/store/utils/codequality_parser_spec.js +++ b/spec/frontend/ci/reports/codequality_report/utils/codequality_parser_spec.js @@ -1,5 +1,5 @@ import { reportIssues, parsedReportIssues } from 'jest/ci/reports/codequality_report/mock_data'; -import { parseCodeclimateMetrics } from '~/ci/reports/codequality_report/store/utils/codequality_parser'; +import { parseCodeclimateMetrics } from '~/ci/reports/codequality_report/utils/codequality_parser'; describe('Codequality report store utils', () => { let result; |