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 = () => [
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();
......@@ -35,6 +35,7 @@ describe('Vulnerability list component', () => {
const findRowVulnerabilityCommentIcon = row => findRow(row).find(VulnerabilityCommentIcon);
const findDataCell = label => wrapper.find(`[data-testid="${label}"]`);
const findDataCells = label => wrapper.findAll(`[data-testid="${label}"]`);
const findCellText = label => findDataCell(label).text();
afterEach(() => {
wrapper.destroy();
......@@ -116,59 +117,40 @@ describe('Vulnerability list component', () => {
});
});
it('should display the vulnerability locations', () => {
expect(findDataCell(`location-${newVulnerabilities[0].id}`).text()).toContain(
newVulnerabilities[0].project.nameWithNamespace,
);
expect(findDataCell(`location-${newVulnerabilities[0].id}`).text()).toContain(
newVulnerabilities[0].location.image,
);
expect(findDataCell(`location-${newVulnerabilities[0].id}`).text()).not.toContain('(line: ');
expect(findDataCell(`location-${newVulnerabilities[1].id}`).text()).toContain(
newVulnerabilities[1].project.nameWithNamespace,
);
expect(findDataCell(`location-${newVulnerabilities[1].id}`).text()).toContain(
newVulnerabilities[1].location.file,
);
expect(findDataCell(`location-${newVulnerabilities[1].id}`).text()).toContain(
newVulnerabilities[1].location.startLine,
);
expect(findDataCell(`location-${newVulnerabilities[2].id}`).text()).toContain(
newVulnerabilities[2].project.nameWithNamespace,
);
expect(findDataCell(`location-${newVulnerabilities[2].id}`).text()).toContain(
newVulnerabilities[2].location.file,
);
expect(findDataCell(`location-${newVulnerabilities[2].id}`).text()).not.toContain('(line: ');
it('should display the vulnerability locations for images', () => {
const { id, project, location } = newVulnerabilities[0];
const cellText = findCellText(`location-${id}`);
expect(cellText).toContain(project.nameWithNamespace);
expect(cellText).toContain(location.image);
expect(cellText).not.toContain('(line: ');
});
it('should not display the vulnerability report type', () => {
const scannerCell = findRow().find('[data-testid="vulnerability-report-type"');
expect(scannerCell.exists()).toBe(false);
it('should display the vulnerability locations for code', () => {
const { id, project, location } = newVulnerabilities[1];
const cellText = findCellText(`location-${id}`);
expect(cellText).toContain(project.nameWithNamespace);
expect(cellText).toContain(location.file);
expect(cellText).toContain(location.startLine);
});
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 },
it('should display the vulnerability locations for code with no line data', () => {
const { id, project, location } = newVulnerabilities[2];
const cellText = findCellText(`location-${id}`);
expect(cellText).toContain(project.nameWithNamespace);
expect(cellText).toContain(location.file);
expect(cellText).not.toContain('(line: ');
});
expect(findDataCell(`location-${vulnerabilityWithoutLocation[0].id}`).text()).toContain(
'Administrator / Security reports',
);
expect(
findDataCell(`location-${vulnerabilityWithoutLocation[0].id}`).findAll('div').length,
).toBe(2);
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', () => {
const scannerCell = findRow().find('[data-testid="vulnerability-report-type"');
expect(scannerCell.exists()).toBe(false);
});
});
......@@ -181,19 +163,25 @@ describe('Vulnerability list component', () => {
});
});
it('should not display the vulnerability locations', () => {
expect(findDataCell(`location-${newVulnerabilities[0].id}`).text()).not.toContain(
'Administrator / Security reports',
);
expect(findDataCell(`location-${newVulnerabilities[0].id}`).text()).toContain(
'registry.gitlab.com/groulot/container-scanning-test/master:5f21de6956aee99ddb68ae49498662d9872f50ff',
);
expect(findDataCell(`location-${newVulnerabilities[1].id}`).text()).not.toContain(
'Administrator / Vulnerability reports',
);
expect(findDataCell(`location-${newVulnerabilities[1].id}`).text()).toContain(
'src/main/java/com/gitlab/security_products/tests/App.java',
);
it('should not display the vulnerability group/project locations for images', () => {
const { id, project, location } = newVulnerabilities[0];
const cellText = findCellText(`location-${id}`);
expect(cellText).not.toContain(project.nameWithNamespace);
expect(cellText).toEqual(location.image);
});
it('should display the vulnerability locations for code', () => {
const { id, project, location } = newVulnerabilities[1];
const cellText = findCellText(`location-${id}`);
expect(cellText).not.toContain(project.nameWithNamespace);
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', () => {
......
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