diff options
Diffstat (limited to 'spec/frontend/reports')
7 files changed, 199 insertions, 64 deletions
diff --git a/spec/frontend/reports/codequality_report/grouped_codequality_reports_app_spec.js b/spec/frontend/reports/codequality_report/grouped_codequality_reports_app_spec.js index ecb657af6f1..fb743c8b90c 100644 --- a/spec/frontend/reports/codequality_report/grouped_codequality_reports_app_spec.js +++ b/spec/frontend/reports/codequality_report/grouped_codequality_reports_app_spec.js @@ -9,7 +9,6 @@ const localVue = createLocalVue(); localVue.use(Vuex); describe('Grouped code quality reports app', () => { - const Component = localVue.extend(GroupedCodequalityReportsApp); let wrapper; let mockStore; @@ -22,7 +21,7 @@ describe('Grouped code quality reports app', () => { }; const mountComponent = (props = {}) => { - wrapper = mount(Component, { + wrapper = mount(GroupedCodequalityReportsApp, { store: mockStore, localVue, propsData: { @@ -135,7 +134,7 @@ describe('Grouped code quality reports app', () => { }); it('renders error text', () => { - expect(findWidget().text()).toEqual('Failed to load codeclimate report'); + expect(findWidget().text()).toContain('Failed to load codeclimate report'); }); it('renders a help icon with more information', () => { diff --git a/spec/frontend/reports/codequality_report/mock_data.js b/spec/frontend/reports/codequality_report/mock_data.js index 9bd61527d3f..c5cecb34509 100644 --- a/spec/frontend/reports/codequality_report/mock_data.js +++ b/spec/frontend/reports/codequality_report/mock_data.js @@ -88,3 +88,53 @@ export const issueDiff = [ urlPath: 'headPath/lib/six.rb#L6', }, ]; + +export const reportIssues = { + status: 'failed', + new_errors: [ + { + description: + 'Method `long_if` has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.', + severity: 'minor', + file_path: 'codequality.rb', + line: 5, + }, + ], + resolved_errors: [ + { + description: 'Insecure Dependency', + severity: 'major', + file_path: 'lib/six.rb', + line: 22, + }, + ], + existing_errors: [], + summary: { total: 3, resolved: 0, errored: 3 }, +}; + +export const parsedReportIssues = { + newIssues: [ + { + description: + 'Method `long_if` has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.', + file_path: 'codequality.rb', + line: 5, + name: + 'Method `long_if` has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.', + path: 'codequality.rb', + severity: 'minor', + urlPath: 'null/codequality.rb#L5', + }, + ], + resolvedIssues: [ + { + description: 'Insecure Dependency', + file_path: 'lib/six.rb', + line: 22, + name: 'Insecure Dependency', + path: 'lib/six.rb', + severity: 'major', + urlPath: 'null/lib/six.rb#L22', + }, + ], +}; diff --git a/spec/frontend/reports/codequality_report/store/actions_spec.js b/spec/frontend/reports/codequality_report/store/actions_spec.js index 321785cb85a..6ff6bae1284 100644 --- a/spec/frontend/reports/codequality_report/store/actions_spec.js +++ b/spec/frontend/reports/codequality_report/store/actions_spec.js @@ -5,7 +5,14 @@ import axios from '~/lib/utils/axios_utils'; import * as actions from '~/reports/codequality_report/store/actions'; import * as types from '~/reports/codequality_report/store/mutation_types'; import createStore from '~/reports/codequality_report/store'; -import { headIssues, baseIssues, mockParsedHeadIssues, mockParsedBaseIssues } from '../mock_data'; +import { + headIssues, + baseIssues, + mockParsedHeadIssues, + mockParsedBaseIssues, + reportIssues, + parsedReportIssues, +} from '../mock_data'; // mock codequality comparison worker jest.mock('~/reports/codequality_report/workers/codequality_comparison_worker', () => @@ -39,6 +46,7 @@ describe('Codequality Reports actions', () => { headPath: 'headPath', baseBlobPath: 'baseBlobPath', headBlobPath: 'headBlobPath', + reportsPath: 'reportsPath', helpPath: 'codequalityHelpPath', }; @@ -55,68 +63,119 @@ describe('Codequality Reports actions', () => { describe('fetchReports', () => { let mock; + let diffFeatureFlagEnabled; - beforeEach(() => { - localState.headPath = `${TEST_HOST}/head.json`; - localState.basePath = `${TEST_HOST}/base.json`; - mock = new MockAdapter(axios); - }); + describe('with codequalityBackendComparison feature flag enabled', () => { + beforeEach(() => { + diffFeatureFlagEnabled = true; + localState.reportsPath = `${TEST_HOST}/codequality_reports.json`; + mock = new MockAdapter(axios); + }); - afterEach(() => { - mock.restore(); - }); + afterEach(() => { + mock.restore(); + }); - describe('on success', () => { - it('commits REQUEST_REPORTS and dispatches receiveReportsSuccess', (done) => { - mock.onGet(`${TEST_HOST}/head.json`).reply(200, headIssues); - mock.onGet(`${TEST_HOST}/base.json`).reply(200, baseIssues); - - testAction( - actions.fetchReports, - null, - localState, - [{ type: types.REQUEST_REPORTS }], - [ - { - payload: { - newIssues: [mockParsedHeadIssues[0]], - resolvedIssues: [mockParsedBaseIssues[0]], + describe('on success', () => { + it('commits REQUEST_REPORTS and dispatches receiveReportsSuccess', (done) => { + mock.onGet(`${TEST_HOST}/codequality_reports.json`).reply(200, reportIssues); + + testAction( + actions.fetchReports, + diffFeatureFlagEnabled, + localState, + [{ type: types.REQUEST_REPORTS }], + [ + { + payload: parsedReportIssues, + type: 'receiveReportsSuccess', }, - type: 'receiveReportsSuccess', - }, - ], - done, - ); + ], + done, + ); + }); }); - }); - describe('on error', () => { - it('commits REQUEST_REPORTS and dispatches receiveReportsError', (done) => { - mock.onGet(`${TEST_HOST}/head.json`).reply(500); - - testAction( - actions.fetchReports, - null, - localState, - [{ type: types.REQUEST_REPORTS }], - [{ type: 'receiveReportsError' }], - done, - ); + describe('on error', () => { + it('commits REQUEST_REPORTS and dispatches receiveReportsError', (done) => { + mock.onGet(`${TEST_HOST}/codequality_reports.json`).reply(500); + + testAction( + actions.fetchReports, + diffFeatureFlagEnabled, + localState, + [{ type: types.REQUEST_REPORTS }], + [{ type: 'receiveReportsError', payload: expect.any(Error) }], + done, + ); + }); }); }); - describe('with no base path', () => { - it('commits REQUEST_REPORTS and dispatches receiveReportsError', (done) => { - localState.basePath = null; - - testAction( - actions.fetchReports, - null, - localState, - [{ type: types.REQUEST_REPORTS }], - [{ type: 'receiveReportsError' }], - done, - ); + describe('with codequalityBackendComparison feature flag disabled', () => { + beforeEach(() => { + diffFeatureFlagEnabled = false; + localState.headPath = `${TEST_HOST}/head.json`; + localState.basePath = `${TEST_HOST}/base.json`; + mock = new MockAdapter(axios); + }); + + afterEach(() => { + mock.restore(); + }); + + describe('on success', () => { + it('commits REQUEST_REPORTS and dispatches receiveReportsSuccess', (done) => { + mock.onGet(`${TEST_HOST}/head.json`).reply(200, headIssues); + mock.onGet(`${TEST_HOST}/base.json`).reply(200, baseIssues); + + testAction( + actions.fetchReports, + diffFeatureFlagEnabled, + localState, + [{ type: types.REQUEST_REPORTS }], + [ + { + payload: { + newIssues: [mockParsedHeadIssues[0]], + resolvedIssues: [mockParsedBaseIssues[0]], + }, + type: 'receiveReportsSuccess', + }, + ], + done, + ); + }); + }); + + describe('on error', () => { + it('commits REQUEST_REPORTS and dispatches receiveReportsError', (done) => { + mock.onGet(`${TEST_HOST}/head.json`).reply(500); + + testAction( + actions.fetchReports, + diffFeatureFlagEnabled, + localState, + [{ type: types.REQUEST_REPORTS }], + [{ type: 'receiveReportsError', payload: expect.any(Error) }], + done, + ); + }); + }); + + describe('with no base path', () => { + it('commits REQUEST_REPORTS and dispatches receiveReportsError', (done) => { + localState.basePath = null; + + testAction( + actions.fetchReports, + diffFeatureFlagEnabled, + localState, + [{ type: types.REQUEST_REPORTS }], + [{ type: 'receiveReportsError' }], + done, + ); + }); }); }); }); @@ -142,7 +201,7 @@ describe('Codequality Reports actions', () => { actions.receiveReportsError, null, localState, - [{ type: types.RECEIVE_REPORTS_ERROR }], + [{ type: types.RECEIVE_REPORTS_ERROR, payload: null }], [], done, ); diff --git a/spec/frontend/reports/codequality_report/store/mutations_spec.js b/spec/frontend/reports/codequality_report/store/mutations_spec.js index 658abf3088c..f7f9e611ee8 100644 --- a/spec/frontend/reports/codequality_report/store/mutations_spec.js +++ b/spec/frontend/reports/codequality_report/store/mutations_spec.js @@ -55,6 +55,12 @@ describe('Codequality Reports mutations', () => { expect(localState.hasError).toEqual(false); }); + it('clears statusReason', () => { + mutations.RECEIVE_REPORTS_SUCCESS(localState, {}); + + 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); @@ -76,5 +82,13 @@ describe('Codequality Reports mutations', () => { expect(localState.hasError).toEqual(true); }); + + 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/reports/codequality_report/store/utils/codequality_comparison_spec.js b/spec/frontend/reports/codequality_report/store/utils/codequality_comparison_spec.js index 085d697672d..389e9b4a1f6 100644 --- a/spec/frontend/reports/codequality_report/store/utils/codequality_comparison_spec.js +++ b/spec/frontend/reports/codequality_report/store/utils/codequality_comparison_spec.js @@ -2,7 +2,13 @@ import { parseCodeclimateMetrics, doCodeClimateComparison, } from '~/reports/codequality_report/store/utils/codequality_comparison'; -import { baseIssues, mockParsedHeadIssues, mockParsedBaseIssues } from '../../mock_data'; +import { + baseIssues, + mockParsedHeadIssues, + mockParsedBaseIssues, + reportIssues, + parsedReportIssues, +} from '../../mock_data'; jest.mock('~/reports/codequality_report/workers/codequality_comparison_worker', () => { let mockPostMessageCallback; @@ -34,7 +40,7 @@ describe('Codequality report store utils', () => { let result; describe('parseCodeclimateMetrics', () => { - it('should parse the received issues', () => { + it('should parse the issues from codeclimate artifacts', () => { [result] = parseCodeclimateMetrics(baseIssues, 'path'); expect(result.name).toEqual(baseIssues[0].check_name); @@ -42,6 +48,14 @@ describe('Codequality report store utils', () => { expect(result.line).toEqual(baseIssues[0].location.lines.begin); }); + it('should parse the issues from backend codequality diff', () => { + [result] = parseCodeclimateMetrics(reportIssues.new_errors, 'path'); + + expect(result.name).toEqual(parsedReportIssues.newIssues[0].name); + expect(result.path).toEqual(parsedReportIssues.newIssues[0].path); + expect(result.line).toEqual(parsedReportIssues.newIssues[0].line); + }); + describe('when an issue has no location or path', () => { const issue = { description: 'Insecure Dependency' }; diff --git a/spec/frontend/reports/components/grouped_test_reports_app_spec.js b/spec/frontend/reports/components/grouped_test_reports_app_spec.js index 492192988fb..88a82908e1e 100644 --- a/spec/frontend/reports/components/grouped_test_reports_app_spec.js +++ b/spec/frontend/reports/components/grouped_test_reports_app_spec.js @@ -18,12 +18,11 @@ localVue.use(Vuex); describe('Grouped test reports app', () => { const endpoint = 'endpoint.json'; const pipelinePath = '/path/to/pipeline'; - const Component = localVue.extend(GroupedTestReportsApp); let wrapper; let mockStore; const mountComponent = ({ props = { pipelinePath } } = {}) => { - wrapper = mount(Component, { + wrapper = mount(GroupedTestReportsApp, { store: mockStore, localVue, propsData: { diff --git a/spec/frontend/reports/components/summary_row_spec.js b/spec/frontend/reports/components/summary_row_spec.js index 85c68ed069b..bdd6de1e0be 100644 --- a/spec/frontend/reports/components/summary_row_spec.js +++ b/spec/frontend/reports/components/summary_row_spec.js @@ -32,7 +32,7 @@ describe('Summary row', () => { it('renders provided summary', () => { createComponent(); - expect(findSummary().text()).toEqual(props.summary); + expect(findSummary().text()).toContain(props.summary); }); it('renders provided icon', () => { @@ -48,7 +48,7 @@ describe('Summary row', () => { createComponent({ slots: { summary: summarySlotContent } }); expect(wrapper.text()).not.toContain(props.summary); - expect(findSummary().text()).toEqual(summarySlotContent); + expect(findSummary().text()).toContain(summarySlotContent); }); }); }); |