Commit 931015ab authored by Vitaly Slobodin's avatar Vitaly Slobodin

Merge branch '327390-file-location-generic-report' into 'master'

Add file-location component for generic security reports

See merge request gitlab-org/gitlab!62653
parents 9728d78a 893aa265
......@@ -8,6 +8,7 @@ export const REPORT_TYPES = {
text: 'text',
value: 'value',
moduleLocation: 'module-location',
fileLocation: 'file-location',
};
const REPORT_TYPE_TO_COMPONENT_MAP = {
......@@ -18,6 +19,7 @@ const REPORT_TYPE_TO_COMPONENT_MAP = {
[REPORT_TYPES.text]: () => import('./value.vue'),
[REPORT_TYPES.value]: () => import('./value.vue'),
[REPORT_TYPES.moduleLocation]: () => import('./module_location.vue'),
[REPORT_TYPES.fileLocation]: () => import('./file_location.vue'),
};
export const getComponentNameForType = (reportType) =>
......
<script>
export default {
inheritAttrs: false,
props: {
fileName: {
type: String,
required: true,
},
lineStart: {
type: Number,
required: true,
},
lineEnd: {
type: Number,
required: false,
default: null,
},
},
computed: {
lineStr() {
return this.lineEnd ? `${this.lineStart}-${this.lineEnd}` : this.lineStart;
},
},
};
</script>
<template>
<span>{{ fileName }}:{{ lineStr }}</span>
</template>
......@@ -26,9 +26,14 @@ const TEST_DATA = {
value: 15,
},
[REPORT_TYPES.moduleName]: {
'module-name': 'foo.c',
moduleName: 'foo.c',
offset: 15,
},
[REPORT_TYPES.fileLocation]: {
fileName: 'index.js',
lineStart: '1',
lineEnd: '2',
},
};
describe('ee/vulnerabilities/components/generic_report/report_item.vue', () => {
......
import { shallowMount } from '@vue/test-utils';
import FileLocation from 'ee/vulnerabilities/components/generic_report/types/file_location.vue';
describe('ee/vulnerabilities/components/generic_report/types/file_location.vue', () => {
let wrapper;
describe.each`
fileName | lineStart | lineEnd | value
${'foo.c'} | ${4} | ${undefined} | ${'foo.c:4'}
${'bar.go'} | ${2} | ${5} | ${'bar.go:2-5'}
`('with value of type "$fieldType"', ({ fileName, lineStart, lineEnd, value }) => {
const createWrapper = () => {
return shallowMount(FileLocation, {
propsData: {
type: 'file-location',
fileName,
lineStart,
lineEnd,
},
});
};
beforeEach(() => {
wrapper = createWrapper();
});
afterEach(() => {
wrapper.destroy();
});
it(`renders ${fileName} file location`, () => {
expect(wrapper.text()).toBe(value.toString());
});
});
});
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