Skip to content

Commit

Permalink
Fix report links in audits listpage.
Browse files Browse the repository at this point in the history
Report links should switch to report or compliance report details
page based on the feature toggle.
  • Loading branch information
a-h-abdelsalam committed Aug 23, 2024
1 parent baa8c85 commit 604d876
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 13 deletions.
124 changes: 114 additions & 10 deletions src/web/pages/audits/__tests__/row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import Row from '../row';
setLocale('en');

const gmp = {settings: {}};
const caps = new Capabilities(['everything']);
const featureList = [
{name: 'COMPLIANCE_REPORTS', _enabled: 0},
];
const caps = new Capabilities(['everything'], featureList);

const lastReport = {
report: {
Expand Down Expand Up @@ -110,11 +113,11 @@ describe('Audit Row tests', () => {
const detailsLinks = getAllByTestId('details-link');

expect(detailsLinks[0]).toHaveTextContent('Done');
expect(detailsLinks[0]).toHaveAttribute('href', '/auditreport/1234');
expect(detailsLinks[0]).toHaveAttribute('href', '/report/1234');

// Report
expect(detailsLinks[1]).toHaveTextContent('Wed, Jul 10, 2019 2:51 PM CEST');
expect(detailsLinks[1]).toHaveAttribute('href', '/auditreport/1234');
expect(detailsLinks[1]).toHaveAttribute('href', '/report/1234');

// Compliance Status
expect(bars[1]).toHaveAttribute('title', '50%');
Expand Down Expand Up @@ -375,7 +378,7 @@ describe('Audit Row tests', () => {
const detailsLinks = getAllByTestId('details-link');

expect(detailsLinks[0]).toHaveTextContent('0 %');
expect(detailsLinks[0]).toHaveAttribute('href', '/auditreport/5678');
expect(detailsLinks[0]).toHaveAttribute('href', '/report/5678');

// Report
expect(detailsLinks.length).toBe(1);
Expand Down Expand Up @@ -483,11 +486,11 @@ describe('Audit Row tests', () => {
const detailsLinks = getAllByTestId('details-link');

expect(detailsLinks[0]).toHaveTextContent('Stopped');
expect(detailsLinks[0]).toHaveAttribute('href', '/auditreport/5678');
expect(detailsLinks[0]).toHaveAttribute('href', '/report/5678');

// Report
expect(detailsLinks[1]).toHaveTextContent('Wed, Jul 10, 2019 2:51 PM CEST');
expect(detailsLinks[1]).toHaveAttribute('href', '/auditreport/1234');
expect(detailsLinks[1]).toHaveAttribute('href', '/report/1234');

// Compliance Status
expect(bars[1]).toHaveAttribute('title', '50%');
Expand Down Expand Up @@ -593,11 +596,11 @@ describe('Audit Row tests', () => {
const detailsLinks = getAllByTestId('details-link');

expect(detailsLinks[0]).toHaveTextContent('Done');
expect(detailsLinks[0]).toHaveAttribute('href', '/auditreport/1234');
expect(detailsLinks[0]).toHaveAttribute('href', '/report/1234');

// Report
expect(detailsLinks[1]).toHaveTextContent('Wed, Jul 10, 2019 2:51 PM CEST');
expect(detailsLinks[1]).toHaveAttribute('href', '/auditreport/1234');
expect(detailsLinks[1]).toHaveAttribute('href', '/report/1234');

// Compliance Status
expect(bars[1]).toHaveAttribute('title', '50%');
Expand Down Expand Up @@ -706,11 +709,11 @@ describe('Audit Row tests', () => {
const detailsLinks = getAllByTestId('details-link');

expect(detailsLinks[0]).toHaveTextContent('Done');
expect(detailsLinks[0]).toHaveAttribute('href', '/auditreport/1234');
expect(detailsLinks[0]).toHaveAttribute('href', '/report/1234');

// Report
expect(detailsLinks[1]).toHaveTextContent('Wed, Jul 10, 2019 2:51 PM CEST');
expect(detailsLinks[1]).toHaveAttribute('href', '/auditreport/1234');
expect(detailsLinks[1]).toHaveAttribute('href', '/report/1234');

// Compliance Status
expect(bars[1]).toHaveAttribute('title', '50%');
Expand Down Expand Up @@ -760,3 +763,104 @@ describe('Audit Row tests', () => {

console.warn = consoleError;
});

describe('Audit Row tests - compliance reports enabled', () => {
// deactivate console.error for tests
// to make it possible to test a row without a table
console.error = () => {};
const featureList = [
{name: 'COMPLIANCE_REPORTS', _enabled: 1},
];
const caps = new Capabilities(['everything'], featureList);

test('should render', () => {
const audit = Audit.fromElement({
_id: '314',
owner: {name: 'username'},
name: 'foo',
comment: 'bar',
status: AUDIT_STATUS.done,
alterable: '0',
last_report: lastReport,
permissions: {permission: [{name: 'everything'}]},
target: {_id: '5678', name: 'target'},
usage_type: 'audit',
});

const handleAuditClone = testing.fn();
const handleAuditDelete = testing.fn();
const handleAuditDownload = testing.fn();
const handleAuditEdit = testing.fn();
const handleAuditResume = testing.fn();
const handleAuditStart = testing.fn();
const handleAuditStop = testing.fn();
const handleReportDownload = testing.fn();
const handleToggleDetailsClick = testing.fn();

const {render, store} = rendererWith({
gmp,
capabilities: caps,
store: true,
router: true,
});

store.dispatch(setTimezone('CET'));
store.dispatch(setUsername('username'));

const {baseElement, getAllByTestId} = render(
<Row
entity={audit}
links={true}
gcrFormatDefined={true}
onAuditCloneClick={handleAuditClone}
onAuditDeleteClick={handleAuditDelete}
onAuditDownloadClick={handleAuditDownload}
onAuditEditClick={handleAuditEdit}
onAuditResumeClick={handleAuditResume}
onAuditStartClick={handleAuditStart}
onAuditStopClick={handleAuditStop}
onReportDownloadClick={handleReportDownload}
onToggleDetailsClick={handleToggleDetailsClick}
/>,
);

expect(baseElement).toBeVisible();

// Name
expect(baseElement).toHaveTextContent('foo');
expect(baseElement).toHaveTextContent('(bar)');

// Status
const bars = getAllByTestId('progressbar-box');

expect(bars[0]).toHaveAttribute('title', AUDIT_STATUS.done);
expect(bars[0]).toHaveTextContent(AUDIT_STATUS.done);

const detailsLinks = getAllByTestId('details-link');

expect(detailsLinks[0]).toHaveTextContent('Done');
expect(detailsLinks[0]).toHaveAttribute('href', '/auditreport/1234');

// Report
expect(detailsLinks[1]).toHaveTextContent('Wed, Jul 10, 2019 2:51 PM CEST');
expect(detailsLinks[1]).toHaveAttribute('href', '/auditreport/1234');

// Compliance Status
expect(bars[1]).toHaveAttribute('title', '50%');
expect(bars[1]).toHaveTextContent('50%');

// Actions
const icons = getAllByTestId('svg-icon');

expect(icons[0]).toHaveAttribute('title', 'Start');
expect(icons[1]).toHaveAttribute('title', 'Audit is not stopped');
expect(icons[2]).toHaveAttribute('title', 'Move Audit to trashcan');
expect(icons[3]).toHaveAttribute('title', 'Edit Audit');
expect(icons[4]).toHaveAttribute('title', 'Clone Audit');
expect(icons[5]).toHaveAttribute('title', 'Export Audit');
expect(icons[6]).toHaveAttribute(
'title',
'Download Greenbone Compliance Report',
);
});
});
16 changes: 13 additions & 3 deletions src/web/pages/audits/row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ import {GREENBONE_SENSOR_SCANNER_TYPE} from 'gmp/models/scanner';

import ComplianceStatusBar from 'web/components/bar/compliancestatusbar';

import {renderReport} from 'web/pages/tasks/row';
import DateTime from 'web/components/date/datetime';
import DetailsLink from 'web/components/link/detailslink';
import useCapabilities from 'web/hooks/useCapabilities';

const renderAuditReport = (report, links) => {
if (!isDefined(report)) {
Expand Down Expand Up @@ -83,8 +85,8 @@ const Row = ({
...props
}) => {
const {scanner, observers} = entity;

const obs = [];
const caps = useCapabilities();

if (isDefined(observers)) {
if (isDefined(observers.user)) {
Expand Down Expand Up @@ -143,9 +145,17 @@ const Row = ({
{entity.comment && <Comment>({entity.comment})</Comment>}
</TableData>
<TableData>
<AuditStatus isAudit={true} task={entity} links={links} />
<AuditStatus
isAudit={caps.featureEnabled('COMPLIANCE_REPORTS') ? true : false}
task={entity}
links={links}/>
</TableData>
<TableData>
{caps.featureEnabled('COMPLIANCE_REPORTS')
? renderAuditReport(entity.last_report, links)
: renderReport(entity.last_report, links)
}
</TableData>
<TableData>{renderAuditReport(entity.last_report, links)}</TableData>
<TableData>
{isDefined(entity.last_report) && (
<ComplianceStatusBar
Expand Down

0 comments on commit 604d876

Please sign in to comment.