Commit 3ca43788 authored by Alexander Turinske's avatar Alexander Turinske

Fix missing styling

- break out string into two strings
- update tests
parent eb978c52
...@@ -12,28 +12,48 @@ export default { ...@@ -12,28 +12,48 @@ export default {
required: true, required: true,
}, },
}, },
computed: {
shouldShowCountMessage() {
return !this.message.status && Boolean(this.message.countMessage);
},
},
methods: { methods: {
getSeverityClass(severity) { getSeverityClass(severity) {
return SEVERITY_CLASS_NAME_MAP[severity]; return SEVERITY_CLASS_NAME_MAP[severity];
}, },
}, },
slotNames: ['critical', 'high', 'other'],
spacingClasses: {
critical: 'gl-pl-4',
high: 'gl-px-2',
other: 'gl-px-2',
},
}; };
</script> </script>
<template> <template>
<span> <span>
<gl-sprintf :message="message.message"> <gl-sprintf :message="message.message">
<template #count="{content}"> <template #total="{content}">
<strong>{{ content }}</strong> <strong>{{ content }}</strong>
</template> </template>
<template v-for="slotName in ['critical', 'high', 'other']" #[slotName]="{content}">
<span :key="slotName">
<strong v-if="Boolean(message[slotName])" :class="getSeverityClass(slotName)">
{{ content }}
</strong>
<span v-else>{{ content }}</span>
</span>
</template>
</gl-sprintf> </gl-sprintf>
<span v-if="shouldShowCountMessage" class="gl-font-sm">
<gl-sprintf :message="message.countMessage">
<template v-for="slotName in $options.slotNames" #[slotName]="{content}">
<span :key="slotName">
<strong
v-if="message[slotName] > 0"
:class="[getSeverityClass(slotName), $options.spacingClasses[slotName]]"
>
{{ content }}
</strong>
<span v-else :class="$options.spacingClasses[slotName]">
{{ content }}
</span>
</span>
</template>
</gl-sprintf>
</span>
</span> </span>
</template> </template>
...@@ -555,7 +555,6 @@ export default { ...@@ -555,7 +555,6 @@ export default {
<template v-if="hasCoverageFuzzingReports"> <template v-if="hasCoverageFuzzingReports">
<summary-row <summary-row
:summary="groupedCoverageFuzzingText.message"
:status-icon="coverageFuzzingStatusIcon" :status-icon="coverageFuzzingStatusIcon"
:popover-options="coverageFuzzingPopover" :popover-options="coverageFuzzingPopover"
class="js-coverage-fuzzing-widget" class="js-coverage-fuzzing-widget"
......
...@@ -9,6 +9,29 @@ import { __, n__, sprintf } from '~/locale'; ...@@ -9,6 +9,29 @@ import { __, n__, sprintf } from '~/locale';
export const findIssueIndex = (issues, issue) => export const findIssueIndex = (issues, issue) =>
issues.findIndex(el => el.project_fingerprint === issue.project_fingerprint); issues.findIndex(el => el.project_fingerprint === issue.project_fingerprint);
const createCountMessage = ({ critical, high, other, total }) => {
const otherMessage = n__('%d Other', '%d Others', other);
const countMessage = __(
'%{criticalStart}%{critical} Critical%{criticalEnd} %{highStart}%{high} High%{highEnd} and %{otherStart}%{otherMessage}%{otherEnd}',
);
return total ? sprintf(countMessage, { critical, high, otherMessage }) : '';
};
const createStatusMessage = ({ reportType, status, total }) => {
const vulnMessage = n__('vulnerability', 'vulnerabilities', total);
let message;
if (status) {
message = __('%{reportType} %{status}');
} else if (!total) {
message = __('%{reportType} detected %{totalStart}no%{totalEnd} vulnerabilities.');
} else {
message = __(
'%{reportType} detected %{totalStart}%{total}%{totalEnd} potential %{vulnMessage}',
);
}
return sprintf(message, { reportType, status, total, vulnMessage });
};
/** /**
* Takes an object of options and returns the object with an externalized string representing * Takes an object of options and returns the object with an externalized string representing
* the critical, high, and other severity vulnerabilities for a given report. * the critical, high, and other severity vulnerabilities for a given report.
...@@ -27,35 +50,15 @@ export const groupedTextBuilder = ({ ...@@ -27,35 +50,15 @@ export const groupedTextBuilder = ({
other = 0, other = 0,
} = {}) => { } = {}) => {
const total = critical + high + other; const total = critical + high + other;
const vulnMessage = n__('vulnerability', 'vulnerabilities', total);
const otherMessage = n__('%d Other', '%d Others', other);
let message;
if (status) {
message = __('%{reportType} %{status}');
} else if (!total) {
message = __('%{reportType} detected %{countStart}no%{countEnd} vulnerabilities.');
} else {
message = __(
'%{reportType} detected %{countStart}%{total}%{countEnd} potential %{vulnMessage} %{criticalStart}%{critical} critical%{criticalEnd} %{highStart}%{high} high%{highEnd} and %{otherStart}%{otherMessage}%{otherEnd}',
);
}
return { return {
message: sprintf(message, { countMessage: createCountMessage({ critical, high, other, total }),
critical, message: createStatusMessage({ reportType, status, total }),
high,
otherMessage,
reportType,
status,
total,
vulnMessage,
}).replace(/\s\s+/g, ' '),
critical, critical,
high, high,
other, other,
status, status,
total,
}; };
}; };
......
...@@ -140,7 +140,7 @@ describe('ee merge request widget options', () => { ...@@ -140,7 +140,7 @@ describe('ee merge request widget options', () => {
`${SAST_SELECTOR} .report-block-list-issue-description`, `${SAST_SELECTOR} .report-block-list-issue-description`,
).textContent, ).textContent,
), ),
).toEqual('SAST detected 1 potential vulnerability 1 critical 0 high and 0 Others'); ).toEqual('SAST detected 1 potential vulnerability 1 Critical 0 High and 0 Others');
done(); done();
}); });
}); });
...@@ -235,8 +235,8 @@ describe('ee merge request widget options', () => { ...@@ -235,8 +235,8 @@ describe('ee merge request widget options', () => {
`${DEPENDENCY_SCANNING_SELECTOR} .report-block-list-issue-description`, `${DEPENDENCY_SCANNING_SELECTOR} .report-block-list-issue-description`,
).textContent, ).textContent,
), ),
).toContain( ).toEqual(
'Dependency scanning detected 2 potential vulnerabilities 1 critical 1 high and 0 Others', 'Dependency scanning detected 2 potential vulnerabilities 1 Critical 1 High and 0 Others',
); );
done(); done();
}); });
...@@ -663,7 +663,7 @@ describe('ee merge request widget options', () => { ...@@ -663,7 +663,7 @@ describe('ee merge request widget options', () => {
).textContent, ).textContent,
), ),
).toEqual( ).toEqual(
'Container scanning detected 2 potential vulnerabilities 1 critical 1 high and 0 Others', 'Container scanning detected 2 potential vulnerabilities 1 Critical 1 High and 0 Others',
); );
done(); done();
}); });
...@@ -734,10 +734,12 @@ describe('ee merge request widget options', () => { ...@@ -734,10 +734,12 @@ describe('ee merge request widget options', () => {
it('should render provided data', done => { it('should render provided data', done => {
setImmediate(() => { setImmediate(() => {
expect( expect(
findExtendedSecurityWidget() trimText(
.querySelector(`${DAST_SELECTOR} .report-block-list-issue-description`) findExtendedSecurityWidget().querySelector(
.textContent.trim(), `${DAST_SELECTOR} .report-block-list-issue-description`,
).toContain('DAST detected 1 potential vulnerability'); ).textContent,
),
).toEqual('DAST detected 1 potential vulnerability 1 Critical 0 High and 0 Others');
done(); done();
}); });
}); });
...@@ -810,10 +812,14 @@ describe('ee merge request widget options', () => { ...@@ -810,10 +812,14 @@ describe('ee merge request widget options', () => {
it('should render provided data', done => { it('should render provided data', done => {
setImmediate(() => { setImmediate(() => {
expect( expect(
findExtendedSecurityWidget() trimText(
.querySelector(`${COVERAGE_FUZZING_SELECTOR} .report-block-list-issue-description`) findExtendedSecurityWidget().querySelector(
.textContent.trim(), `${COVERAGE_FUZZING_SELECTOR} .report-block-list-issue-description`,
).toContain('Coverage fuzzing detected 2 potential vulnerabilities'); ).textContent,
),
).toEqual(
'Coverage fuzzing detected 2 potential vulnerabilities 1 Critical 1 High and 0 Others',
);
done(); done();
}); });
}); });
...@@ -889,7 +895,7 @@ describe('ee merge request widget options', () => { ...@@ -889,7 +895,7 @@ describe('ee merge request widget options', () => {
).textContent, ).textContent,
), ),
).toEqual( ).toEqual(
'Secret scanning detected 2 potential vulnerabilities 1 critical 1 high and 0 Others', 'Secret scanning detected 2 potential vulnerabilities 1 Critical 1 High and 0 Others',
); );
done(); done();
}); });
......
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Severity Summary given the message {"critical": 0, "high": 1, "message": "Security scanning detected %{countStart}1%{countEnd} potential vulnerability %{criticalStart}0 critical%{criticalEnd} %{highStart}1 high%{highEnd} and %{otherStart}0 Others%{otherEnd}", "other": 0, "status": ""} interpolates correctly 1`] = ` exports[`Severity Summary given the message {"countMessage": "%{criticalStart}0 Critical%{criticalEnd} %{highStart}1 High%{highEnd} and %{otherStart}0 Others%{otherEnd}", "critical": 0, "high": 1, "message": "Security scanning detected %{totalStart}1%{totalEnd} potential vulnerability", "other": 0, "status": "", "total": 1} interpolates correctly 1`] = `
<span> <span>
Security scanning detected Security scanning detected
<strong> <strong>
1 1
</strong> </strong>
potential vulnerability potential vulnerability
<span> <span
class="gl-font-sm"
>
<span> <span>
0 critical <span
class="gl-pl-4"
>
0 Critical
</span>
</span> </span>
</span>
<span>
<span> <strong
<strong class="text-danger-600 gl-px-2"
class="text-danger-600" >
>
1 high
</strong> 1 High
</span>
and </strong>
<span> </span>
and
<span> <span>
0 Others <span
class="gl-px-2"
>
0 Others
</span>
</span> </span>
</span> </span>
</span> </span>
`; `;
exports[`Severity Summary given the message {"critical": 1, "high": 0, "message": "Security scanning detected %{countStart}1%{countEnd} potential vulnerability %{criticalStart}1 critical%{criticalEnd} %{highStart}0 high%{highEnd} and %{otherStart}0 Others%{otherEnd}", "other": 0, "status": ""} interpolates correctly 1`] = ` exports[`Severity Summary given the message {"countMessage": "%{criticalStart}1 Critical%{criticalEnd} %{highStart}0 High%{highEnd} and %{otherStart}0 Others%{otherEnd}", "critical": 1, "high": 0, "message": "Security scanning detected %{totalStart}1%{totalEnd} potential vulnerability", "other": 0, "status": "", "total": 1} interpolates correctly 1`] = `
<span> <span>
Security scanning detected Security scanning detected
<strong> <strong>
1 1
</strong> </strong>
potential vulnerability potential vulnerability
<span> <span
<strong class="gl-font-sm"
class="text-danger-800" >
> <span>
<strong
1 critical class="text-danger-800 gl-pl-4"
>
</strong> 1 Critical
</span>
</strong>
<span> </span>
<span> <span>
0 high <span
class="gl-px-2"
>
0 High
</span>
</span> </span>
</span> and
and
<span>
<span> <span>
0 Others <span
class="gl-px-2"
>
0 Others
</span>
</span> </span>
</span> </span>
</span> </span>
`; `;
exports[`Severity Summary given the message {"critical": 1, "high": 2, "message": "Security scanning detected %{countStart}3%{countEnd} potential vulnerabilities %{criticalStart}1 critical%{criticalEnd} %{highStart}2 high%{highEnd} and %{otherStart}0 Others%{otherEnd}", "other": 0, "status": ""} interpolates correctly 1`] = ` exports[`Severity Summary given the message {"countMessage": "%{criticalStart}1 Critical%{criticalEnd} %{highStart}2 High%{highEnd} and %{otherStart}0 Others%{otherEnd}", "critical": 1, "high": 2, "message": "Security scanning detected %{totalStart}3%{totalEnd} potential vulnerabilities", "other": 0, "status": "", "total": 3} interpolates correctly 1`] = `
<span> <span>
Security scanning detected Security scanning detected
<strong> <strong>
3 3
</strong> </strong>
potential vulnerabilities potential vulnerabilities
<span> <span
<strong class="gl-font-sm"
class="text-danger-800" >
> <span>
<strong
1 critical class="text-danger-800 gl-pl-4"
>
</strong> 1 Critical
</span>
</strong>
<span> </span>
<strong
class="text-danger-600" <span>
> <strong
class="text-danger-600 gl-px-2"
2 high >
</strong> 2 High
</span>
and </strong>
<span> </span>
and
<span> <span>
0 Others <span
class="gl-px-2"
>
0 Others
</span>
</span> </span>
</span> </span>
</span> </span>
`; `;
exports[`Severity Summary given the message {"message": ""} interpolates correctly 1`] = `<span />`; exports[`Severity Summary given the message {"message": ""} interpolates correctly 1`] = `
<span>
<!---->
</span>
`;
exports[`Severity Summary given the message {"message": "foo"} interpolates correctly 1`] = ` exports[`Severity Summary given the message {"message": "foo"} interpolates correctly 1`] = `
<span> <span>
foo foo
<!---->
</span> </span>
`; `;
...@@ -144,9 +144,11 @@ describe('Grouped security reports app', () => { ...@@ -144,9 +144,11 @@ describe('Grouped security reports app', () => {
it('renders error state', () => { it('renders error state', () => {
expect(wrapper.vm.$el.querySelector('.gl-spinner')).toBeNull(); expect(wrapper.vm.$el.querySelector('.gl-spinner')).toBeNull();
expect(wrapper.vm.$el.querySelector('.js-code-text').textContent.trim()).toEqual( expect(
'Security scanning failed loading any results', wrapper.vm.$el
); .querySelector('[data-testid="report-section-code-text"]')
.textContent.trim(),
).toEqual('Security scanning failed loading any results');
expect(wrapper.vm.$el.querySelector('.js-collapse-btn').textContent.trim()).toEqual( expect(wrapper.vm.$el.querySelector('.js-collapse-btn').textContent.trim()).toEqual(
'Expand', 'Expand',
...@@ -185,9 +187,11 @@ describe('Grouped security reports app', () => { ...@@ -185,9 +187,11 @@ describe('Grouped security reports app', () => {
it('renders loading summary text + spinner', () => { it('renders loading summary text + spinner', () => {
expect(wrapper.vm.$el.querySelector('.gl-spinner')).not.toBeNull(); expect(wrapper.vm.$el.querySelector('.gl-spinner')).not.toBeNull();
expect(wrapper.vm.$el.querySelector('.js-code-text').textContent.trim()).toEqual( expect(
'Security scanning is loading', wrapper.vm.$el
); .querySelector('[data-testid="report-section-code-text"]')
.textContent.trim(),
).toEqual('Security scanning is loading');
expect(wrapper.vm.$el.querySelector('.js-collapse-btn').textContent.trim()).toEqual( expect(wrapper.vm.$el.querySelector('.js-collapse-btn').textContent.trim()).toEqual(
'Expand', 'Expand',
...@@ -228,9 +232,11 @@ describe('Grouped security reports app', () => { ...@@ -228,9 +232,11 @@ describe('Grouped security reports app', () => {
expect(wrapper.vm.$el.querySelector('.gl-spinner')).toBeNull(); expect(wrapper.vm.$el.querySelector('.gl-spinner')).toBeNull();
// Renders the summary text // Renders the summary text
expect(wrapper.vm.$el.querySelector('.js-code-text').textContent.trim()).toEqual( expect(
'Security scanning detected no vulnerabilities.', wrapper.vm.$el
); .querySelector('[data-testid="report-section-code-text"]')
.textContent.trim(),
).toEqual('Security scanning detected no vulnerabilities.');
// Renders Sast result // Renders Sast result
expect(trimText(wrapper.vm.$el.textContent)).toContain('SAST detected no vulnerabilities.'); expect(trimText(wrapper.vm.$el.textContent)).toContain('SAST detected no vulnerabilities.');
...@@ -276,8 +282,12 @@ describe('Grouped security reports app', () => { ...@@ -276,8 +282,12 @@ describe('Grouped security reports app', () => {
expect(wrapper.vm.$el.querySelector('.gl-spinner')).toBeNull(); expect(wrapper.vm.$el.querySelector('.gl-spinner')).toBeNull();
// Renders the summary text // Renders the summary text
expect(wrapper.vm.$el.querySelector('.js-code-text').textContent.trim()).toContain( expect(
'Security scanning detected 10 potential vulnerabilities', trimText(
wrapper.vm.$el.querySelector('[data-testid="report-section-code-text"]').textContent,
),
).toEqual(
'Security scanning detected 10 potential vulnerabilities 6 Critical 4 High and 0 Others',
); );
// Renders the expand button // Renders the expand button
...@@ -287,25 +297,27 @@ describe('Grouped security reports app', () => { ...@@ -287,25 +297,27 @@ describe('Grouped security reports app', () => {
// Renders Sast result // Renders Sast result
expect(trimText(wrapper.vm.$el.textContent)).toContain( expect(trimText(wrapper.vm.$el.textContent)).toContain(
'SAST detected 1 potential vulnerability', 'SAST detected 1 potential vulnerability 1 Critical 0 High and 0 Others',
); );
// Renders DSS result // Renders DSS result
expect(trimText(wrapper.vm.$el.textContent)).toContain( expect(trimText(wrapper.vm.$el.textContent)).toContain(
'Dependency scanning detected 2 potential vulnerabilities', 'Dependency scanning detected 2 potential vulnerabilities 1 Critical 1 High and 0 Others',
); );
// Renders container scanning result // Renders container scanning result
expect(wrapper.vm.$el.textContent).toContain( expect(trimText(wrapper.vm.$el.textContent)).toContain(
'Container scanning detected 2 potential vulnerabilities', 'Container scanning detected 2 potential vulnerabilities 1 Critical 1 High and 0 Others',
); );
// Renders DAST result // Renders DAST result
expect(wrapper.vm.$el.textContent).toContain('DAST detected 1 potential vulnerability'); expect(trimText(wrapper.vm.$el.textContent)).toContain(
'DAST detected 1 potential vulnerability 1 Critical 0 High and 0 Others',
);
// Renders container scanning result // Renders container scanning result
expect(wrapper.vm.$el.textContent).toContain( expect(trimText(wrapper.vm.$el.textContent)).toContain(
'Coverage fuzzing detected 2 potential vulnerabilities', 'Coverage fuzzing detected 2 potential vulnerabilities 1 Critical 1 High and 0 Others',
); );
}); });
...@@ -426,7 +438,9 @@ describe('Grouped security reports app', () => { ...@@ -426,7 +438,9 @@ describe('Grouped security reports app', () => {
}); });
it('should display the correct numbers of vulnerabilities', () => { it('should display the correct numbers of vulnerabilities', () => {
expect(wrapper.text()).toContain('Container scanning detected 2 potential vulnerabilities'); expect(trimText(wrapper.text())).toContain(
'Container scanning detected 2 potential vulnerabilities 1 Critical 1 High and 0 Others',
);
}); });
}); });
...@@ -454,8 +468,8 @@ describe('Grouped security reports app', () => { ...@@ -454,8 +468,8 @@ describe('Grouped security reports app', () => {
}); });
it('should display the correct numbers of vulnerabilities', () => { it('should display the correct numbers of vulnerabilities', () => {
expect(wrapper.vm.$el.textContent).toContain( expect(trimText(wrapper.vm.$el.textContent)).toContain(
'Dependency scanning detected 2 potential vulnerabilities', 'Dependency scanning detected 2 potential vulnerabilities 1 Critical 1 High and 0 Others',
); );
}); });
}); });
...@@ -485,7 +499,9 @@ describe('Grouped security reports app', () => { ...@@ -485,7 +499,9 @@ describe('Grouped security reports app', () => {
}); });
it('should display the correct numbers of vulnerabilities', () => { it('should display the correct numbers of vulnerabilities', () => {
expect(wrapper.vm.$el.textContent).toContain('DAST detected 1 potential vulnerability'); expect(trimText(wrapper.vm.$el.textContent)).toContain(
'DAST detected 1 potential vulnerability 1 Critical 0 High and 0 Others',
);
}); });
it('shows the scanned URLs count and opens a modal', async () => { it('shows the scanned URLs count and opens a modal', async () => {
...@@ -565,7 +581,9 @@ describe('Grouped security reports app', () => { ...@@ -565,7 +581,9 @@ describe('Grouped security reports app', () => {
}); });
it('should display the correct numbers of vulnerabilities', () => { it('should display the correct numbers of vulnerabilities', () => {
expect(wrapper.text()).toContain('Secret scanning detected 2 potential vulnerabilities'); expect(trimText(wrapper.text())).toContain(
'Secret scanning detected 2 potential vulnerabilities 1 Critical 1 High and 0 Others',
);
}); });
}); });
...@@ -602,7 +620,9 @@ describe('Grouped security reports app', () => { ...@@ -602,7 +620,9 @@ describe('Grouped security reports app', () => {
}); });
it('should display the correct numbers of vulnerabilities', () => { it('should display the correct numbers of vulnerabilities', () => {
expect(wrapper.vm.$el.textContent).toContain('SAST detected 1 potential vulnerability'); expect(trimText(wrapper.vm.$el.textContent)).toContain(
'SAST detected 1 potential vulnerability 1 Critical 0 High and 0 Others',
);
}); });
}); });
......
...@@ -30,11 +30,13 @@ describe('groupedSastText', () => { ...@@ -30,11 +30,13 @@ describe('groupedSastText', () => {
const result = getters.groupedSastText(sast); const result = getters.groupedSastText(sast);
expect(result).toStrictEqual({ expect(result).toStrictEqual({
countMessage: '',
critical: 0, critical: 0,
high: 0, high: 0,
message: 'SAST detected %{countStart}no%{countEnd} vulnerabilities.', message: 'SAST detected %{totalStart}no%{totalEnd} vulnerabilities.',
other: 0, other: 0,
status: '', status: '',
total: 0,
}); });
}); });
}); });
......
...@@ -116,32 +116,37 @@ describe('security reports utils', () => { ...@@ -116,32 +116,37 @@ describe('security reports utils', () => {
const other = 7; const other = 7;
it.each` it.each`
vulnerabilities | message vulnerabilities | message | countMessage
${undefined} | ${' detected %{countStart}no%{countEnd} vulnerabilities.'} ${undefined} | ${' detected %{totalStart}no%{totalEnd} vulnerabilities.'} | ${''}
${{ critical }} | ${` detected %{countStart}2%{countEnd} potential vulnerabilities %{criticalStart}2 critical%{criticalEnd} %{highStart}0 high%{highEnd} and %{otherStart}0 Others%{otherEnd}`} ${{ critical }} | ${` detected %{totalStart}2%{totalEnd} potential vulnerabilities`} | ${`%{criticalStart}2 Critical%{criticalEnd} %{highStart}0 High%{highEnd} and %{otherStart}0 Others%{otherEnd}`}
${{ high }} | ${` detected %{countStart}4%{countEnd} potential vulnerabilities %{criticalStart}0 critical%{criticalEnd} %{highStart}4 high%{highEnd} and %{otherStart}0 Others%{otherEnd}`} ${{ high }} | ${` detected %{totalStart}4%{totalEnd} potential vulnerabilities`} | ${`%{criticalStart}0 Critical%{criticalEnd} %{highStart}4 High%{highEnd} and %{otherStart}0 Others%{otherEnd}`}
${{ other }} | ${` detected %{countStart}7%{countEnd} potential vulnerabilities %{criticalStart}0 critical%{criticalEnd} %{highStart}0 high%{highEnd} and %{otherStart}7 Others%{otherEnd}`} ${{ other }} | ${` detected %{totalStart}7%{totalEnd} potential vulnerabilities`} | ${`%{criticalStart}0 Critical%{criticalEnd} %{highStart}0 High%{highEnd} and %{otherStart}7 Others%{otherEnd}`}
${{ critical, high }} | ${` detected %{countStart}6%{countEnd} potential vulnerabilities %{criticalStart}2 critical%{criticalEnd} %{highStart}4 high%{highEnd} and %{otherStart}0 Others%{otherEnd}`} ${{ critical, high }} | ${` detected %{totalStart}6%{totalEnd} potential vulnerabilities`} | ${`%{criticalStart}2 Critical%{criticalEnd} %{highStart}4 High%{highEnd} and %{otherStart}0 Others%{otherEnd}`}
${{ critical, other }} | ${` detected %{countStart}9%{countEnd} potential vulnerabilities %{criticalStart}2 critical%{criticalEnd} %{highStart}0 high%{highEnd} and %{otherStart}7 Others%{otherEnd}`} ${{ critical, other }} | ${` detected %{totalStart}9%{totalEnd} potential vulnerabilities`} | ${`%{criticalStart}2 Critical%{criticalEnd} %{highStart}0 High%{highEnd} and %{otherStart}7 Others%{otherEnd}`}
${{ high, other }} | ${` detected %{countStart}11%{countEnd} potential vulnerabilities %{criticalStart}0 critical%{criticalEnd} %{highStart}4 high%{highEnd} and %{otherStart}7 Others%{otherEnd}`} ${{ high, other }} | ${` detected %{totalStart}11%{totalEnd} potential vulnerabilities`} | ${`%{criticalStart}0 Critical%{criticalEnd} %{highStart}4 High%{highEnd} and %{otherStart}7 Others%{otherEnd}`}
${{ critical, high, other }} | ${` detected %{countStart}13%{countEnd} potential vulnerabilities %{criticalStart}2 critical%{criticalEnd} %{highStart}4 high%{highEnd} and %{otherStart}7 Others%{otherEnd}`} ${{ critical, high, other }} | ${` detected %{totalStart}13%{totalEnd} potential vulnerabilities`} | ${`%{criticalStart}2 Critical%{criticalEnd} %{highStart}4 High%{highEnd} and %{otherStart}7 Others%{otherEnd}`}
`('should build the message as "$message"', ({ vulnerabilities, message }) => { `('should build the message as "$message"', ({ vulnerabilities, message, countMessage }) => {
expect(groupedTextBuilder(vulnerabilities).message).toEqual(message); expect(groupedTextBuilder(vulnerabilities).message).toEqual(message);
expect(groupedTextBuilder(vulnerabilities).countMessage).toEqual(countMessage);
}); });
it.each` it.each`
vulnerabilities | message vulnerabilities | message | countMessage
${{ critical: 1 }} | ${` detected %{countStart}1%{countEnd} potential vulnerability %{criticalStart}1 critical%{criticalEnd} %{highStart}0 high%{highEnd} and %{otherStart}0 Others%{otherEnd}`} ${{ critical: 1 }} | ${` detected %{totalStart}1%{totalEnd} potential vulnerability`} | ${`%{criticalStart}1 Critical%{criticalEnd} %{highStart}0 High%{highEnd} and %{otherStart}0 Others%{otherEnd}`}
${{ high: 1 }} | ${` detected %{countStart}1%{countEnd} potential vulnerability %{criticalStart}0 critical%{criticalEnd} %{highStart}1 high%{highEnd} and %{otherStart}0 Others%{otherEnd}`} ${{ high: 1 }} | ${` detected %{totalStart}1%{totalEnd} potential vulnerability`} | ${`%{criticalStart}0 Critical%{criticalEnd} %{highStart}1 High%{highEnd} and %{otherStart}0 Others%{otherEnd}`}
${{ other: 1 }} | ${` detected %{countStart}1%{countEnd} potential vulnerability %{criticalStart}0 critical%{criticalEnd} %{highStart}0 high%{highEnd} and %{otherStart}1 Other%{otherEnd}`} ${{ other: 1 }} | ${` detected %{totalStart}1%{totalEnd} potential vulnerability`} | ${`%{criticalStart}0 Critical%{criticalEnd} %{highStart}0 High%{highEnd} and %{otherStart}1 Other%{otherEnd}`}
`('should handle single vulnerabilities for "$message"', ({ vulnerabilities, message }) => { `(
expect(groupedTextBuilder(vulnerabilities).message).toEqual(message); 'should handle single vulnerabilities for "$message"',
}); ({ vulnerabilities, message, countMessage }) => {
expect(groupedTextBuilder(vulnerabilities).message).toEqual(message);
expect(groupedTextBuilder(vulnerabilities).countMessage).toEqual(countMessage);
},
);
it('should pass through the report type', () => { it('should pass through the report type', () => {
const reportType = 'HAL'; const reportType = 'HAL';
expect(groupedTextBuilder({ reportType }).message).toEqual( expect(groupedTextBuilder({ reportType }).message).toEqual(
'HAL detected %{countStart}no%{countEnd} vulnerabilities.', 'HAL detected %{totalStart}no%{totalEnd} vulnerabilities.',
); );
}); });
...@@ -149,11 +154,13 @@ describe('security reports utils', () => { ...@@ -149,11 +154,13 @@ describe('security reports utils', () => {
const reportType = 'HAL'; const reportType = 'HAL';
const status = 'is loading'; const status = 'is loading';
expect(groupedTextBuilder({ reportType, status })).toEqual({ expect(groupedTextBuilder({ reportType, status })).toEqual({
countMessage: '',
critical: 0, critical: 0,
high: 0, high: 0,
message: 'HAL is loading', message: 'HAL is loading',
other: 0, other: 0,
status: 'is loading', status: 'is loading',
total: 0,
}); });
}); });
}); });
...@@ -193,7 +200,7 @@ describe('security reports utils', () => { ...@@ -193,7 +200,7 @@ describe('security reports utils', () => {
${[{ severity: LOW }, { severity: MEDIUM }]} | ${{ critical: 0, high: 0, other: 2 }} ${[{ severity: LOW }, { severity: MEDIUM }]} | ${{ critical: 0, high: 0, other: 2 }}
${[{ severity: CRITICAL }, { severity: HIGH }]} | ${{ critical: 1, high: 1, other: 0 }} ${[{ severity: CRITICAL }, { severity: HIGH }]} | ${{ critical: 1, high: 1, other: 0 }}
${[{ severity: CRITICAL }, { severity: LOW }]} | ${{ critical: 1, high: 0, other: 1 }} ${[{ severity: CRITICAL }, { severity: LOW }]} | ${{ critical: 1, high: 0, other: 1 }}
`('should count the vulnerabilities correctly', ({ vulnerabilities, response }) => { `('should total the vulnerabilities correctly', ({ vulnerabilities, response }) => {
expect(countVulnerabilities(vulnerabilities)).toEqual(response); expect(countVulnerabilities(vulnerabilities)).toEqual(response);
}); });
}); });
...@@ -223,11 +230,13 @@ describe('security reports utils', () => { ...@@ -223,11 +230,13 @@ describe('security reports utils', () => {
const result = groupedReportText(report, reportType, errorMessage, loadingMessage); const result = groupedReportText(report, reportType, errorMessage, loadingMessage);
expect(result).toStrictEqual({ expect(result).toStrictEqual({
countMessage: '',
critical: 0, critical: 0,
high: 0, high: 0,
message: 'dummyReport detected %{countStart}no%{countEnd} vulnerabilities.', message: 'dummyReport detected %{totalStart}no%{totalEnd} vulnerabilities.',
other: 0, other: 0,
status: '', status: '',
total: 0,
}); });
}); });
}); });
......
...@@ -450,6 +450,9 @@ msgstr "" ...@@ -450,6 +450,9 @@ msgstr ""
msgid "%{count} total weight" msgid "%{count} total weight"
msgstr "" msgstr ""
msgid "%{criticalStart}%{critical} Critical%{criticalEnd} %{highStart}%{high} High%{highEnd} and %{otherStart}%{otherMessage}%{otherEnd}"
msgstr ""
msgid "%{dashboard_path} could not be found." msgid "%{dashboard_path} could not be found."
msgstr "" msgstr ""
...@@ -718,10 +721,10 @@ msgstr "" ...@@ -718,10 +721,10 @@ msgstr ""
msgid "%{reportType} %{status}" msgid "%{reportType} %{status}"
msgstr "" msgstr ""
msgid "%{reportType} detected %{countStart}%{total}%{countEnd} potential %{vulnMessage} %{criticalStart}%{critical} critical%{criticalEnd} %{highStart}%{high} high%{highEnd} and %{otherStart}%{otherMessage}%{otherEnd}" msgid "%{reportType} detected %{totalStart}%{total}%{totalEnd} potential %{vulnMessage}"
msgstr "" msgstr ""
msgid "%{reportType} detected %{countStart}no%{countEnd} vulnerabilities." msgid "%{reportType} detected %{totalStart}no%{totalEnd} vulnerabilities."
msgstr "" msgstr ""
msgid "%{retryButtonStart}Try again%{retryButtonEnd} or %{newFileButtonStart}attach a new file%{newFileButtonEnd}." msgid "%{retryButtonStart}Try again%{retryButtonEnd} or %{newFileButtonStart}attach a new file%{newFileButtonEnd}."
......
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