foreman-tasks 2.0.3 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/js_tests.yml +31 -0
  3. data/.github/workflows/ruby_tests.yml +74 -0
  4. data/.rubocop.yml +12 -4
  5. data/.rubocop_todo.yml +32 -25
  6. data/Gemfile +5 -0
  7. data/app/controllers/foreman_tasks/api/tasks_controller.rb +50 -63
  8. data/app/controllers/foreman_tasks/concerns/parameters/triggering.rb +1 -1
  9. data/app/controllers/foreman_tasks/recurring_logics_controller.rb +7 -0
  10. data/app/helpers/foreman_tasks/foreman_tasks_helper.rb +3 -3
  11. data/app/models/foreman_tasks/recurring_logic.rb +1 -1
  12. data/app/models/foreman_tasks/task.rb +11 -0
  13. data/app/models/foreman_tasks/task/dynflow_task.rb +27 -33
  14. data/app/models/foreman_tasks/task/search.rb +1 -1
  15. data/app/models/foreman_tasks/task/status_explicator.rb +1 -1
  16. data/app/models/foreman_tasks/triggering.rb +1 -1
  17. data/app/models/setting/foreman_tasks.rb +9 -9
  18. data/app/services/foreman_tasks/dashboard_table_filter.rb +5 -1
  19. data/app/views/foreman_tasks/api/tasks/index.json.rabl +2 -0
  20. data/app/views/foreman_tasks/layouts/react.html.erb +1 -2
  21. data/app/views/foreman_tasks/recurring_logics/index.html.erb +3 -1
  22. data/app/views/foreman_tasks/tasks/dashboard/_latest_tasks_in_error_warning.html.erb +1 -1
  23. data/app/views/foreman_tasks/tasks/dashboard/_tasks_status.html.erb +1 -1
  24. data/app/views/foreman_tasks/tasks/show.html.erb +1 -6
  25. data/config/routes.rb +2 -1
  26. data/db/migrate/20200517215015_rename_bookmarks_controller.rb +2 -2
  27. data/db/seeds.d/30-notification_blueprints.rb +7 -7
  28. data/db/seeds.d/61-foreman_tasks_bookmarks.rb +1 -1
  29. data/foreman-tasks.gemspec +1 -0
  30. data/lib/foreman_tasks/cleaner.rb +4 -6
  31. data/lib/foreman_tasks/dynflow/configuration.rb +1 -1
  32. data/lib/foreman_tasks/dynflow/persistence.rb +4 -6
  33. data/lib/foreman_tasks/engine.rb +2 -2
  34. data/lib/foreman_tasks/version.rb +1 -1
  35. data/package.json +0 -1
  36. data/test/controllers/api/recurring_logics_controller_test.rb +1 -1
  37. data/test/controllers/api/tasks_controller_test.rb +17 -7
  38. data/test/controllers/tasks_controller_test.rb +6 -6
  39. data/test/core/unit/runner_test.rb +20 -20
  40. data/test/core/unit/task_launcher_test.rb +8 -8
  41. data/test/helpers/foreman_tasks/foreman_tasks_helper_test.rb +7 -7
  42. data/test/helpers/foreman_tasks/tasks_helper_test.rb +3 -3
  43. data/test/lib/actions/middleware/keep_current_request_id_test.rb +3 -3
  44. data/test/support/history_tasks_builder.rb +1 -1
  45. data/test/tasks/generate_task_actions_test.rb +1 -1
  46. data/test/unit/actions/action_with_sub_plans_test.rb +2 -2
  47. data/test/unit/actions/bulk_action_test.rb +6 -6
  48. data/test/unit/actions/proxy_action_test.rb +20 -20
  49. data/test/unit/actions/recurring_action_test.rb +30 -32
  50. data/test/unit/cleaner_test.rb +24 -24
  51. data/test/unit/dashboard_table_filter_test.rb +5 -5
  52. data/test/unit/otp_manager_test.rb +2 -2
  53. data/test/unit/proxy_selector_test.rb +9 -9
  54. data/test/unit/recurring_logic_test.rb +32 -32
  55. data/test/unit/remote_task_test.rb +2 -2
  56. data/test/unit/task_groups_test.rb +4 -4
  57. data/test/unit/task_test.rb +26 -18
  58. data/test/unit/triggering_test.rb +8 -8
  59. data/test/unit/troubleshooting_help_generator_test.rb +6 -6
  60. data/test/unit/ui_notifications_test.rb +11 -11
  61. data/webpack/ForemanTasks/Components/TaskDetails/Components/RunningSteps.js +3 -3
  62. data/webpack/ForemanTasks/Components/TaskDetails/Components/Task.js +8 -157
  63. data/webpack/ForemanTasks/Components/TaskDetails/Components/TaskButtons.js +168 -0
  64. data/webpack/ForemanTasks/Components/TaskDetails/Components/TaskInfo.js +6 -7
  65. data/webpack/ForemanTasks/Components/TaskDetails/Components/TaskSkeleton.js +48 -0
  66. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/RunningSteps.test.js +1 -1
  67. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/Task.test.js +12 -70
  68. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/TaskButtons.test.js +95 -0
  69. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/__snapshots__/Task.test.js.snap +78 -225
  70. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/__snapshots__/TaskButtons.test.js.snap +212 -0
  71. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/__snapshots__/TaskInfo.test.js.snap +8 -4
  72. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetails.js +87 -70
  73. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetails.scss +10 -0
  74. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsActions.js +48 -125
  75. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsConstants.js +3 -16
  76. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsSelectors.js +55 -29
  77. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetails.fixtures.js +2 -2
  78. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetails.test.js +6 -0
  79. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetailsActions.test.js +2 -18
  80. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/__snapshots__/TaskDetails.test.js.snap +77 -27
  81. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/__snapshots__/TaskDetailsActions.test.js.snap +14 -101
  82. data/webpack/ForemanTasks/Components/TaskDetails/index.js +6 -3
  83. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/ScheduledTasksCard/ScheduledTasksCard.scss +4 -0
  84. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/OtherInfo.js +53 -0
  85. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/OtherInfo.test.js +14 -0
  86. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.js +27 -19
  87. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.scss +14 -0
  88. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.test.js +1 -34
  89. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/{StoppedTasksCardHelper.js → StoppedTasksCardTable.js} +28 -1
  90. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCardTable.test.js +54 -0
  91. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/__snapshots__/OtherInfo.test.js.snap +48 -0
  92. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/__snapshots__/StoppedTasksCard.test.js.snap +60 -1367
  93. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/__snapshots__/StoppedTasksCardTable.test.js.snap +960 -0
  94. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/__snapshots__/TasksCardsGrid.test.js.snap +14 -11
  95. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardConstants.js +2 -0
  96. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardSelectors.js +17 -11
  97. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboardSelectors.test.js +26 -14
  98. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/__snapshots__/TasksDashboard.test.js.snap +14 -11
  99. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/__snapshots__/TasksDashboardSelectors.test.js.snap +38 -22
  100. data/webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js +0 -8
  101. data/webpack/ForemanTasks/Components/TasksTable/TasksTablePage.js +13 -4
  102. data/webpack/ForemanTasks/Components/TasksTable/TasksTablePage.scss +0 -10
  103. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksTablePage.test.js.snap +0 -2
  104. data/webpack/ForemanTasks/Components/TasksTable/formatters/__test__/__snapshots__/actionNameCellFormatter.test.js.snap +3 -1
  105. data/webpack/ForemanTasks/Components/TasksTable/formatters/actionNameCellFormatter.js +6 -1
  106. data/webpack/ForemanTasks/Components/common/urlHelpers.js +7 -0
  107. data/webpack/ForemanTasks/ForemanTasksReducers.js +0 -2
  108. data/webpack/__mocks__/foremanReact/common/helpers.js +2 -0
  109. data/webpack/__mocks__/foremanReact/redux/API/APISelectors.js +10 -0
  110. data/webpack/__mocks__/foremanReact/redux/API/index.js +10 -0
  111. data/webpack/__mocks__/foremanReact/redux/middlewares/IntervalMiddleware.js +5 -0
  112. metadata +21 -13
  113. data/.travis.yml +0 -7
  114. data/app/assets/stylesheets/foreman_tasks/tasks.scss +0 -9
  115. data/script/travis_run_js_tests.sh +0 -7
  116. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsReducer.js +0 -38
  117. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetailsReducer.test.js +0 -33
  118. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/__snapshots__/TaskDetailsReducer.test.js.snap +0 -26
  119. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/__snapshots__/integration.test.js.snap +0 -122
  120. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/integration.test.js +0 -72
  121. data/webpack/__mocks__/foremanReact/redux/API.js +0 -7
