debian-mirror-gitlab/spec/frontend/diffs/components/diff_code_quality_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
2.2 KiB
JavaScript
Raw Normal View History

2022-08-13 15:12:31 +05:30
import { GlIcon } from '@gitlab/ui';
import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper';
import DiffCodeQuality from '~/diffs/components/diff_code_quality.vue';
2023-03-04 22:38:38 +05:30
import { SEVERITY_CLASSES, SEVERITY_ICONS } from '~/ci/reports/codequality_report/constants';
import { NEW_CODE_QUALITY_FINDINGS } from '~/diffs/i18n';
2022-08-13 15:12:31 +05:30
import { multipleFindingsArr } from '../mock_data/diff_code_quality';
let wrapper;
const findIcon = () => wrapper.findComponent(GlIcon);
2023-03-04 22:38:38 +05:30
const findHeading = () => wrapper.findByTestId(`diff-codequality-findings-heading`);
2022-08-13 15:12:31 +05:30
describe('DiffCodeQuality', () => {
afterEach(() => {
wrapper.destroy();
});
const createWrapper = (codeQuality, mountFunction = mountExtended) => {
return mountFunction(DiffCodeQuality, {
propsData: {
expandedLines: [],
codeQuality,
},
});
};
it('hides details and throws hideCodeQualityFindings event on close click', async () => {
wrapper = createWrapper(multipleFindingsArr);
expect(wrapper.findByTestId('diff-codequality').exists()).toBe(true);
await wrapper.findByTestId('diff-codequality-close').trigger('click');
expect(wrapper.emitted('hideCodeQualityFindings').length).toBe(1);
});
2023-03-04 22:38:38 +05:30
it('renders heading and correct amount of list items for codequality array and their description', async () => {
2022-08-13 15:12:31 +05:30
wrapper = createWrapper(multipleFindingsArr);
2023-03-04 22:38:38 +05:30
expect(findHeading().text()).toEqual(NEW_CODE_QUALITY_FINDINGS);
2022-08-13 15:12:31 +05:30
2023-03-04 22:38:38 +05:30
const listItems = wrapper.findAll('li');
expect(wrapper.findAll('li').length).toBe(5);
2022-08-13 15:12:31 +05:30
listItems.wrappers.map((e, i) => {
2023-03-04 22:38:38 +05:30
return expect(e.text()).toContain(
`${multipleFindingsArr[i].severity} - ${multipleFindingsArr[i].description}`,
);
2022-08-13 15:12:31 +05:30
});
});
it.each`
severity
${'info'}
${'minor'}
${'major'}
${'critical'}
${'blocker'}
${'unknown'}
`('shows icon for $severity degradation', ({ severity }) => {
wrapper = createWrapper([{ severity }], shallowMountExtended);
expect(findIcon().exists()).toBe(true);
expect(findIcon().attributes()).toMatchObject({
class: `codequality-severity-icon ${SEVERITY_CLASSES[severity]}`,
name: SEVERITY_ICONS[severity],
size: '12',
});
});
});