Commit cdd10bf7 authored by Alexander Turinske's avatar Alexander Turinske

Update code to use less CSS

- use humanize method to prepare strings
- remove unnecessary backticks
parent 17aa74e4
import { REPORT_TYPES } from 'ee/security_dashboard/store/constants'; import { REPORT_TYPES } from 'ee/security_dashboard/store/constants';
import { humanize } from '~/lib/utils/text_utility';
/** /**
* Takes the report type, that is not human-readable and converts it to be human-readable * Takes the report type, that is not human-readable and converts it to be human-readable
* @param {string} reportType that is not human-readable * @param {string} reportType that is not human-readable
* @returns {string} the conversion from REPORT_TYPES or a lowercase version without '_' in it to * @returns {string} a human-readable version of the report type
* be paired with the CSS class `text-capitalize`
*/ */
const convertReportType = reportType => { const convertReportType = reportType => {
if (!reportType) return ''; if (!reportType) return '';
const lowerCaseType = reportType.toLowerCase(); const lowerCaseType = reportType.toLowerCase();
return REPORT_TYPES[lowerCaseType] || lowerCaseType.split('_').join(' '); return REPORT_TYPES[lowerCaseType] || humanize(lowerCaseType);
}; };
export default convertReportType; export default convertReportType;
...@@ -112,7 +112,7 @@ export default { ...@@ -112,7 +112,7 @@ export default {
key: 'reportType', key: 'reportType',
class: this.reportTypeClass, class: this.reportTypeClass,
label: s__('Reports|Scanner'), label: s__('Reports|Scanner'),
thClass: `${commonThClass}`, thClass: commonThClass,
}, },
]; ];
}, },
......
...@@ -50,9 +50,9 @@ describe('security reports utils', () => { ...@@ -50,9 +50,9 @@ describe('security reports utils', () => {
['sast', 'SAST'], ['sast', 'SAST'],
['dependency_scanning', 'Dependency Scanning'], ['dependency_scanning', 'Dependency Scanning'],
['CONTAINER_SCANNING', 'Container Scanning'], ['CONTAINER_SCANNING', 'Container Scanning'],
['CUSTOM_SCANNER', 'custom scanner'], ['CUSTOM_SCANNER', 'Custom scanner'],
['mast', 'mast'], ['mast', 'Mast'],
['TAST', 'tast'], ['TAST', 'Tast'],
[undefined, ''], [undefined, ''],
])('converts the report type "%s" to the human-readable string "%s"', (input, output) => { ])('converts the report type "%s" to the human-readable string "%s"', (input, output) => {
expect(convertReportType(input)).toEqual(output); expect(convertReportType(input)).toEqual(output);
......
...@@ -194,7 +194,7 @@ describe('Vulnerability list component', () => { ...@@ -194,7 +194,7 @@ describe('Vulnerability list component', () => {
const cells = findCells('reportType'); const cells = findCells('reportType');
expect(cells.wrappers[0].text()).toBe('SAST'); expect(cells.wrappers[0].text()).toBe('SAST');
expect(cells.wrappers[1].text()).toBe('Dependency Scanning'); expect(cells.wrappers[1].text()).toBe('Dependency Scanning');
expect(cells.wrappers[2].text()).toBe('custom scanner without translation'); expect(cells.wrappers[2].text()).toBe('Custom scanner without translation');
expect(cells.wrappers[3].text()).toBe(''); expect(cells.wrappers[3].text()).toBe('');
}); });
}); });
......
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