@@ -0,0 +1,168 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { Col, Button } from 'patternfly-react';
4
+ import { useForemanModal } from 'foremanReact/components/ForemanModal/ForemanModalHooks';
5
+ import { translate as __ } from 'foremanReact/common/I18n';
6
+ import {
7
+ UNLOCK_MODAL,
8
+ FORCE_UNLOCK_MODAL,
9
+ } from '../../TaskActions/TaskActionsConstants';
10
+
11
+ export const TaskButtons = ({
12
+ canEdit,
13
+ dynflowEnableConsole,
14
+ taskReloadStart,
15
+ taskProgressToggle,
16
+ taskReload,
17
+ externalId,
18
+ id,
19
+ action,
20
+ state,
21
+ resumable,
22
+ cancellable,
23
+ hasSubTasks,
24
+ parentTask,
25
+ cancelTaskRequest,
26
+ resumeTaskRequest,
27
+ }) => {
28
+ const unlockModalActions = useForemanModal({
29
+ id: UNLOCK_MODAL,
30
+ });
31
+ const forceUnlockModalActions = useForemanModal({
32
+ id: FORCE_UNLOCK_MODAL,
33
+ });
34
+ const editActionsTitle = canEdit
35
+ ? undefined
36
+ : __('You do not have permission');
37
+ const dynflowTitle = dynflowEnableConsole
38
+ ? undefined
39
+ : `dynflow_enable_console ${__('Setting is off')}`;
40
+
41
+ return (
42
+ <Col xs={12}>
43
+ <Button
44
+ className="reload-button"
45
+ bsSize="small"
46
+ onClick={taskProgressToggle}
47
+ >
48
+ <span
49
+ className={`glyphicon glyphicon-refresh ${taskReload ? 'spin' : ''}`}
50
+ />
51
+ {__(`${taskReload ? 'Stop' : 'Start'} auto-reloading`)}
52
+ </Button>
53
+ <Button
54
+ className="dynflow-button"
55
+ bsSize="small"
56
+ href={`/foreman_tasks/dynflow/${externalId}`}
57
+ disabled={!dynflowEnableConsole}
58
+ rel="noopener noreferrer"
59
+ target="_blank"
60
+ >
61
+ <span title={dynflowTitle} data-original-title={dynflowTitle}>
62
+ {__('Dynflow console')}
63
+ </span>
64
+ </Button>
65
+ <Button
66
+ className="resume-button"
67
+ bsSize="small"
68
+ title={editActionsTitle}
69
+ data-original-title={editActionsTitle}
70
+ disabled={!canEdit || !resumable}
71
+ onClick={() => {
72
+ if (!taskReload) {
73
+ taskReloadStart(id);
74
+ }
75
+ resumeTaskRequest(id, action);
76
+ }}
77
+ >
78
+ {__('Resume')}
79
+ </Button>
80
+ <Button
81
+ className="cancel-button"
82
+ bsSize="small"
83
+ title={editActionsTitle}
84
+ data-original-title={editActionsTitle}
85
+ disabled={!canEdit || !cancellable}
86
+ onClick={() => {
87
+ if (!taskReload) {
88
+ taskReloadStart(id);
89
+ }
90
+ cancelTaskRequest(id, action);
91
+ }}
92
+ >
93
+ {__('Cancel')}
94
+ </Button>
95
+ {parentTask && (
96
+ <Button
97
+ className="parent-button"
98
+ bsSize="small"
99
+ href={`/foreman_tasks/tasks/${parentTask}`}
100
+ >
101
+ {__('Parent task')}
102
+ </Button>
103
+ )}
104
+ {hasSubTasks && (
105
+ <Button
106
+ className="subtask-button"
107
+ bsSize="small"
108
+ href={`/foreman_tasks/tasks/${id}/sub_tasks`}
109
+ >
110
+ {__('Sub tasks')}
111
+ </Button>
112
+ )}
113
+ <Button
114
+ className="unlock-button"
115
+ bsSize="small"
116
+ disabled={!canEdit || state !== 'paused'}
117
+ onClick={unlockModalActions.setModalOpen}
118
+ title={editActionsTitle}
119
+ data-original-title={editActionsTitle}
120
+ >
121
+ {__('Unlock')}
122
+ </Button>
123
+ <Button
124
+ className="force-unlock-button"
125
+ bsSize="small"
126
+ disabled={!canEdit || state === 'stopped'}
127
+ onClick={forceUnlockModalActions.setModalOpen}
128
+ title={editActionsTitle}
129
+ data-original-title={editActionsTitle}
130
+ >
131
+ {__('Force Unlock')}
132
+ </Button>
133
+ </Col>
134
+ );
135
+ };
136
+
137
+ TaskButtons.propTypes = {
138
+ canEdit: PropTypes.bool,
139
+ dynflowEnableConsole: PropTypes.bool,
140
+ taskReloadStart: PropTypes.func.isRequired,
141
+ taskProgressToggle: PropTypes.func.isRequired,
142
+ taskReload: PropTypes.bool,
143
+ externalId: PropTypes.string,
144
+ id: PropTypes.string.isRequired,
145
+ action: PropTypes.string,
146
+ state: PropTypes.string,
147
+ resumable: PropTypes.bool,
148
+ cancellable: PropTypes.bool,
149
+ hasSubTasks: PropTypes.bool,
150
+ parentTask: PropTypes.string,
151
+ cancelTaskRequest: PropTypes.func,
152
+ resumeTaskRequest: PropTypes.func,
153
+ };
154
+
155
+ TaskButtons.defaultProps = {
156
+ canEdit: false,
157
+ dynflowEnableConsole: false,
158
+ taskReload: false,
159
+ externalId: '',
160
+ action: '',
161
+ state: '',
162
+ resumable: false,
163
+ cancellable: false,
164
+ hasSubTasks: false,
165
+ parentTask: '',
166
+ cancelTaskRequest: () => null,
167
+ resumeTaskRequest: () => null,
168
+ };
@@ -3,7 +3,6 @@ import PropTypes from 'prop-types';
3
3
  import { Grid, Row, Col, ProgressBar } from 'patternfly-react';
