Commit 29a3bab9 authored by Alexander Turinske's avatar Alexander Turinske

Update location tests

- abstract out logic and property getters
parent 5f1bc407
...@@ -52,6 +52,16 @@ export const generateVulnerabilities = () => [ ...@@ -52,6 +52,16 @@ export const generateVulnerabilities = () => [
nameWithNamespace: 'Mixed Vulnerabilities / Rails App', nameWithNamespace: 'Mixed Vulnerabilities / Rails App',
}, },
}, },
{
id: 'id_4',
title: 'Vulnerability 4',
severity: 'critical',
state: 'dismissed',
location: {},
project: {
nameWithNamespace: 'Administrator / Security reports',
},
},
]; ];
export const vulnerabilities = generateVulnerabilities(); export const vulnerabilities = generateVulnerabilities();
...@@ -35,6 +35,7 @@ describe('Vulnerability list component', () => { ...@@ -35,6 +35,7 @@ describe('Vulnerability list component', () => {
const findRowVulnerabilityCommentIcon = row => findRow(row).find(VulnerabilityCommentIcon); const findRowVulnerabilityCommentIcon = row => findRow(row).find(VulnerabilityCommentIcon);
const findDataCell = label => wrapper.find(`[data-testid="${label}"]`); const findDataCell = label => wrapper.find(`[data-testid="${label}"]`);
const findDataCells = label => wrapper.findAll(`[data-testid="${label}"]`); const findDataCells = label => wrapper.findAll(`[data-testid="${label}"]`);
const findCellText = label => findDataCell(label).text();
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
...@@ -116,60 +117,41 @@ describe('Vulnerability list component', () => { ...@@ -116,60 +117,41 @@ describe('Vulnerability list component', () => {
}); });
}); });
it('should display the vulnerability locations', () => { it('should display the vulnerability locations for images', () => {
expect(findDataCell(`location-${newVulnerabilities[0].id}`).text()).toContain( const { id, project, location } = newVulnerabilities[0];
newVulnerabilities[0].project.nameWithNamespace, const cellText = findCellText(`location-${id}`);
); expect(cellText).toContain(project.nameWithNamespace);
expect(findDataCell(`location-${newVulnerabilities[0].id}`).text()).toContain( expect(cellText).toContain(location.image);
newVulnerabilities[0].location.image, expect(cellText).not.toContain('(line: ');
); });
expect(findDataCell(`location-${newVulnerabilities[0].id}`).text()).not.toContain('(line: ');
expect(findDataCell(`location-${newVulnerabilities[1].id}`).text()).toContain( it('should display the vulnerability locations for code', () => {
newVulnerabilities[1].project.nameWithNamespace, const { id, project, location } = newVulnerabilities[1];
); const cellText = findCellText(`location-${id}`);
expect(findDataCell(`location-${newVulnerabilities[1].id}`).text()).toContain( expect(cellText).toContain(project.nameWithNamespace);
newVulnerabilities[1].location.file, expect(cellText).toContain(location.file);
); expect(cellText).toContain(location.startLine);
expect(findDataCell(`location-${newVulnerabilities[1].id}`).text()).toContain( });
newVulnerabilities[1].location.startLine,
); it('should display the vulnerability locations for code with no line data', () => {
expect(findDataCell(`location-${newVulnerabilities[2].id}`).text()).toContain( const { id, project, location } = newVulnerabilities[2];
newVulnerabilities[2].project.nameWithNamespace, const cellText = findCellText(`location-${id}`);
); expect(cellText).toContain(project.nameWithNamespace);
expect(findDataCell(`location-${newVulnerabilities[2].id}`).text()).toContain( expect(cellText).toContain(location.file);
newVulnerabilities[2].location.file, expect(cellText).not.toContain('(line: ');
); });
expect(findDataCell(`location-${newVulnerabilities[2].id}`).text()).not.toContain('(line: ');
it('should not display the vulnerability locations for vulnerabilities without a location', () => {
const { id, project } = newVulnerabilities[4];
const cellText = findCellText(`location-${id}`);
expect(cellText).toEqual(project.nameWithNamespace);
expect(cellText).not.toContain('(line: ');
}); });
it('should not display the vulnerability report type', () => { it('should not display the vulnerability report type', () => {
const scannerCell = findRow().find('[data-testid="vulnerability-report-type"'); const scannerCell = findRow().find('[data-testid="vulnerability-report-type"');
expect(scannerCell.exists()).toBe(false); expect(scannerCell.exists()).toBe(false);
}); });
it('should not display the vulnerability locations', () => {
const vulnerabilityWithoutLocation = [
{
id: 'id_0',
title: 'Vulnerability 1',
severity: 'critical',
state: 'dismissed',
location: {},
project: {
nameWithNamespace: 'Administrator / Security reports',
},
},
];
wrapper = createWrapper({
props: { vulnerabilities: vulnerabilityWithoutLocation, shouldShowProjectNamespace: true },
});
expect(findDataCell(`location-${vulnerabilityWithoutLocation[0].id}`).text()).toContain(
'Administrator / Security reports',
);
expect(
findDataCell(`location-${vulnerabilityWithoutLocation[0].id}`).findAll('div').length,
).toBe(2);
});
}); });
describe('when displayed on a project level dashboard', () => { describe('when displayed on a project level dashboard', () => {
...@@ -181,19 +163,25 @@ describe('Vulnerability list component', () => { ...@@ -181,19 +163,25 @@ describe('Vulnerability list component', () => {
}); });
}); });
it('should not display the vulnerability locations', () => { it('should not display the vulnerability group/project locations for images', () => {
expect(findDataCell(`location-${newVulnerabilities[0].id}`).text()).not.toContain( const { id, project, location } = newVulnerabilities[0];
'Administrator / Security reports', const cellText = findCellText(`location-${id}`);
); expect(cellText).not.toContain(project.nameWithNamespace);
expect(findDataCell(`location-${newVulnerabilities[0].id}`).text()).toContain( expect(cellText).toEqual(location.image);
'registry.gitlab.com/groulot/container-scanning-test/master:5f21de6956aee99ddb68ae49498662d9872f50ff', });
);
expect(findDataCell(`location-${newVulnerabilities[1].id}`).text()).not.toContain( it('should display the vulnerability locations for code', () => {
'Administrator / Vulnerability reports', const { id, project, location } = newVulnerabilities[1];
); const cellText = findCellText(`location-${id}`);
expect(findDataCell(`location-${newVulnerabilities[1].id}`).text()).toContain( expect(cellText).not.toContain(project.nameWithNamespace);
'src/main/java/com/gitlab/security_products/tests/App.java', expect(cellText).toEqual(`${location.file} (line: ${location.startLine})`);
); });
it('should not display the vulnerability group/project locations for code with no line data', () => {
const { id, project, location } = newVulnerabilities[2];
const cellText = findCellText(`location-${id}`);
expect(cellText).not.toContain(project.nameWithNamespace);
expect(cellText).toEqual(location.file);
}); });
it('should display the vulnerability report type', () => { it('should display the vulnerability report type', () => {
......
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