Commit 356c5edd authored by Scott Hampton's avatar Scott Hampton

Merge branch '208407-remove-empty-string-for-severity' into 'master'

Use v-if instead of passing empty string for severity

See merge request gitlab-org/gitlab!53218
parents d260958e 56a5a6d1
...@@ -53,7 +53,7 @@ export default { ...@@ -53,7 +53,7 @@ export default {
return this.alert?.prometheusAlert?.humanizedText; return this.alert?.prometheusAlert?.humanizedText;
}, },
severity() { severity() {
return this.alert?.severity || ''; return this.alert?.severity;
}, },
}, },
classes: [ classes: [
...@@ -71,7 +71,7 @@ export default { ...@@ -71,7 +71,7 @@ export default {
<div v-if="alert" :class="$options.classes" data-testid="alert"> <div v-if="alert" :class="$options.classes" data-testid="alert">
<gl-sprintf :message="$options.translations.alertText"> <gl-sprintf :message="$options.translations.alertText">
<template #severity> <template #severity>
<severity-badge :severity="severity" class="gl-display-inline" /> <severity-badge v-if="severity" :severity="severity" class="gl-display-inline" />
</template> </template>
<template #startedAt> <template #startedAt>
<span v-gl-tooltip :title="tooltipTitle(alert.startedAt)"> <span v-gl-tooltip :title="tooltipTitle(alert.startedAt)">
......
...@@ -43,9 +43,6 @@ export default { ...@@ -43,9 +43,6 @@ export default {
computed: { computed: {
...mapState(['dashboardType']), ...mapState(['dashboardType']),
...mapState('vulnerabilities', ['selectedVulnerabilities']), ...mapState('vulnerabilities', ['selectedVulnerabilities']),
severity() {
return this.vulnerability.severity || ' ';
},
vulnerabilityIdentifier() { vulnerabilityIdentifier() {
return getPrimaryIdentifier(this.vulnerability.identifiers, 'external_type'); return getPrimaryIdentifier(this.vulnerability.identifiers, 'external_type');
}, },
...@@ -126,7 +123,11 @@ export default { ...@@ -126,7 +123,11 @@ export default {
<div class="table-section section-15"> <div class="table-section section-15">
<div class="table-mobile-header" role="rowheader">{{ s__('Reports|Severity') }}</div> <div class="table-mobile-header" role="rowheader">{{ s__('Reports|Severity') }}</div>
<div class="table-mobile-content"> <div class="table-mobile-content">
<severity-badge :severity="severity" class="text-right text-md-left" /> <severity-badge
v-if="vulnerability.severity"
:severity="vulnerability.severity"
class="text-right text-md-left"
/>
</div> </div>
</div> </div>
......
...@@ -22,7 +22,7 @@ export default { ...@@ -22,7 +22,7 @@ export default {
return Object.keys(SEVERITY_CLASS_NAME_MAP).includes(this.severityKey); return Object.keys(SEVERITY_CLASS_NAME_MAP).includes(this.severityKey);
}, },
severityKey() { severityKey() {
return this.severity.toLowerCase(); return this.severity?.toLowerCase();
}, },
className() { className() {
return SEVERITY_CLASS_NAME_MAP[this.severityKey]; return SEVERITY_CLASS_NAME_MAP[this.severityKey];
......
...@@ -23,6 +23,8 @@ describe('Environment Alert', () => { ...@@ -23,6 +23,8 @@ describe('Environment Alert', () => {
}); });
}; };
const findSeverityBadge = () => wrapper.find(SeverityBadge);
beforeEach(() => { beforeEach(() => {
factory(); factory();
}); });
...@@ -59,14 +61,17 @@ describe('Environment Alert', () => { ...@@ -59,14 +61,17 @@ describe('Environment Alert', () => {
expect(link.attributes('href')).toBe('/alert/details'); expect(link.attributes('href')).toBe('/alert/details');
}); });
it('should show a severity badge', () => { it('should show a severity badge with the correct severity', () => {
expect(wrapper.find(SeverityBadge).props('severity')).toBe('CRITICAL'); const badge = findSeverityBadge();
expect(badge.exists()).toBe(true);
expect(badge.props('severity')).toBe('CRITICAL');
}); });
}); });
describe('has no alert', () => { describe('has no alert', () => {
it('should display nothing', () => { it('should display nothing', () => {
expect(wrapper.find('[data-testid="alert"]').exists()).toBe(false); expect(wrapper.find('[data-testid="alert"]').exists()).toBe(false);
expect(findSeverityBadge().exists()).toBe(false);
}); });
}); });
}); });
...@@ -6,6 +6,7 @@ import { VULNERABILITY_MODAL_ID } from 'ee/vue_shared/security_reports/component ...@@ -6,6 +6,7 @@ import { VULNERABILITY_MODAL_ID } from 'ee/vue_shared/security_reports/component
import createStore from 'ee/security_dashboard/store'; import createStore from 'ee/security_dashboard/store';
import { DASHBOARD_TYPES } from 'ee/security_dashboard/store/constants'; import { DASHBOARD_TYPES } from 'ee/security_dashboard/store/constants';
import { trimText } from 'helpers/text_helper'; import { trimText } from 'helpers/text_helper';
import SeverityBadge from 'ee/vue_shared/security_reports/components/severity_badge.vue';
import { BV_SHOW_MODAL } from '~/lib/utils/constants'; import { BV_SHOW_MODAL } from '~/lib/utils/constants';
import mockDataVulnerabilities from '../store/modules/vulnerabilities/data/mock_data_vulnerabilities'; import mockDataVulnerabilities from '../store/modules/vulnerabilities/data/mock_data_vulnerabilities';
...@@ -41,6 +42,7 @@ describe('Security Dashboard Table Row', () => { ...@@ -41,6 +42,7 @@ describe('Security Dashboard Table Row', () => {
const findAllIssueCreated = () => wrapper.findAll('[data-testid="issues-icon"]'); const findAllIssueCreated = () => wrapper.findAll('[data-testid="issues-icon"]');
const hasSelectedClass = () => wrapper.classes('gl-bg-blue-50'); const hasSelectedClass = () => wrapper.classes('gl-bg-blue-50');
const findCheckbox = () => wrapper.find(GlFormCheckbox); const findCheckbox = () => wrapper.find(GlFormCheckbox);
const findSeverityBadge = () => wrapper.find(SeverityBadge);
describe('when loading', () => { describe('when loading', () => {
beforeEach(() => { beforeEach(() => {
...@@ -51,9 +53,8 @@ describe('Security Dashboard Table Row', () => { ...@@ -51,9 +53,8 @@ describe('Security Dashboard Table Row', () => {
expect(findLoader().exists()).toBeTruthy(); expect(findLoader().exists()).toBeTruthy();
}); });
it('should render a ` ` for severity', () => { it('should not render the severity', () => {
expect(wrapper.vm.severity).toEqual(' '); expect(findSeverityBadge().exists()).toBe(false);
expect(findContent(0).text()).toEqual('');
}); });
it('should render a `` for the report type and scanner', () => { it('should render a `` for the report type and scanner', () => {
...@@ -78,7 +79,7 @@ describe('Security Dashboard Table Row', () => { ...@@ -78,7 +79,7 @@ describe('Security Dashboard Table Row', () => {
}); });
it('should render the severity', () => { it('should render the severity', () => {
expect(findContent(0).text().toLowerCase()).toContain(vulnerability.severity); expect(findSeverityBadge().text().toLowerCase()).toBe(vulnerability.severity);
}); });
it('should render the identifier cell', () => { it('should render the identifier cell', () => {
......
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