Commit ae7134ae authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch '356318-fix-vulnerability-list-clearing-incorrectly' into 'master'

Fix vulnerability list clearing when already-selected filter is clicked

See merge request gitlab-org/gitlab!83243
parents 7147cdd6 654ea526
...@@ -179,11 +179,11 @@ export default { ...@@ -179,11 +179,11 @@ export default {
} }
}, },
sort(newSort, oldSort) { sort(newSort, oldSort) {
// Clear out the vulnerabilities so that the skeleton loader is shown.
this.vulnerabilities = [];
// Anything that changes the querystring will also trigger this watcher (because sort is // Anything that changes the querystring will also trigger this watcher (because sort is
// recomputed), so we need to check that the sort has changed before we reset the paging. // recomputed), so we need to check that the sort has changed before we reset the paging.
if (newSort.sortBy !== oldSort.sortBy || newSort.sortDesc !== oldSort.sortDesc) { if (newSort.sortBy !== oldSort.sortBy || newSort.sortDesc !== oldSort.sortDesc) {
// Clear out the vulnerabilities so that the skeleton loader is shown.
this.vulnerabilities = [];
this.resetPaging(); this.resetPaging();
} }
}, },
......
...@@ -63,7 +63,7 @@ export const generateVulnerabilities = () => [ ...@@ -63,7 +63,7 @@ export const generateVulnerabilities = () => [
severity: 'critical', severity: 'critical',
state: 'DISMISSED', state: 'DISMISSED',
reportType: 'SAST', reportType: 'SAST',
resolvedOnDefaultBranch: true, resolvedOnDefaultBranch: false,
location: { location: {
image: image:
'registry.gitlab.com/groulot/container-scanning-test/main:5f21de6956aee99ddb68ae49498662d9872f50ff', 'registry.gitlab.com/groulot/container-scanning-test/main:5f21de6956aee99ddb68ae49498662d9872f50ff',
...@@ -77,17 +77,39 @@ export const generateVulnerabilities = () => [ ...@@ -77,17 +77,39 @@ export const generateVulnerabilities = () => [
vendor: 'GitLab', vendor: 'GitLab',
}, },
issueLinks: { issueLinks: {
nodes: [{ id: 'issue-1', issue: { id: 'issue-1', iid: 15 } }], nodes: [
{
id: 'issue-1',
issue: {
id: 'issue-1',
iid: 15,
webUrl: 'url',
webPath: 'path',
title: 'title',
state: 'state',
resolvedOnDefaultBranch: true,
},
},
],
}, },
externalIssueLinks: { externalIssueLinks: {
nodes: [{ id: 'issue-1', issue: { iid: 15, externalTracker: 'jira' } }], nodes: [
}, {
id: 'issue-1',
issue: { iid: 15, externalTracker: 'jira', resolvedOnDefaultBranch: true },
},
],
},
vulnerabilityPath: 'path',
userNotesCount: 1,
__typename: 'Vulnerability', __typename: 'Vulnerability',
}, },
{ {
id: 'id_1', id: 'id_1',
detectedAt: '2020-07-22T19:31:24Z', detectedAt: '2020-07-22T19:31:24Z',
resolvedOnDefaultBranch: false,
hasSolutions: false, hasSolutions: false,
issueLinks: [],
identifiers: [ identifiers: [
{ {
externalType: 'gemnasium', externalType: 'gemnasium',
...@@ -108,15 +130,16 @@ export const generateVulnerabilities = () => [ ...@@ -108,15 +130,16 @@ export const generateVulnerabilities = () => [
id: 'project-2', id: 'project-2',
nameWithNamespace: 'Administrator / Vulnerability reports', nameWithNamespace: 'Administrator / Vulnerability reports',
}, },
scanner: { scanner: { id: 'scanner-2', vendor: 'GitLab' },
id: 'scanner-2', vulnerabilityPath: '#',
vendor: 'GitLab', userNotesCount: 0,
},
__typename: 'Vulnerability', __typename: 'Vulnerability',
}, },
{ {
id: 'id_2', id: 'id_2',
detectedAt: '2020-08-22T20:00:12Z', detectedAt: '2020-08-22T20:00:12Z',
resolvedOnDefaultBranch: false,
issueLinks: [],
identifiers: [], identifiers: [],
title: 'Vulnerability 2', title: 'Vulnerability 2',
severity: 'high', severity: 'high',
...@@ -133,11 +156,18 @@ export const generateVulnerabilities = () => [ ...@@ -133,11 +156,18 @@ export const generateVulnerabilities = () => [
id: 'scanner-3', id: 'scanner-3',
vendor: 'My Custom Scanner', vendor: 'My Custom Scanner',
}, },
vulnerabilityPath: 'path',
userNotesCount: 2,
__typename: 'Vulnerability', __typename: 'Vulnerability',
}, },
{ {
id: 'id_3', id: 'id_3',
title: 'Vulnerability 3', title: 'Vulnerability 3',
detectedAt: new Date(),
resolvedOnDefaultBranch: true,
issueLinks: [],
identifiers: [],
reportType: '',
severity: 'high', severity: 'high',
state: 'DETECTED', state: 'DETECTED',
location: { location: {
...@@ -147,7 +177,9 @@ export const generateVulnerabilities = () => [ ...@@ -147,7 +177,9 @@ export const generateVulnerabilities = () => [
id: 'project-4', id: 'project-4',
nameWithNamespace: 'Mixed Vulnerabilities / Rails App', nameWithNamespace: 'Mixed Vulnerabilities / Rails App',
}, },
scanner: {}, scanner: { id: 'scanner-3', vendor: '' },
vulnerabilityPath: 'path',
userNotesCount: 3,
__typename: 'Vulnerability', __typename: 'Vulnerability',
}, },
{ {
...@@ -155,12 +187,19 @@ export const generateVulnerabilities = () => [ ...@@ -155,12 +187,19 @@ export const generateVulnerabilities = () => [
title: 'Vulnerability 4', title: 'Vulnerability 4',
severity: 'critical', severity: 'critical',
state: 'DISMISSED', state: 'DISMISSED',
detectedAt: new Date(),
resolvedOnDefaultBranch: true,
issueLinks: [],
identifiers: [],
reportType: 'DAST',
location: {}, location: {},
project: { project: {
id: 'project-5', id: 'project-5',
nameWithNamespace: 'Administrator / Security reports', nameWithNamespace: 'Administrator / Security reports',
}, },
scanner: {}, scanner: { id: 'scanner-4', vendor: 'GitLab' },
vulnerabilityPath: 'path',
userNotesCount: 4,
__typename: 'Vulnerability', __typename: 'Vulnerability',
}, },
{ {
...@@ -168,6 +207,11 @@ export const generateVulnerabilities = () => [ ...@@ -168,6 +207,11 @@ export const generateVulnerabilities = () => [
title: 'Vulnerability 5', title: 'Vulnerability 5',
severity: 'high', severity: 'high',
state: 'DETECTED', state: 'DETECTED',
detectedAt: new Date(),
resolvedOnDefaultBranch: false,
issueLinks: [],
identifiers: [],
reportType: 'DEPENDENCY_SCANNING',
location: { location: {
path: '/v1/trees', path: '/v1/trees',
}, },
...@@ -175,7 +219,9 @@ export const generateVulnerabilities = () => [ ...@@ -175,7 +219,9 @@ export const generateVulnerabilities = () => [
id: 'project-6', id: 'project-6',
nameWithNamespace: 'Administrator / Security reports', nameWithNamespace: 'Administrator / Security reports',
}, },
scanner: {}, scanner: { id: 'scanner-5', vendor: 'GitLab' },
vulnerabilityPath: 'path',
userNotesCount: 5,
__typename: 'Vulnerability', __typename: 'Vulnerability',
}, },
]; ];
......
...@@ -11,6 +11,7 @@ import waitForPromises from 'helpers/wait_for_promises'; ...@@ -11,6 +11,7 @@ import waitForPromises from 'helpers/wait_for_promises';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { FIELDS } from 'ee/security_dashboard/components/shared/vulnerability_report/constants'; import { FIELDS } from 'ee/security_dashboard/components/shared/vulnerability_report/constants';
import { DASHBOARD_TYPES } from 'ee/security_dashboard/store/constants'; import { DASHBOARD_TYPES } from 'ee/security_dashboard/store/constants';
import { vulnerabilities } from '../../mock_data';
jest.mock('~/flash'); jest.mock('~/flash');
...@@ -29,8 +30,9 @@ const createVulnerabilitiesRequestHandler = (options) => ...@@ -29,8 +30,9 @@ const createVulnerabilitiesRequestHandler = (options) =>
data: { data: {
group: { group: {
id: 'group-1', id: 'group-1',
__typename: 'Group',
vulnerabilities: { vulnerabilities: {
nodes: [], nodes: vulnerabilities,
pageInfo: { pageInfo: {
__typename: 'PageInfo', __typename: 'PageInfo',
startCursor: 'abc', startCursor: 'abc',
...@@ -244,22 +246,26 @@ describe('Vulnerability list GraphQL component', () => { ...@@ -244,22 +246,26 @@ describe('Vulnerability list GraphQL component', () => {
); );
}); });
it('will reset paging if the sort has changed', async () => { it('will reset paging and the vulnerability list if the sort has changed', async () => {
createWrapper(); createWrapper();
await waitForPromises();
router.push({ query: { after: 'abc' } }); router.push({ query: { after: 'abc' } });
findVulnerabilityList().vm.$emit('update:sort', SORT_OBJECT); findVulnerabilityList().vm.$emit('update:sort', SORT_OBJECT);
await nextTick(); await nextTick();
expect(router.currentRoute.query.after).toBeUndefined(); expect(router.currentRoute.query.after).toBeUndefined();
expect(findVulnerabilityList().props('vulnerabilities')).toHaveLength(0);
}); });
it('will not reset paging when the page changes but sorting has not', async () => { it('will not reset paging when the page changes but sorting has not', async () => {
router.push({ query: SORT_OBJECT }); router.push({ query: SORT_OBJECT });
createWrapper(); createWrapper();
await waitForPromises();
router.push({ query: { ...router.currentRoute.query, after: 'abc' } }); router.push({ query: { ...router.currentRoute.query, after: 'abc' } });
await nextTick(); await nextTick();
expect(router.currentRoute.query.after).toBe('abc'); expect(router.currentRoute.query.after).toBe('abc');
expect(findVulnerabilityList().props('vulnerabilities')).toHaveLength(vulnerabilities.length);
}); });
}); });
......
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