4
4
  import { translate as __ } from 'foremanReact/common/I18n';
5
5
  import RelativeDateTime from 'foremanReact/components/common/dates/RelativeDateTime';
6
- import ReactHtmlParser from 'react-html-parser';
7
6
 
8
7
  class TaskInfo extends Component {
9
8
  isDelayed = () => {
@@ -59,7 +58,7 @@ class TaskInfo extends Component {
59
58
  state,
60
59
  help,
61
60
  output,
62
- error,
61
+ errors,
63
62
  progress,
64
63
  username,
65
64
  usernamePath,
@@ -171,7 +170,7 @@ class TaskInfo extends Component {
171
170
  <b>{__('Troubleshooting')}</b>
172
171
  </span>
173
172
  </p>
174
- <p>{ReactHtmlParser(help)}</p>
173
+ <p dangerouslySetInnerHTML={{ __html: help }} />
175
174
  </Col>
176
175
  </Row>
177
176
  )}
@@ -187,7 +186,7 @@ class TaskInfo extends Component {
187
186
  </Col>
188
187
  </Row>
189
188
  )}
190
- {error && error.length > 0 && (
189
+ {errors && errors.length > 0 && (
191
190
  <Row>
192
191
  <Col xs={12}>
193
192
  <div>
@@ -195,7 +194,7 @@ class TaskInfo extends Component {
195
194
  <b>{__('Errors:')}</b>
196
195
  </span>
197
196
  </div>
198
- <pre>{error}</pre>
197
+ <pre>{errors}</pre>
199
198
  </Col>
200
199
  </Row>
201
200
  )}
@@ -213,7 +212,7 @@ TaskInfo.propTypes = {
213
212
  startedAt: PropTypes.string,
214
213
  state: PropTypes.string,
215
214
  help: PropTypes.string,
216
- error: PropTypes.array,
215
+ errors: PropTypes.array,
217
216
  progress: PropTypes.number,
218
217
  username: PropTypes.string,
219
218
  usernamePath: PropTypes.string,
@@ -232,7 +231,7 @@ TaskInfo.defaultProps = {
232
231
  startedAt: '',
233
232
  state: '',
234
233
  help: '',
235
- error: [],
234
+ errors: [],
236
235
  progress: 0,
237
236
  username: '',
238
237
  usernamePath: '',
@@ -0,0 +1,48 @@
1
+ import React from 'react';
2
+ import Skeleton from 'react-loading-skeleton';
3
+ import { Grid, Row, Col } from 'patternfly-react';
4
+
5
+ export const TaskSkeleton = () => {
6
+ const details = [1, 2, 3, 4, 5, 6];
7
+ return (
8
+ <Grid>
9
+ <br />
10
+ <Row>
11
+ <Col>
12
+ <Skeleton />
13
+ </Col>
14
+ </Row>
15
+ {details.map((items, key) => (
16
+ <Row key={key}>
17
+ <Col md={2} sm={6}>
18
+ <Skeleton />
19
+ </Col>
20
+ <Col md={5} sm={6}>
21
+ <Skeleton />
22
+ </Col>
23
+ <Col md={2} sm={6}>
24
+ <Skeleton />
25
+ </Col>
26
+ <Col md={3} sm={6}>
27
+ <Skeleton />
28
+ </Col>
29
+ </Row>
30
+ ))}
31
+ <br />
32
+ <Row>
33
+ <Col xs={6}>
34
+ <div className="progress-description">
35
+ <Skeleton />
36
+ </div>
37
+ </Col>
38
+ <Col xs={3} xsOffset={3} className="progress-label-top-right">
39
+ <Skeleton />
40
+ </Col>
41
+ <Col xs={12}>
42
+ <Skeleton />
43
+ </Col>
44
+ </Row>
45
+ <br />
46
+ </Grid>
47
+ );
48
+ };
@@ -6,7 +6,7 @@ const minProps = {
6
6
  id: 'task-id1',
7
7
  taskReload: true,
8
8
  cancelStep: jest.fn(),
9
- taskProgressToggle: jest.fn(),
9
+ taskReloadStart: jest.fn(),
10
10
  };
11
11
  const fixtures = {
12
12
  'render with min Props': minProps,
@@ -1,18 +1,13 @@
1
- import React from 'react';
2
- import {
3
- testComponentSnapshotsWithFixtures,
4
- mount,
5
- shallow,
6
- } from '@theforeman/test';
7
- import { useForemanModal } from 'foremanReact/components/ForemanModal/ForemanModalHooks';
1
+ import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
+ import { STATUS } from 'foremanReact/constants';
8
3
  import Task from '../Task';
9
- import {
10
- UNLOCK_MODAL,
11
- FORCE_UNLOCK_MODAL,
12
- } from '../../../TaskActions/TaskActionsConstants';
13
4
 
14
5
  const fixtures = {
15
- 'render without Props': { id: 'test' },
6
+ 'render with minimal Props': {
7
+ id: 'test',
8
+ taskReloadStart: jest.fn(),
9
+ taskProgressToggle: jest.fn(),
10
+ },
16
11
  'render with some Props': {
17
12
  id: 'test',
18
13
  state: 'paused',
@@ -21,64 +16,11 @@ const fixtures = {
21
16
  parentTask: 'parent-id',
22
17
  taskReload: true,
23
18
  canEdit: true,
19
+ status: STATUS.RESOLVED,
20
+ taskProgressToggle: jest.fn(),
21
+ taskReloadStart: jest.fn(),
24
22
  },
25
23
  };
26
24
 
27
- describe('Task', () => {
28
- describe('rendering', () =>
29
- testComponentSnapshotsWithFixtures(Task, fixtures));
30
- describe('click test', () => {
31
- const setModalOpen = jest.fn();
32
- useForemanModal.mockImplementation(id => ({
33
- setModalOpen: () => setModalOpen(id),
34
- }));
35
- const cancelTaskRequest = jest.fn();
36
- const resumeTaskRequest = jest.fn();
37
- const taskProgressToggle = jest.fn();
38
- const id = 'some-id';
39
- const action = 'some-action';
40
- const props = {
41
- taskReload: false,
42
- id,
43
- action,
44
- cancelTaskRequest,
45
- resumeTaskRequest,
46
- taskProgressToggle,
47
- };
48
- afterEach(() => {
49
- jest.clearAllMocks();
50
- });
51
- it('reload', () => {
52
- const component = mount(<Task {...props} />);
53
- const reloadButton = component.find('.reload-button').at(0);
54
- reloadButton.simulate('click');
55
- expect(taskProgressToggle).toBeCalled();
56
- });
57
- it('resume', () => {
58
- const component = shallow(<Task {...props} />);
59
- const resumeButton = component.find('.resume-button').at(0);
60
- resumeButton.props().onClick();
61
- expect(taskProgressToggle).toBeCalled();
62
- expect(resumeTaskRequest).toBeCalledWith(id, action);
63
- });
64
- it('cancel', () => {
65
- const component = shallow(<Task {...props} />);
66
- const cancelButton = component.find('.cancel-button').at(0);
67
- cancelButton.props().onClick();
68
- expect(taskProgressToggle).toBeCalled();
69
- expect(cancelTaskRequest).toBeCalledWith(id, action);
70
- });
71
- it('unlock', () => {
72
- const component = shallow(<Task {...props} />);
73
- const unlockButton = component.find('.unlock-button').at(0);
74
- unlockButton.props().onClick();
75
- expect(setModalOpen).toBeCalledWith({ id: UNLOCK_MODAL });
76
- });
77
- it('focrce unlock', () => {
78
- const component = shallow(<Task {...props} />);
79
- const forceUnlockButton = component.find('.force-unlock-button').at(0);
80
- forceUnlockButton.props().onClick();
81
- expect(setModalOpen).toBeCalledWith({ id: FORCE_UNLOCK_MODAL });
82
- });
83
- });
84
- });
25
+ describe('Task rendering', () =>
26
+ testComponentSnapshotsWithFixtures(Task, fixtures));
@@ -0,0 +1,95 @@
1
+ import React from 'react';
2
+ import {
3
+ testComponentSnapshotsWithFixtures,
4
+ mount,
5
+ shallow,
6
+ } from '@theforeman/test';
7
+ import { useForemanModal } from 'foremanReact/components/ForemanModal/ForemanModalHooks';
8
+ import { STATUS } from 'foremanReact/constants';
9
+ import { TaskButtons } from '../TaskButtons';
10
+ import {
11
+ UNLOCK_MODAL,
12
+ FORCE_UNLOCK_MODAL,
13
+ } from '../../../TaskActions/TaskActionsConstants';
14
+
15
+ const fixtures = {
16
+ 'render with minimal Props': {
17
+ id: 'test',
18
+ taskReloadStart: jest.fn(),
19
+ taskProgressToggle: jest.fn(),
20
+ },
21
+ 'render with some Props': {
22
+ id: 'test',
23
+ state: 'paused',
24
+ hasSubTasks: true,
25
+ dynflowEnableConsole: true,
26
+ parentTask: 'parent-id',
27
+ taskReload: true,
28
+ canEdit: true,
29
+ status: STATUS.RESOLVED,
30
+ taskReloadStart: jest.fn(),
31
+ taskProgressToggle: jest.fn(),
32
+ },
33
+ };
34
+
35
+ describe('Task', () => {
36
+ describe('rendering', () =>
37
+ testComponentSnapshotsWithFixtures(TaskButtons, fixtures));
38
+ describe('click test', () => {
39
+ const setModalOpen = jest.fn();
40
+ useForemanModal.mockImplementation(id => ({
41
+ setModalOpen: () => setModalOpen(id),
42
+ }));
43
+ const cancelTaskRequest = jest.fn();
44
+ const resumeTaskRequest = jest.fn();
45
+ const taskProgressToggle = jest.fn();
46
+ const taskReloadStart = jest.fn();
47
+ const id = 'some-id';
48
+ const action = 'some-action';
49
+ const props = {
50
+ taskReload: false,
51
+ id,
52
+ action,
53
+ cancelTaskRequest,
54
+ resumeTaskRequest,
55
+ taskProgressToggle,
56
+ taskReloadStart,
57
+ status: STATUS.RESOLVED,
58
+ };
59
+ afterEach(() => {
60
+ jest.clearAllMocks();
61
+ });
62
+ it('reload', () => {
63
+ const component = mount(<TaskButtons {...props} />);
64
+ const reloadButton = component.find('.reload-button').at(0);
65
+ reloadButton.simulate('click');
66
+ expect(taskProgressToggle).toBeCalled();
67
+ });
68
+ it('resume', () => {
69
+ const component = shallow(<TaskButtons {...props} />);
70
+ const resumeButton = component.find('.resume-button').at(0);
71
+ resumeButton.props().onClick();
72
+ expect(taskReloadStart).toBeCalled();
73
+ expect(resumeTaskRequest).toBeCalledWith(id, action);
74
+ });
75
+ it('cancel', () => {
76
+ const component = shallow(<TaskButtons {...props} />);
77
+ const cancelButton = component.find('.cancel-button').at(0);
78
+ cancelButton.props().onClick();
79
+ expect(taskReloadStart).toBeCalled();
80
+ expect(cancelTaskRequest).toBeCalledWith(id, action);
81
+ });
82
+ it('unlock', () => {
83
+ const component = shallow(<TaskButtons {...props} />);
84
+ const unlockButton = component.find('.unlock-button').at(0);
85
+ unlockButton.props().onClick();
86
+ expect(setModalOpen).toBeCalledWith({ id: UNLOCK_MODAL });
87
+ });
88
+ it('focrce unlock', () => {
89
+ const component = shallow(<TaskButtons {...props} />);
90
+ const forceUnlockButton = component.find('.force-unlock-button').at(0);
91
+ forceUnlockButton.props().onClick();
92
+ expect(setModalOpen).toBeCalledWith({ id: FORCE_UNLOCK_MODAL });
93
+ });
94
+ });
95
+ });