Skip to content

Commit

Permalink
Add start icon test for tasks with duration limit
Browse files Browse the repository at this point in the history
  • Loading branch information
timopollmeier authored and bjoernricks committed Nov 23, 2023
1 parent cc1939d commit 9cf69e1
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/web/pages/tasks/icons/__tests__/starticon.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Capabilities from 'gmp/capabilities/capabilities';

import Audit, {AUDIT_STATUS} from 'gmp/models/audit';
import Task, {TASK_STATUS} from 'gmp/models/task';
import Event from 'gmp/models/event';

import {rendererWith, fireEvent} from 'web/utils/testing';

Expand Down Expand Up @@ -108,6 +109,50 @@ describe('Task StartIcon component tests', () => {
});
});

test('should render in inactive state if task is scheduled with a duration limit', () => {
const caps = new Capabilities(['everything']);
const icalendar = `BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Greenbone.net//NONSGML Greenbone Security Manager 8.0.0//EN
BEGIN:VEVENT
UID:c35f82f1-7798-4b84-b2c4-761a33068956
DTSTAMP:20190715T124352Z
DTSTART:20190716T040000
DTEND:20190716T050000
END:VEVENT
END:VCALENDAR
`;

const task = Task.fromElement({
status: TASK_STATUS.new,
target: {_id: '123'},
permissions: {permission: [{name: 'everything'}]},
schedule: {
_id: 'schedule1',
event: Event.fromIcal(icalendar, 'UTC'),
},
});
const clickHandler = jest.fn();

const {render} = rendererWith({capabilities: caps});

const {element} = render(<StartIcon task={task} />);

expect(caps.mayOp('start_task')).toEqual(true);
expect(task.userCapabilities.mayOp('start_task')).toEqual(true);

fireEvent.click(element);

expect(clickHandler).not.toHaveBeenCalled();
expect(element).toHaveAttribute(
'title',
'Task cannot be started manually because the assigned schedule has a duration limit',
);
expect(element).toHaveStyleRule('fill', Theme.inputBorderGray, {
modifier: `svg path`,
});
});

test('should render in inactive state if task is already active', () => {
const caps = new Capabilities(['everything']);
const task = Task.fromElement({
Expand Down

0 comments on commit 9cf69e1

Please sign in to comment.