diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 15:44:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 15:44:42 +0000 |
commit | 4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch) | |
tree | 5423a1c7516cffe36384133ade12572cf709398d /spec/frontend/reports | |
parent | e570267f2f6b326480d284e0164a6464ba4081bc (diff) | |
download | gitlab-ce-4555e1b21c365ed8303ffb7a3325d773c9b8bf31.tar.gz |
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'spec/frontend/reports')
10 files changed, 141 insertions, 400 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 f0b23bb7b58..b8299d44f13 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 @@ -3,7 +3,7 @@ import Vuex from 'vuex'; import CodequalityIssueBody from '~/reports/codequality_report/components/codequality_issue_body.vue'; import GroupedCodequalityReportsApp from '~/reports/codequality_report/grouped_codequality_reports_app.vue'; import { getStoreConfig } from '~/reports/codequality_report/store'; -import { mockParsedHeadIssues, mockParsedBaseIssues } from './mock_data'; +import { parsedReportIssues } from './mock_data'; const localVue = createLocalVue(); localVue.use(Vuex); @@ -80,7 +80,7 @@ describe('Grouped code quality reports app', () => { describe('with issues', () => { describe('with new issues', () => { beforeEach(() => { - mockStore.state.newIssues = [mockParsedHeadIssues[0]]; + mockStore.state.newIssues = parsedReportIssues.newIssues; mockStore.state.resolvedIssues = []; }); @@ -89,14 +89,14 @@ describe('Grouped code quality reports app', () => { }); it('renders custom codequality issue body', () => { - expect(findIssueBody().props('issue')).toEqual(mockParsedHeadIssues[0]); + expect(findIssueBody().props('issue')).toEqual(parsedReportIssues.newIssues[0]); }); }); describe('with resolved issues', () => { beforeEach(() => { mockStore.state.newIssues = []; - mockStore.state.resolvedIssues = [mockParsedBaseIssues[0]]; + mockStore.state.resolvedIssues = parsedReportIssues.resolvedIssues; }); it('renders summary text', () => { @@ -104,14 +104,14 @@ describe('Grouped code quality reports app', () => { }); it('renders custom codequality issue body', () => { - expect(findIssueBody().props('issue')).toEqual(mockParsedBaseIssues[0]); + expect(findIssueBody().props('issue')).toEqual(parsedReportIssues.resolvedIssues[0]); }); }); describe('with new and resolved issues', () => { beforeEach(() => { - mockStore.state.newIssues = [mockParsedHeadIssues[0]]; - mockStore.state.resolvedIssues = [mockParsedBaseIssues[0]]; + mockStore.state.newIssues = parsedReportIssues.newIssues; + mockStore.state.resolvedIssues = parsedReportIssues.resolvedIssues; }); it('renders summary text', () => { @@ -121,7 +121,7 @@ describe('Grouped code quality reports app', () => { }); it('renders custom codequality issue body', () => { - expect(findIssueBody().props('issue')).toEqual(mockParsedHeadIssues[0]); + expect(findIssueBody().props('issue')).toEqual(parsedReportIssues.newIssues[0]); }); }); }); diff --git a/spec/frontend/reports/codequality_report/mock_data.js b/spec/frontend/reports/codequality_report/mock_data.js index c5cecb34509..2c994116db6 100644 --- a/spec/frontend/reports/codequality_report/mock_data.js +++ b/spec/frontend/reports/codequality_report/mock_data.js @@ -1,94 +1,3 @@ -export const headIssues = [ - { - check_name: 'Rubocop/Lint/UselessAssignment', - description: 'Insecure Dependency', - location: { - path: 'lib/six.rb', - lines: { - begin: 6, - end: 7, - }, - }, - fingerprint: 'e879dd9bbc0953cad5037cde7ff0f627', - }, - { - categories: ['Security'], - check_name: 'Insecure Dependency', - description: 'Insecure Dependency', - location: { - path: 'Gemfile.lock', - lines: { - begin: 22, - end: 22, - }, - }, - fingerprint: 'ca2e59451e98ae60ba2f54e3857c50e5', - }, -]; - -export const mockParsedHeadIssues = [ - { - ...headIssues[1], - name: 'Insecure Dependency', - path: 'lib/six.rb', - urlPath: 'headPath/lib/six.rb#L6', - line: 6, - }, -]; - -export const baseIssues = [ - { - categories: ['Security'], - check_name: 'Insecure Dependency', - description: 'Insecure Dependency', - location: { - path: 'Gemfile.lock', - lines: { - begin: 22, - end: 22, - }, - }, - fingerprint: 'ca2e59451e98ae60ba2f54e3857c50e5', - }, - { - categories: ['Security'], - check_name: 'Insecure Dependency', - description: 'Insecure Dependency', - location: { - path: 'Gemfile.lock', - lines: { - begin: 21, - end: 21, - }, - }, - fingerprint: 'ca2354534dee94ae60ba2f54e3857c50e5', - }, -]; - -export const mockParsedBaseIssues = [ - { - ...baseIssues[1], - name: 'Insecure Dependency', - path: 'Gemfile.lock', - line: 21, - urlPath: 'basePath/Gemfile.lock#L21', - }, -]; - -export const issueDiff = [ - { - categories: ['Security'], - check_name: 'Insecure Dependency', - description: 'Insecure Dependency', - fingerprint: 'ca2e59451e98ae60ba2f54e3857c50e5', - line: 6, - location: { lines: { begin: 22, end: 22 }, path: 'Gemfile.lock' }, - name: 'Insecure Dependency', - path: 'lib/six.rb', - urlPath: 'headPath/lib/six.rb#L6', - }, -]; - export const reportIssues = { status: 'failed', new_errors: [ diff --git a/spec/frontend/reports/codequality_report/store/actions_spec.js b/spec/frontend/reports/codequality_report/store/actions_spec.js index a2b256448ef..1b83d071d17 100644 --- a/spec/frontend/reports/codequality_report/store/actions_spec.js +++ b/spec/frontend/reports/codequality_report/store/actions_spec.js @@ -5,30 +5,7 @@ import axios from '~/lib/utils/axios_utils'; import createStore from '~/reports/codequality_report/store'; import * as actions from '~/reports/codequality_report/store/actions'; import * as types from '~/reports/codequality_report/store/mutation_types'; -import { - headIssues, - baseIssues, - mockParsedHeadIssues, - mockParsedBaseIssues, - reportIssues, - parsedReportIssues, -} from '../mock_data'; - -// mock codequality comparison worker -jest.mock('~/reports/codequality_report/workers/codequality_comparison_worker', () => - jest.fn().mockImplementation(() => { - return { - addEventListener: (eventName, callback) => { - callback({ - data: { - newIssues: [mockParsedHeadIssues[0]], - resolvedIssues: [mockParsedBaseIssues[0]], - }, - }); - }, - }; - }), -); +import { reportIssues, parsedReportIssues } from '../mock_data'; describe('Codequality Reports actions', () => { let localState; @@ -43,9 +20,6 @@ describe('Codequality Reports actions', () => { it('should commit SET_PATHS mutation', (done) => { const paths = { basePath: 'basePath', - headPath: 'headPath', - baseBlobPath: 'baseBlobPath', - headBlobPath: 'headBlobPath', reportsPath: 'reportsPath', helpPath: 'codequalityHelpPath', }; @@ -63,119 +37,64 @@ describe('Codequality Reports actions', () => { describe('fetchReports', () => { let mock; - let diffFeatureFlagEnabled; - describe('with codequalityBackendComparison feature flag enabled', () => { - beforeEach(() => { - diffFeatureFlagEnabled = true; - localState.reportsPath = `${TEST_HOST}/codequality_reports.json`; - mock = new MockAdapter(axios); - }); - - afterEach(() => { - mock.restore(); - }); - - 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', - }, - ], - 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, - ); - }); - }); + beforeEach(() => { + localState.reportsPath = `${TEST_HOST}/codequality_reports.json`; + localState.basePath = '/base/path'; + mock = new MockAdapter(axios); }); - 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(); - }); + 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 success', () => { + it('commits REQUEST_REPORTS and dispatches receiveReportsSuccess', (done) => { + mock.onGet(`${TEST_HOST}/codequality_reports.json`).reply(200, reportIssues); + + testAction( + actions.fetchReports, + null, + localState, + [{ type: types.REQUEST_REPORTS }], + [ + { + payload: parsedReportIssues, + 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('on error', () => { + it('commits REQUEST_REPORTS and dispatches receiveReportsError', (done) => { + mock.onGet(`${TEST_HOST}/codequality_reports.json`).reply(500); + + testAction( + actions.fetchReports, + null, + 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, - ); - }); + 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, + ); }); }); }); diff --git a/spec/frontend/reports/codequality_report/store/mutations_spec.js b/spec/frontend/reports/codequality_report/store/mutations_spec.js index 05a16cd6f82..9d4c05afd36 100644 --- a/spec/frontend/reports/codequality_report/store/mutations_spec.js +++ b/spec/frontend/reports/codequality_report/store/mutations_spec.js @@ -13,23 +13,17 @@ describe('Codequality Reports mutations', () => { describe('SET_PATHS', () => { it('sets paths to given values', () => { const basePath = 'base.json'; - const headPath = 'head.json'; - const baseBlobPath = 'base/blob/path/'; - const headBlobPath = 'head/blob/path/'; + const reportsPath = 'reports.json'; const helpPath = 'help.html'; mutations.SET_PATHS(localState, { basePath, - headPath, - baseBlobPath, - headBlobPath, + reportsPath, helpPath, }); expect(localState.basePath).toEqual(basePath); - expect(localState.headPath).toEqual(headPath); - expect(localState.baseBlobPath).toEqual(baseBlobPath); - expect(localState.headBlobPath).toEqual(headBlobPath); + expect(localState.reportsPath).toEqual(reportsPath); expect(localState.helpPath).toEqual(helpPath); }); }); 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 deleted file mode 100644 index 389e9b4a1f6..00000000000 --- a/spec/frontend/reports/codequality_report/store/utils/codequality_comparison_spec.js +++ /dev/null @@ -1,153 +0,0 @@ -import { - parseCodeclimateMetrics, - doCodeClimateComparison, -} from '~/reports/codequality_report/store/utils/codequality_comparison'; -import { - baseIssues, - mockParsedHeadIssues, - mockParsedBaseIssues, - reportIssues, - parsedReportIssues, -} from '../../mock_data'; - -jest.mock('~/reports/codequality_report/workers/codequality_comparison_worker', () => { - let mockPostMessageCallback; - return jest.fn().mockImplementation(() => { - return { - addEventListener: (_, callback) => { - mockPostMessageCallback = callback; - }, - postMessage: (data) => { - if (!data.headIssues) return mockPostMessageCallback({ data: {} }); - if (!data.baseIssues) throw new Error(); - const key = 'fingerprint'; - return mockPostMessageCallback({ - data: { - newIssues: data.headIssues.filter( - (item) => !data.baseIssues.find((el) => el[key] === item[key]), - ), - resolvedIssues: data.baseIssues.filter( - (item) => !data.headIssues.find((el) => el[key] === item[key]), - ), - }, - }); - }, - }; - }); -}); - -describe('Codequality report store utils', () => { - let result; - - describe('parseCodeclimateMetrics', () => { - it('should parse the issues from codeclimate artifacts', () => { - [result] = parseCodeclimateMetrics(baseIssues, 'path'); - - expect(result.name).toEqual(baseIssues[0].check_name); - expect(result.path).toEqual(baseIssues[0].location.path); - 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' }; - - beforeEach(() => { - [result] = parseCodeclimateMetrics([issue], 'path'); - }); - - it('is parsed', () => { - expect(result.name).toEqual(issue.description); - }); - }); - - describe('when an issue has a path but no line', () => { - const issue = { description: 'Insecure Dependency', location: { path: 'Gemfile.lock' } }; - - beforeEach(() => { - [result] = parseCodeclimateMetrics([issue], 'path'); - }); - - it('is parsed', () => { - expect(result.name).toEqual(issue.description); - expect(result.path).toEqual(issue.location.path); - expect(result.urlPath).toEqual(`path/${issue.location.path}`); - }); - }); - - describe('when an issue has a line nested in positions', () => { - const issue = { - description: 'Insecure Dependency', - location: { - path: 'Gemfile.lock', - positions: { begin: { line: 84 } }, - }, - }; - - beforeEach(() => { - [result] = parseCodeclimateMetrics([issue], 'path'); - }); - - it('is parsed', () => { - expect(result.name).toEqual(issue.description); - expect(result.path).toEqual(issue.location.path); - expect(result.urlPath).toEqual( - `path/${issue.location.path}#L${issue.location.positions.begin.line}`, - ); - }); - }); - - describe('with an empty issue array', () => { - beforeEach(() => { - result = parseCodeclimateMetrics([], 'path'); - }); - - it('returns an empty array', () => { - expect(result).toEqual([]); - }); - }); - }); - - describe('doCodeClimateComparison', () => { - describe('when the comparison worker finds changed issues', () => { - beforeEach(async () => { - result = await doCodeClimateComparison(mockParsedHeadIssues, mockParsedBaseIssues); - }); - - it('returns the new and resolved issues', () => { - expect(result.resolvedIssues[0]).toEqual(mockParsedBaseIssues[0]); - expect(result.newIssues[0]).toEqual(mockParsedHeadIssues[0]); - }); - }); - - describe('when the comparison worker finds no changed issues', () => { - beforeEach(async () => { - result = await doCodeClimateComparison([], []); - }); - - it('returns the empty issue arrays', () => { - expect(result.newIssues).toEqual([]); - expect(result.resolvedIssues).toEqual([]); - }); - }); - - describe('when the comparison worker is given malformed data', () => { - it('rejects the promise', () => { - return expect(doCodeClimateComparison(null)).rejects.toEqual({}); - }); - }); - - describe('when the comparison worker encounters an error', () => { - it('rejects the promise and throws an error', () => { - return expect(doCodeClimateComparison([], null)).rejects.toThrow(); - }); - }); - }); -}); diff --git a/spec/frontend/reports/codequality_report/store/utils/codequality_parser_spec.js b/spec/frontend/reports/codequality_report/store/utils/codequality_parser_spec.js new file mode 100644 index 00000000000..ba95294ab0a --- /dev/null +++ b/spec/frontend/reports/codequality_report/store/utils/codequality_parser_spec.js @@ -0,0 +1,74 @@ +import { reportIssues, parsedReportIssues } from 'jest/reports/codequality_report/mock_data'; +import { parseCodeclimateMetrics } from '~/reports/codequality_report/store/utils/codequality_parser'; + +describe('Codequality report store utils', () => { + let result; + + describe('parseCodeclimateMetrics', () => { + 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' }; + + beforeEach(() => { + [result] = parseCodeclimateMetrics([issue], 'path'); + }); + + it('is parsed', () => { + expect(result.name).toEqual(issue.description); + }); + }); + + describe('when an issue has a path but no line', () => { + const issue = { description: 'Insecure Dependency', location: { path: 'Gemfile.lock' } }; + + beforeEach(() => { + [result] = parseCodeclimateMetrics([issue], 'path'); + }); + + it('is parsed', () => { + expect(result.name).toEqual(issue.description); + expect(result.path).toEqual(issue.location.path); + expect(result.urlPath).toEqual(`path/${issue.location.path}`); + }); + }); + + describe('when an issue has a line nested in positions', () => { + const issue = { + description: 'Insecure Dependency', + location: { + path: 'Gemfile.lock', + positions: { begin: { line: 84 } }, + }, + }; + + beforeEach(() => { + [result] = parseCodeclimateMetrics([issue], 'path'); + }); + + it('is parsed', () => { + expect(result.name).toEqual(issue.description); + expect(result.path).toEqual(issue.location.path); + expect(result.urlPath).toEqual( + `path/${issue.location.path}#L${issue.location.positions.begin.line}`, + ); + }); + }); + + describe('with an empty issue array', () => { + beforeEach(() => { + result = parseCodeclimateMetrics([], 'path'); + }); + + it('returns an empty array', () => { + expect(result).toEqual([]); + }); + }); + }); +}); diff --git a/spec/frontend/reports/grouped_test_report/grouped_test_reports_app_spec.js b/spec/frontend/reports/grouped_test_report/grouped_test_reports_app_spec.js index 55bb7dbe5c0..d29048d640c 100644 --- a/spec/frontend/reports/grouped_test_report/grouped_test_reports_app_spec.js +++ b/spec/frontend/reports/grouped_test_report/grouped_test_reports_app_spec.js @@ -279,9 +279,7 @@ describe('Grouped test reports app', () => { }); it('renders the recent failures count on the test case', () => { - expect(findIssueRecentFailures().text()).toBe( - 'Failed 8 times in master in the last 14 days', - ); + expect(findIssueRecentFailures().text()).toBe('Failed 8 times in main in the last 14 days'); }); }); diff --git a/spec/frontend/reports/grouped_test_report/store/mutations_spec.js b/spec/frontend/reports/grouped_test_report/store/mutations_spec.js index d8642a9b440..b2890d7285f 100644 --- a/spec/frontend/reports/grouped_test_report/store/mutations_spec.js +++ b/spec/frontend/reports/grouped_test_report/store/mutations_spec.js @@ -52,7 +52,7 @@ describe('Reports Store Mutations', () => { system_output: "Failure/Error: is_expected.to eq('gitlab')", recent_failures: { count: 4, - base_branch: 'master', + base_branch: 'main', }, }, ], diff --git a/spec/frontend/reports/mock_data/mock_data.js b/spec/frontend/reports/mock_data/mock_data.js index 68c7439df47..2599b0ac365 100644 --- a/spec/frontend/reports/mock_data/mock_data.js +++ b/spec/frontend/reports/mock_data/mock_data.js @@ -7,7 +7,7 @@ export const failedIssue = { "Failure/Error: is_expected.to eq(3)\n\n expected: 3\n got: -1\n\n (compared using ==)\n./spec/test_spec.rb:12:in `block (4 levels) in \u003ctop (required)\u003e'", recent_failures: { count: 3, - base_branch: 'master', + base_branch: 'main', }, }; diff --git a/spec/frontend/reports/mock_data/recent_failures_report.json b/spec/frontend/reports/mock_data/recent_failures_report.json index bc86d788ee2..c4a5fb78dcd 100644 --- a/spec/frontend/reports/mock_data/recent_failures_report.json +++ b/spec/frontend/reports/mock_data/recent_failures_report.json @@ -12,7 +12,7 @@ "system_output": "Failure/Error: is_expected.to eq(3)\n\n expected: 3\n got: -1\n\n (compared using ==)\n./spec/test_spec.rb:12:in `block (4 levels) in <top (required)>'", "recent_failures": { "count": 8, - "base_branch": "master" + "base_branch": "main" } }, { @@ -38,7 +38,7 @@ "execution_time": 0.000562, "recent_failures": { "count": 3, - "base_branch": "master" + "base_branch": "main" } } ], |