debian-mirror-gitlab/spec/frontend/reports/codequality_report/grouped_codequality_reports_app_spec.js

153 lines
4.4 KiB
JavaScript
Raw Normal View History

2020-07-28 23:09:34 +05:30
import { mount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import CodequalityIssueBody from '~/reports/codequality_report/components/codequality_issue_body.vue';
2021-03-11 19:13:27 +05:30
import GroupedCodequalityReportsApp from '~/reports/codequality_report/grouped_codequality_reports_app.vue';
2020-11-24 15:15:51 +05:30
import { getStoreConfig } from '~/reports/codequality_report/store';
2021-10-27 15:23:28 +05:30
import { STATUS_NOT_FOUND } from '~/reports/constants';
2021-06-08 01:23:25 +05:30
import { parsedReportIssues } from './mock_data';
2020-07-28 23:09:34 +05:30
const localVue = createLocalVue();
localVue.use(Vuex);
describe('Grouped code quality reports app', () => {
let wrapper;
let mockStore;
2020-11-24 15:15:51 +05:30
const PATHS = {
codequalityHelpPath: 'codequality_help.html',
baseBlobPath: 'base/blob/path/',
headBlobPath: 'head/blob/path/',
};
2020-07-28 23:09:34 +05:30
const mountComponent = (props = {}) => {
2021-03-11 19:13:27 +05:30
wrapper = mount(GroupedCodequalityReportsApp, {
2020-07-28 23:09:34 +05:30
store: mockStore,
localVue,
propsData: {
2020-11-24 15:15:51 +05:30
...PATHS,
2020-07-28 23:09:34 +05:30
...props,
},
});
};
const findWidget = () => wrapper.find('.js-codequality-widget');
const findIssueBody = () => wrapper.find(CodequalityIssueBody);
beforeEach(() => {
2020-11-24 15:15:51 +05:30
const { state, ...storeConfig } = getStoreConfig();
mockStore = new Vuex.Store({
...storeConfig,
actions: {
setPaths: () => {},
fetchReports: () => {},
},
state: {
...state,
...PATHS,
},
});
2020-07-28 23:09:34 +05:30
mountComponent();
});
afterEach(() => {
wrapper.destroy();
});
describe('when it is loading reports', () => {
beforeEach(() => {
mockStore.state.isLoading = true;
});
it('should render loading text', () => {
2021-11-18 22:05:49 +05:30
expect(findWidget().text()).toEqual('Loading Code quality report');
2020-07-28 23:09:34 +05:30
});
});
describe('when base and head reports are loaded and compared', () => {
describe('with no issues', () => {
beforeEach(() => {
mockStore.state.newIssues = [];
mockStore.state.resolvedIssues = [];
});
it('renders no changes text', () => {
expect(findWidget().text()).toEqual('No changes to code quality');
});
});
describe('with issues', () => {
describe('with new issues', () => {
beforeEach(() => {
2021-06-08 01:23:25 +05:30
mockStore.state.newIssues = parsedReportIssues.newIssues;
2020-07-28 23:09:34 +05:30
mockStore.state.resolvedIssues = [];
});
it('renders summary text', () => {
2021-11-18 22:05:49 +05:30
expect(findWidget().text()).toContain('Code quality degraded');
2020-07-28 23:09:34 +05:30
});
it('renders custom codequality issue body', () => {
2021-06-08 01:23:25 +05:30
expect(findIssueBody().props('issue')).toEqual(parsedReportIssues.newIssues[0]);
2020-07-28 23:09:34 +05:30
});
});
describe('with resolved issues', () => {
beforeEach(() => {
mockStore.state.newIssues = [];
2021-06-08 01:23:25 +05:30
mockStore.state.resolvedIssues = parsedReportIssues.resolvedIssues;
2020-07-28 23:09:34 +05:30
});
it('renders summary text', () => {
2021-11-18 22:05:49 +05:30
expect(findWidget().text()).toContain('Code quality improved');
2020-07-28 23:09:34 +05:30
});
it('renders custom codequality issue body', () => {
2021-06-08 01:23:25 +05:30
expect(findIssueBody().props('issue')).toEqual(parsedReportIssues.resolvedIssues[0]);
2020-07-28 23:09:34 +05:30
});
});
describe('with new and resolved issues', () => {
beforeEach(() => {
2021-06-08 01:23:25 +05:30
mockStore.state.newIssues = parsedReportIssues.newIssues;
mockStore.state.resolvedIssues = parsedReportIssues.resolvedIssues;
2020-07-28 23:09:34 +05:30
});
it('renders summary text', () => {
expect(findWidget().text()).toContain(
2021-11-18 22:05:49 +05:30
'Code quality scanning detected 2 changes in merged results',
2020-07-28 23:09:34 +05:30
);
});
it('renders custom codequality issue body', () => {
2021-06-08 01:23:25 +05:30
expect(findIssueBody().props('issue')).toEqual(parsedReportIssues.newIssues[0]);
2020-07-28 23:09:34 +05:30
});
});
});
});
describe('on error', () => {
beforeEach(() => {
mockStore.state.hasError = true;
});
it('renders error text', () => {
2021-11-18 22:05:49 +05:30
expect(findWidget().text()).toContain('Failed to load Code quality report');
2020-07-28 23:09:34 +05:30
});
it('does not render a help icon', () => {
2021-03-08 18:12:59 +05:30
expect(findWidget().find('[data-testid="question-icon"]').exists()).toBe(false);
2020-07-28 23:09:34 +05:30
});
2021-10-27 15:23:28 +05:30
describe('when base report was not found', () => {
beforeEach(() => {
mockStore.state.status = STATUS_NOT_FOUND;
});
it('renders a help icon with more information', () => {
expect(findWidget().find('[data-testid="question-icon"]').exists()).toBe(true);
});
});
2020-07-28 23:09:34 +05:30
});
});