Commit f7dfe54e authored by mfluharty's avatar mfluharty

Add codequality report specs and changelog

Add spec for the codequality_report vue app
Add tests for the codequality_report vuex store
parent 8db24c42
---
title: Add code quality tab to pipeline view
merge_request: 21527
author:
type: added
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import { TEST_HOST } from 'helpers/test_constants';
import CodequalityReportApp from 'ee/codequality_report/codequality_report.vue';
import store from 'ee/codequality_report/store';
import { parsedIssues, unparsedIssues } from './mock_data';
import { mount } from '@vue/test-utils';
import waitForPromises from 'helpers/wait_for_promises';
import createFlash from '~/flash';
jest.mock('~/flash', () => jest.fn());
describe('Codequality report app', () => {
let wrapper;
let mock;
const codequalityReportDownloadPath = `${TEST_HOST}/codequality_report`;
const createComponent = (props = {}) => {
wrapper = mount(CodequalityReportApp, {
store,
propsData: {
codequalityReportDownloadPath,
blobPath: '/root/test-codequality/blob/feature-branch',
...props,
},
});
};
const findStatus = () => wrapper.find('.js-code-text');
const findSuccessIcon = () => wrapper.find('.js-ci-status-icon-success');
const findWarningIcon = () => wrapper.find('.js-ci-status-icon-warning');
beforeEach(() => {
mock = new MockAdapter(axios);
});
afterEach(() => {
wrapper.destroy();
mock.restore();
});
describe('when loading', () => {
beforeEach(() => {
createComponent();
});
it('shows a loading state', () => {
expect(findStatus().text()).toBe('Loading codeclimate report');
});
});
describe('on error', () => {
beforeEach(() => {
mock.onGet(codequalityReportDownloadPath).reply(500);
createComponent();
return waitForPromises();
});
it('shows a warning icon and error message', () => {
expect(findWarningIcon().exists()).toBe(true);
expect(findStatus().text()).toBe('Failed to load codeclimate report');
});
it('shows a flash message', () => {
expect(createFlash).toHaveBeenCalled();
});
});
describe('when there are codequality issues', () => {
beforeEach(() => {
mock.onGet(codequalityReportDownloadPath).reply(200, unparsedIssues);
createComponent();
return waitForPromises();
});
it('renders the codequality issues', () => {
const expectedIssueTotal = parsedIssues.length;
expect(wrapper.vm.$store.state.allCodequalityIssues).toEqual(parsedIssues);
expect(findStatus().text()).toBe(`Found ${expectedIssueTotal} code quality issues`);
expect(wrapper.findAll('.report-block-list-issue').length).toBe(expectedIssueTotal);
});
});
describe('when there are no codequality issues', () => {
beforeEach(() => {
mock.onGet(codequalityReportDownloadPath).reply(200, []);
createComponent();
return waitForPromises();
});
it('shows a message that no codequality issues were found', () => {
expect(wrapper.vm.$store.state.allCodequalityIssues).toEqual([]);
expect(findSuccessIcon().exists()).toBe(true);
expect(findStatus().text()).toBe('No code quality issues found');
expect(wrapper.findAll('.report-block-list-issue').length).toBe(0);
});
});
});
export const unparsedIssues = [
{
type: 'issue',
check_name: 'similar-code',
description: 'Similar blocks of code found in 2 locations. Consider refactoring.',
categories: ['Duplication'],
location: {
path: 'ee/spec/features/admin/geo/admin_geo_projects_spec.rb',
lines: {
begin: 152,
end: 158,
},
},
remediation_points: 230000,
other_locations: [
{
path: 'ee/spec/features/admin/geo/admin_geo_projects_spec.rb',
lines: {
begin: 134,
end: 140,
},
},
],
content: {
body:
"## Duplicated Code\n\nDuplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:\n\n> Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.\n\nWhen you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).\n\n## Tuning\n\n**This issue has a mass of 29**.\n\nWe set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.\n\nThe threshold configuration represents the minimum [mass](https://docs.codeclimate.com/docs/duplication#mass) a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.\n\nIf the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.\n\nSee [`codeclimate-duplication`'s documentation](https://docs.codeclimate.com/docs/duplication) for more information about tuning the mass threshold in your `.codeclimate.yml`.\n\n## Refactorings\n\n* [Extract Method](http://sourcemaking.com/refactoring/extract-method)\n* [Extract Class](http://sourcemaking.com/refactoring/extract-class)\n* [Form Template Method](http://sourcemaking.com/refactoring/form-template-method)\n* [Introduce Null Object](http://sourcemaking.com/refactoring/introduce-null-object)\n* [Pull Up Method](http://sourcemaking.com/refactoring/pull-up-method)\n* [Pull Up Field](http://sourcemaking.com/refactoring/pull-up-field)\n* [Substitute Algorithm](http://sourcemaking.com/refactoring/substitute-algorithm)\n\n## Further Reading\n\n* [Don't Repeat Yourself](http://c2.com/cgi/wiki?DontRepeatYourself) on the C2 Wiki\n* [Duplicated Code](http://sourcemaking.com/refactoring/duplicated-code) on SourceMaking\n* [Refactoring: Improving the Design of Existing Code](http://www.amazon.com/Refactoring-Improving-Design-Existing-Code/dp/0201485672) by Martin Fowler. _Duplicated Code_, p76\n",
},
fingerprint: 'eee6e62c2e1e0eaf901e747c935a7c63',
severity: 'minor',
engine_name: 'duplication',
},
{
type: 'issue',
check_name: 'similar-code',
description: 'Similar blocks of code found in 2 locations. Consider refactoring.',
categories: ['Duplication'],
location: {
path: 'ee/spec/finders/geo/lfs_object_registry_finder_spec.rb',
lines: {
begin: 491,
end: 497,
},
},
remediation_points: 230000,
other_locations: [
{
path: 'ee/spec/finders/geo/lfs_object_registry_finder_spec.rb',
lines: {
begin: 512,
end: 518,
},
},
],
content: {
body:
"## Duplicated Code\n\nDuplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:\n\n> Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.\n\nWhen you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).\n\n## Tuning\n\n**This issue has a mass of 29**.\n\nWe set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.\n\nThe threshold configuration represents the minimum [mass](https://docs.codeclimate.com/docs/duplication#mass) a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.\n\nIf the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.\n\nSee [`codeclimate-duplication`'s documentation](https://docs.codeclimate.com/docs/duplication) for more information about tuning the mass threshold in your `.codeclimate.yml`.\n\n## Refactorings\n\n* [Extract Method](http://sourcemaking.com/refactoring/extract-method)\n* [Extract Class](http://sourcemaking.com/refactoring/extract-class)\n* [Form Template Method](http://sourcemaking.com/refactoring/form-template-method)\n* [Introduce Null Object](http://sourcemaking.com/refactoring/introduce-null-object)\n* [Pull Up Method](http://sourcemaking.com/refactoring/pull-up-method)\n* [Pull Up Field](http://sourcemaking.com/refactoring/pull-up-field)\n* [Substitute Algorithm](http://sourcemaking.com/refactoring/substitute-algorithm)\n\n## Further Reading\n\n* [Don't Repeat Yourself](http://c2.com/cgi/wiki?DontRepeatYourself) on the C2 Wiki\n* [Duplicated Code](http://sourcemaking.com/refactoring/duplicated-code) on SourceMaking\n* [Refactoring: Improving the Design of Existing Code](http://www.amazon.com/Refactoring-Improving-Design-Existing-Code/dp/0201485672) by Martin Fowler. _Duplicated Code_, p76\n",
},
fingerprint: '60d0dd59a1cd7e6da18fdeb6c7fdd17f',
severity: 'minor',
engine_name: 'duplication',
},
{
type: 'issue',
check_name: 'similar-code',
description: 'Similar blocks of code found in 2 locations. Consider refactoring.',
categories: ['Duplication'],
location: {
path: 'ee/spec/finders/geo/lfs_object_registry_finder_spec.rb',
lines: {
begin: 512,
end: 518,
},
},
remediation_points: 230000,
other_locations: [
{
path: 'ee/spec/finders/geo/lfs_object_registry_finder_spec.rb',
lines: {
begin: 491,
end: 497,
},
},
],
content: {
body:
"## Duplicated Code\n\nDuplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:\n\n> Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.\n\nWhen you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).\n\n## Tuning\n\n**This issue has a mass of 29**.\n\nWe set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.\n\nThe threshold configuration represents the minimum [mass](https://docs.codeclimate.com/docs/duplication#mass) a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.\n\nIf the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.\n\nSee [`codeclimate-duplication`'s documentation](https://docs.codeclimate.com/docs/duplication) for more information about tuning the mass threshold in your `.codeclimate.yml`.\n\n## Refactorings\n\n* [Extract Method](http://sourcemaking.com/refactoring/extract-method)\n* [Extract Class](http://sourcemaking.com/refactoring/extract-class)\n* [Form Template Method](http://sourcemaking.com/refactoring/form-template-method)\n* [Introduce Null Object](http://sourcemaking.com/refactoring/introduce-null-object)\n* [Pull Up Method](http://sourcemaking.com/refactoring/pull-up-method)\n* [Pull Up Field](http://sourcemaking.com/refactoring/pull-up-field)\n* [Substitute Algorithm](http://sourcemaking.com/refactoring/substitute-algorithm)\n\n## Further Reading\n\n* [Don't Repeat Yourself](http://c2.com/cgi/wiki?DontRepeatYourself) on the C2 Wiki\n* [Duplicated Code](http://sourcemaking.com/refactoring/duplicated-code) on SourceMaking\n* [Refactoring: Improving the Design of Existing Code](http://www.amazon.com/Refactoring-Improving-Design-Existing-Code/dp/0201485672) by Martin Fowler. _Duplicated Code_, p76\n",
},
fingerprint: '60d0dd59a1cd7e6da18fdeb6c7fdd17f',
severity: 'minor',
engine_name: 'duplication',
},
];
export const parsedIssues = [
{
type: 'issue',
check_name: 'similar-code',
description: 'Similar blocks of code found in 2 locations. Consider refactoring.',
categories: ['Duplication'],
location: {
path: 'ee/spec/features/admin/geo/admin_geo_projects_spec.rb',
lines: { begin: 152, end: 158 },
},
remediation_points: 230000,
other_locations: [
{
path: 'ee/spec/features/admin/geo/admin_geo_projects_spec.rb',
lines: { begin: 134, end: 140 },
},
],
content: {
body:
"## Duplicated Code\n\nDuplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:\n\n> Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.\n\nWhen you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).\n\n## Tuning\n\n**This issue has a mass of 29**.\n\nWe set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.\n\nThe threshold configuration represents the minimum [mass](https://docs.codeclimate.com/docs/duplication#mass) a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.\n\nIf the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.\n\nSee [`codeclimate-duplication`'s documentation](https://docs.codeclimate.com/docs/duplication) for more information about tuning the mass threshold in your `.codeclimate.yml`.\n\n## Refactorings\n\n* [Extract Method](http://sourcemaking.com/refactoring/extract-method)\n* [Extract Class](http://sourcemaking.com/refactoring/extract-class)\n* [Form Template Method](http://sourcemaking.com/refactoring/form-template-method)\n* [Introduce Null Object](http://sourcemaking.com/refactoring/introduce-null-object)\n* [Pull Up Method](http://sourcemaking.com/refactoring/pull-up-method)\n* [Pull Up Field](http://sourcemaking.com/refactoring/pull-up-field)\n* [Substitute Algorithm](http://sourcemaking.com/refactoring/substitute-algorithm)\n\n## Further Reading\n\n* [Don't Repeat Yourself](http://c2.com/cgi/wiki?DontRepeatYourself) on the C2 Wiki\n* [Duplicated Code](http://sourcemaking.com/refactoring/duplicated-code) on SourceMaking\n* [Refactoring: Improving the Design of Existing Code](http://www.amazon.com/Refactoring-Improving-Design-Existing-Code/dp/0201485672) by Martin Fowler. _Duplicated Code_, p76\n",
},
fingerprint: 'eee6e62c2e1e0eaf901e747c935a7c63',
severity: 'minor',
engine_name: 'duplication',
name: 'Similar blocks of code found in 2 locations. Consider refactoring.',
path: 'ee/spec/features/admin/geo/admin_geo_projects_spec.rb',
line: 152,
urlPath:
'/root/test-codequality/blob/feature-branch/ee/spec/features/admin/geo/admin_geo_projects_spec.rb#L152',
},
{
type: 'issue',
check_name: 'similar-code',
description: 'Similar blocks of code found in 2 locations. Consider refactoring.',
categories: ['Duplication'],
location: {
path: 'ee/spec/finders/geo/lfs_object_registry_finder_spec.rb',
lines: { begin: 491, end: 497 },
},
remediation_points: 230000,
other_locations: [
{
path: 'ee/spec/finders/geo/lfs_object_registry_finder_spec.rb',
lines: { begin: 512, end: 518 },
},
],
content: {
body:
"## Duplicated Code\n\nDuplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:\n\n> Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.\n\nWhen you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).\n\n## Tuning\n\n**This issue has a mass of 29**.\n\nWe set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.\n\nThe threshold configuration represents the minimum [mass](https://docs.codeclimate.com/docs/duplication#mass) a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.\n\nIf the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.\n\nSee [`codeclimate-duplication`'s documentation](https://docs.codeclimate.com/docs/duplication) for more information about tuning the mass threshold in your `.codeclimate.yml`.\n\n## Refactorings\n\n* [Extract Method](http://sourcemaking.com/refactoring/extract-method)\n* [Extract Class](http://sourcemaking.com/refactoring/extract-class)\n* [Form Template Method](http://sourcemaking.com/refactoring/form-template-method)\n* [Introduce Null Object](http://sourcemaking.com/refactoring/introduce-null-object)\n* [Pull Up Method](http://sourcemaking.com/refactoring/pull-up-method)\n* [Pull Up Field](http://sourcemaking.com/refactoring/pull-up-field)\n* [Substitute Algorithm](http://sourcemaking.com/refactoring/substitute-algorithm)\n\n## Further Reading\n\n* [Don't Repeat Yourself](http://c2.com/cgi/wiki?DontRepeatYourself) on the C2 Wiki\n* [Duplicated Code](http://sourcemaking.com/refactoring/duplicated-code) on SourceMaking\n* [Refactoring: Improving the Design of Existing Code](http://www.amazon.com/Refactoring-Improving-Design-Existing-Code/dp/0201485672) by Martin Fowler. _Duplicated Code_, p76\n",
},
fingerprint: '60d0dd59a1cd7e6da18fdeb6c7fdd17f',
severity: 'minor',
engine_name: 'duplication',
name: 'Similar blocks of code found in 2 locations. Consider refactoring.',
path: 'ee/spec/finders/geo/lfs_object_registry_finder_spec.rb',
line: 491,
urlPath:
'/root/test-codequality/blob/feature-branch/ee/spec/finders/geo/lfs_object_registry_finder_spec.rb#L491',
},
{
type: 'issue',
check_name: 'similar-code',
description: 'Similar blocks of code found in 2 locations. Consider refactoring.',
categories: ['Duplication'],
location: {
path: 'ee/spec/finders/geo/lfs_object_registry_finder_spec.rb',
lines: { begin: 512, end: 518 },
},
remediation_points: 230000,
other_locations: [
{
path: 'ee/spec/finders/geo/lfs_object_registry_finder_spec.rb',
lines: { begin: 491, end: 497 },
},
],
content: {
body:
"## Duplicated Code\n\nDuplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:\n\n> Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.\n\nWhen you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).\n\n## Tuning\n\n**This issue has a mass of 29**.\n\nWe set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.\n\nThe threshold configuration represents the minimum [mass](https://docs.codeclimate.com/docs/duplication#mass) a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.\n\nIf the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.\n\nSee [`codeclimate-duplication`'s documentation](https://docs.codeclimate.com/docs/duplication) for more information about tuning the mass threshold in your `.codeclimate.yml`.\n\n## Refactorings\n\n* [Extract Method](http://sourcemaking.com/refactoring/extract-method)\n* [Extract Class](http://sourcemaking.com/refactoring/extract-class)\n* [Form Template Method](http://sourcemaking.com/refactoring/form-template-method)\n* [Introduce Null Object](http://sourcemaking.com/refactoring/introduce-null-object)\n* [Pull Up Method](http://sourcemaking.com/refactoring/pull-up-method)\n* [Pull Up Field](http://sourcemaking.com/refactoring/pull-up-field)\n* [Substitute Algorithm](http://sourcemaking.com/refactoring/substitute-algorithm)\n\n## Further Reading\n\n* [Don't Repeat Yourself](http://c2.com/cgi/wiki?DontRepeatYourself) on the C2 Wiki\n* [Duplicated Code](http://sourcemaking.com/refactoring/duplicated-code) on SourceMaking\n* [Refactoring: Improving the Design of Existing Code](http://www.amazon.com/Refactoring-Improving-Design-Existing-Code/dp/0201485672) by Martin Fowler. _Duplicated Code_, p76\n",
},
fingerprint: '60d0dd59a1cd7e6da18fdeb6c7fdd17f',
severity: 'minor',
engine_name: 'duplication',
name: 'Similar blocks of code found in 2 locations. Consider refactoring.',
path: 'ee/spec/finders/geo/lfs_object_registry_finder_spec.rb',
line: 512,
urlPath:
'/root/test-codequality/blob/feature-branch/ee/spec/finders/geo/lfs_object_registry_finder_spec.rb#L512',
},
];
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import * as actions from 'ee/codequality_report/store/actions';
import * as types from 'ee/codequality_report/store/mutation_types';
import { TEST_HOST } from 'helpers/test_constants';
import testAction from 'helpers/vuex_action_helper';
import createFlash from '~/flash';
import { unparsedIssues, parsedIssues } from '../mock_data';
jest.mock('~/flash');
describe('Codequality report actions', () => {
let mock;
let state;
const endpoint = `${TEST_HOST}/codequality_report.json`;
const defaultState = {
endpoint,
};
beforeEach(() => {
mock = new MockAdapter(axios);
state = defaultState;
});
afterEach(() => {
mock.restore();
});
describe('setEndpoint', () => {
it('sets the endpoint', done => {
testAction(
actions.setEndpoint,
'endpoint',
state,
[{ type: types.SET_ENDPOINT, payload: 'endpoint' }],
[],
done,
);
});
});
describe('setBlobPath', () => {
it('sets the blob path', done => {
testAction(
actions.setBlobPath,
'blobPath',
state,
[{ type: types.SET_BLOB_PATH, payload: 'blobPath' }],
[],
done,
);
});
});
describe('setPage', () => {
it('sets the page number', done => {
testAction(actions.setPage, 12, state, [{ type: types.SET_PAGE, payload: 12 }], [], done);
});
});
describe('requestReport', () => {
it('sets the loading flag', done => {
testAction(actions.requestReport, null, state, [{ type: types.REQUEST_REPORT }], [], done);
});
});
describe('receiveReportSuccess', () => {
it('parses the list of issues from the report', done => {
testAction(
actions.receiveReportSuccess,
unparsedIssues,
{ blobPath: '/root/test-codequality/blob/feature-branch', ...state },
[{ type: types.RECEIVE_REPORT_SUCCESS, payload: parsedIssues }],
[],
done,
);
});
});
describe('receiveReportError', () => {
it('accepts a report error', done => {
testAction(
actions.receiveReportError,
'error',
state,
[{ type: types.RECEIVE_REPORT_ERROR, payload: 'error' }],
[],
done,
);
});
});
describe('fetchReport', () => {
beforeEach(() => {
mock.onGet(endpoint).replyOnce(200, unparsedIssues);
});
it('fetches the report', done => {
testAction(
actions.fetchReport,
null,
{ blobPath: 'blah', ...state },
[],
[{ type: 'requestReport' }, { type: 'receiveReportSuccess', payload: unparsedIssues }],
done,
);
});
it('shows a flash message when there is an error', done => {
testAction(
actions.fetchReport,
'error',
state,
[],
[{ type: 'requestReport' }, { type: 'receiveReportError', payload: new Error() }],
() => {
expect(createFlash).toHaveBeenCalledWith(
'There was an error fetching the codequality report.',
);
done();
},
);
});
it('shows an error when blob path is missing', done => {
testAction(
actions.fetchReport,
null,
state,
[],
[{ type: 'requestReport' }, { type: 'receiveReportError', payload: new Error() }],
() => {
expect(createFlash).toHaveBeenCalledWith(
'There was an error fetching the codequality report.',
);
done();
},
);
});
});
});
import * as getters from 'ee/codequality_report/store/getters';
import { parsedIssues } from '../mock_data';
describe('Codequality report getters', () => {
let state;
const defaultState = {
allCodequalityIssues: parsedIssues,
};
beforeEach(() => {
state = defaultState;
});
describe('codequalityIssues', () => {
it('gets the current page of issues', () => {
expect(
getters.codequalityIssues({ pageInfo: { page: 1, perPage: 2, total: 3 }, ...state }),
).toEqual(parsedIssues.slice(0, 2));
expect(
getters.codequalityIssues({ pageInfo: { page: 2, perPage: 2, total: 3 }, ...state }),
).toEqual(parsedIssues.slice(2, 3));
});
});
describe('codequalityIssueTotal', () => {
it('gets the total number of codequality issues', () => {
expect(getters.codequalityIssueTotal(state)).toBe(parsedIssues.length);
});
});
});
import * as types from 'ee/codequality_report/store/mutation_types';
import mutations from 'ee/codequality_report/store/mutations';
import { parsedIssues } from '../mock_data';
describe('Codequality report mutations', () => {
let state;
const defaultState = {
pageInfo: {},
};
beforeEach(() => {
state = defaultState;
});
describe('set endpoint', () => {
it('should set endpoint', () => {
mutations[types.SET_ENDPOINT](state, 'endpoint');
expect(state.endpoint).toBe('endpoint');
});
});
describe('set blob path', () => {
it('should set blob path', () => {
mutations[types.SET_BLOB_PATH](state, 'blobPath');
expect(state.blobPath).toBe('blobPath');
});
});
describe('set page', () => {
it('should set page', () => {
mutations[types.SET_PAGE](state, 4);
expect(state.pageInfo.page).toBe(4);
});
});
describe('request report', () => {
it('should set the loading flag', () => {
mutations[types.REQUEST_REPORT](state);
expect(state.isLoadingCodequality).toBe(true);
});
});
describe('receive report success', () => {
it('should set issue info and clear the loading flag', () => {
mutations[types.RECEIVE_REPORT_SUCCESS](state, parsedIssues);
expect(state.isLoadingCodequality).toBe(false);
expect(state.allCodequalityIssues).toBe(parsedIssues);
expect(state.pageInfo.total).toBe(parsedIssues.length);
});
});
describe('receive report error', () => {
it('should set error info and clear the loading flag', () => {
mutations[types.RECEIVE_REPORT_ERROR](state, new Error());
expect(state.isLoadingCodequality).toBe(false);
expect(state.loadingCodequalityFailed).toBe(true);
expect(state.allCodequalityIssues).toEqual([]);
expect(state.codeQualityError).toEqual(new Error());
expect(state.pageInfo.total).toBe(0);
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment