foreman-tasks 13.2.3 → 14.0.0
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.
- checksums.yaml +4 -4
- data/.github/workflows/js_tests.yml +6 -2
- data/.github/workflows/ruby_tests.yml +2 -2
- data/.github/workflows/test-breaking.yaml +1 -1
- data/README.md +29 -3
- data/app/assets/javascripts/foreman-tasks/locale/de/foreman_tasks.js +8 -8
- data/app/assets/javascripts/foreman-tasks/locale/en/foreman_tasks.js +1 -1
- data/app/assets/javascripts/foreman-tasks/locale/es/foreman_tasks.js +7 -7
- data/app/assets/javascripts/foreman-tasks/locale/fr/foreman_tasks.js +38 -38
- data/app/assets/javascripts/foreman-tasks/locale/ja/foreman_tasks.js +55 -55
- data/app/assets/javascripts/foreman-tasks/locale/ka/foreman_tasks.js +5 -5
- data/app/assets/javascripts/foreman-tasks/locale/ko/foreman_tasks.js +39 -39
- data/app/assets/javascripts/foreman-tasks/locale/pt_BR/foreman_tasks.js +6 -6
- data/app/assets/javascripts/foreman-tasks/locale/ru/foreman_tasks.js +5 -5
- data/app/assets/javascripts/foreman-tasks/locale/zh_CN/foreman_tasks.js +36 -36
- data/app/assets/javascripts/foreman-tasks/locale/zh_TW/foreman_tasks.js +6 -6
- data/eslint.spelling.config.js +52 -0
- data/lib/foreman_tasks/engine.rb +1 -1
- data/lib/foreman_tasks/version.rb +1 -1
- data/locale/de/LC_MESSAGES/foreman_tasks.mo +0 -0
- data/locale/de/foreman_tasks.po +8 -8
- data/locale/en/LC_MESSAGES/foreman_tasks.mo +0 -0
- data/locale/en/foreman_tasks.po +1 -1
- data/locale/es/LC_MESSAGES/foreman_tasks.mo +0 -0
- data/locale/es/foreman_tasks.po +7 -7
- data/locale/foreman_tasks.pot +2 -2
- data/locale/fr/LC_MESSAGES/foreman_tasks.mo +0 -0
- data/locale/fr/foreman_tasks.po +38 -38
- data/locale/ja/LC_MESSAGES/foreman_tasks.mo +0 -0
- data/locale/ja/foreman_tasks.po +55 -55
- data/locale/ka/LC_MESSAGES/foreman_tasks.mo +0 -0
- data/locale/ka/foreman_tasks.po +5 -5
- data/locale/ko/LC_MESSAGES/foreman_tasks.mo +0 -0
- data/locale/ko/foreman_tasks.po +39 -39
- data/locale/pt_BR/LC_MESSAGES/foreman_tasks.mo +0 -0
- data/locale/pt_BR/foreman_tasks.po +6 -6
- data/locale/ru/LC_MESSAGES/foreman_tasks.mo +0 -0
- data/locale/ru/foreman_tasks.po +5 -5
- data/locale/zh_CN/LC_MESSAGES/foreman_tasks.mo +0 -0
- data/locale/zh_CN/foreman_tasks.po +36 -36
- data/locale/zh_TW/LC_MESSAGES/foreman_tasks.mo +0 -0
- data/locale/zh_TW/foreman_tasks.po +6 -6
- data/package.json +12 -19
- data/webpack/ForemanTasks/Components/TaskActions/TaskAction.test.js +0 -4
- data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksBulkActions.test.js +414 -162
- metadata +2 -4
- data/.eslintrc +0 -4
- data/babel.config.js +0 -3
- data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksBulkActions.test.js.snap +0 -367
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { testActionSnapshotWithFixtures } from '@theforeman/test';
|
|
2
1
|
import { API } from 'foremanReact/redux/API';
|
|
3
2
|
import {
|
|
3
|
+
bulkByIdRequest,
|
|
4
|
+
bulkBySearchRequest,
|
|
4
5
|
bulkCancelById,
|
|
5
6
|
bulkCancelBySearch,
|
|
6
7
|
bulkResumeById,
|
|
@@ -8,10 +9,16 @@ import {
|
|
|
8
9
|
bulkForceCancelById,
|
|
9
10
|
bulkForceCancelBySearch,
|
|
10
11
|
} from '../TasksBulkActions';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
import {
|
|
13
|
+
TASKS_RESUME_REQUEST,
|
|
14
|
+
TASKS_RESUME_SUCCESS,
|
|
15
|
+
TASKS_RESUME_FAILURE,
|
|
16
|
+
TASKS_CANCEL_REQUEST,
|
|
17
|
+
TASKS_CANCEL_SUCCESS,
|
|
18
|
+
TASKS_FORCE_CANCEL_REQUEST,
|
|
19
|
+
TASKS_FORCE_CANCEL_SUCCESS,
|
|
20
|
+
TASKS_FORCE_CANCEL_FAILURE,
|
|
21
|
+
} from '../../TaskActions/TaskActionsConstants';
|
|
15
22
|
|
|
16
23
|
jest.mock('foremanReact/redux/API');
|
|
17
24
|
|
|
@@ -31,173 +38,279 @@ const task = {
|
|
|
31
38
|
can_edit: true,
|
|
32
39
|
};
|
|
33
40
|
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return bulkResumeById({ selected, reloadPage: jest.fn() });
|
|
42
|
-
},
|
|
43
|
-
'handles skipped bulkResumeById requests': () => {
|
|
44
|
-
const selected = [{ ...task, available_actions: { resumable: true } }];
|
|
45
|
-
|
|
46
|
-
API.post.mockImplementation(() => ({
|
|
47
|
-
data: {
|
|
48
|
-
skipped: [{ action: 'I am skipped' }],
|
|
49
|
-
},
|
|
50
|
-
}));
|
|
51
|
-
return bulkResumeById({ selected, reloadPage: jest.fn() });
|
|
52
|
-
},
|
|
53
|
-
'handles skipped bulkCancelById requests': () => {
|
|
54
|
-
const selected = [{ ...task, available_actions: { cancellable: true } }];
|
|
55
|
-
API.post.mockImplementation(() => ({
|
|
56
|
-
data: {
|
|
57
|
-
skipped: [{ action: 'I am skipped' }],
|
|
58
|
-
},
|
|
59
|
-
}));
|
|
60
|
-
return bulkCancelById({ selected, reloadPage: jest.fn() });
|
|
61
|
-
},
|
|
62
|
-
'handles bulkForceCancelById requests that fail': () => {
|
|
63
|
-
const selected = [
|
|
64
|
-
{
|
|
65
|
-
...task,
|
|
66
|
-
state: 'running',
|
|
67
|
-
can_edit: true,
|
|
68
|
-
},
|
|
69
|
-
];
|
|
70
|
-
|
|
71
|
-
API.post.mockImplementation(() =>
|
|
72
|
-
Promise.reject(new Error('Network Error'))
|
|
73
|
-
);
|
|
74
|
-
return bulkForceCancelById({
|
|
75
|
-
selected,
|
|
76
|
-
reloadPage: jest.fn(),
|
|
77
|
-
});
|
|
78
|
-
},
|
|
79
|
-
|
|
80
|
-
'handles bulkCancelById requests that are not cancellable': () => {
|
|
81
|
-
const selected = [{ ...task, available_actions: { cancellable: false } }];
|
|
82
|
-
return bulkCancelById({ selected, reloadPage: jest.fn() });
|
|
83
|
-
},
|
|
84
|
-
'handles bulkResumeById requests that are not resumable': () => {
|
|
85
|
-
const selected = [
|
|
86
|
-
{ ...task, available_actions: { resumable: false, cancellable: false } },
|
|
87
|
-
];
|
|
88
|
-
return bulkResumeById({ selected, reloadPage: jest.fn() });
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
'handles bulkForceCancelById requests that are stopped': () => {
|
|
92
|
-
const selected = [
|
|
93
|
-
{ ...task, available_actions: { resumable: false }, state: 'stopped' },
|
|
94
|
-
];
|
|
95
|
-
return bulkForceCancelById({
|
|
96
|
-
selected,
|
|
97
|
-
reloadPage: jest.fn(),
|
|
98
|
-
});
|
|
99
|
-
},
|
|
100
|
-
|
|
101
|
-
'handles bulkCancelBySearch requests': () => {
|
|
102
|
-
API.post.mockImplementation(() => ({
|
|
103
|
-
data: {
|
|
104
|
-
cancelled: [{ action: 'I am cancelled' }],
|
|
105
|
-
skipped: [{ action: 'I am skipped' }],
|
|
106
|
-
},
|
|
107
|
-
}));
|
|
108
|
-
return bulkCancelBySearch({
|
|
109
|
-
query: '',
|
|
110
|
-
parentTaskID: 'parent',
|
|
111
|
-
});
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
'handles bulkResumeBySearch requests': () => {
|
|
115
|
-
API.post.mockImplementation(() => ({
|
|
116
|
-
data: {
|
|
117
|
-
cancelled: [{ action: 'I am cancelled' }],
|
|
118
|
-
skipped: [{ action: 'I am skipped' }],
|
|
119
|
-
failed: [{ action: 'I am failed' }],
|
|
120
|
-
},
|
|
121
|
-
}));
|
|
122
|
-
return bulkResumeBySearch({
|
|
123
|
-
query: '',
|
|
124
|
-
parentTaskID: 'parent',
|
|
125
|
-
});
|
|
126
|
-
},
|
|
127
|
-
'handles bulkForceCancelBySearch requests': () =>
|
|
128
|
-
bulkForceCancelBySearch({
|
|
129
|
-
query: '',
|
|
130
|
-
parentTaskID: 'parent',
|
|
131
|
-
}),
|
|
132
|
-
'handles bulkCancelById requests with canEdit false': () => {
|
|
133
|
-
const selected = [
|
|
134
|
-
{
|
|
135
|
-
...task,
|
|
136
|
-
available_actions: { cancellable: true },
|
|
137
|
-
can_edit: false,
|
|
138
|
-
},
|
|
139
|
-
];
|
|
140
|
-
return bulkCancelById({ selected, reloadPage: jest.fn() });
|
|
141
|
-
},
|
|
142
|
-
'handles bulkResumeById requests with canEdit false': () => {
|
|
143
|
-
const selected = [
|
|
144
|
-
{
|
|
145
|
-
...task,
|
|
146
|
-
available_actions: { resumable: true },
|
|
147
|
-
can_edit: false,
|
|
148
|
-
},
|
|
149
|
-
];
|
|
150
|
-
return bulkResumeById({ selected, reloadPage: jest.fn() });
|
|
151
|
-
},
|
|
152
|
-
'handles bulkForceCancelById requests with canEdit false': () => {
|
|
153
|
-
const selected = [
|
|
154
|
-
{
|
|
155
|
-
...task,
|
|
156
|
-
state: 'running',
|
|
157
|
-
available_actions: { resumable: false },
|
|
158
|
-
can_edit: false,
|
|
159
|
-
},
|
|
160
|
-
];
|
|
161
|
-
return bulkForceCancelById({ selected, reloadPage: jest.fn() });
|
|
162
|
-
},
|
|
41
|
+
const expectToastDispatch = (dispatch, callIndex, { message, type }) => {
|
|
42
|
+
expect(dispatch.mock.calls[callIndex][0]).toEqual({
|
|
43
|
+
type: 'TOASTS_ADD',
|
|
44
|
+
payload: {
|
|
45
|
+
message: { message, type },
|
|
46
|
+
},
|
|
47
|
+
});
|
|
163
48
|
};
|
|
164
49
|
|
|
165
50
|
describe('TasksBulkActions', () => {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
51
|
+
beforeEach(() => {
|
|
52
|
+
jest.clearAllMocks();
|
|
53
|
+
API.post.mockResolvedValue({ data: {} });
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('bulkByIdRequest', () => {
|
|
57
|
+
it('posts task ids to the bulk action path', async () => {
|
|
58
|
+
await bulkByIdRequest([task], 'bulk_resume');
|
|
59
|
+
|
|
60
|
+
expect(API.post).toHaveBeenCalledWith(
|
|
61
|
+
'/foreman_tasks/api/tasks/bulk_resume',
|
|
62
|
+
{ task_ids: [task.id] }
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('bulkBySearchRequest', () => {
|
|
68
|
+
it('posts the search query', async () => {
|
|
69
|
+
await bulkBySearchRequest({
|
|
70
|
+
query: 'state=running',
|
|
71
|
+
parentTaskID: null,
|
|
72
|
+
path: 'bulk_cancel',
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
expect(API.post).toHaveBeenCalledWith(
|
|
76
|
+
'/foreman_tasks/api/tasks/bulk_cancel',
|
|
77
|
+
{ search: 'state=running' }
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('appends parent_task_id to the search when parentTaskID is set', async () => {
|
|
82
|
+
await bulkBySearchRequest({
|
|
83
|
+
query: '',
|
|
84
|
+
parentTaskID: 'parent',
|
|
85
|
+
path: 'bulk_resume',
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
expect(API.post).toHaveBeenCalledWith(
|
|
89
|
+
'/foreman_tasks/api/tasks/bulk_resume',
|
|
90
|
+
{ search: 'parent_task_id=parent' }
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('combines query and parent_task_id', async () => {
|
|
95
|
+
await bulkBySearchRequest({
|
|
96
|
+
query: 'state=running',
|
|
97
|
+
parentTaskID: 'parent',
|
|
98
|
+
path: 'bulk_stop',
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
expect(API.post).toHaveBeenCalledWith(
|
|
102
|
+
'/foreman_tasks/api/tasks/bulk_stop',
|
|
103
|
+
{ search: ' state=running and parent_task_id=parent' }
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
169
107
|
|
|
170
|
-
|
|
108
|
+
describe('bulkResumeById', () => {
|
|
109
|
+
it('dispatches success toasts and reloads when tasks are resumed', async () => {
|
|
110
|
+
const selected = [{ ...task, available_actions: { resumable: true } }];
|
|
111
|
+
API.post.mockResolvedValue({
|
|
171
112
|
data: {
|
|
172
113
|
resumed: [{ action: 'I am resumed' }],
|
|
173
114
|
failed: [{ action: 'I am failed' }],
|
|
174
115
|
},
|
|
175
|
-
}));
|
|
176
|
-
const reloadPage = jest.fn();
|
|
177
|
-
const action = bulkResumeById({
|
|
178
|
-
selected,
|
|
179
|
-
reloadPage,
|
|
180
116
|
});
|
|
117
|
+
const reloadPage = jest.fn();
|
|
181
118
|
const dispatch = jest.fn();
|
|
182
|
-
|
|
119
|
+
|
|
120
|
+
await bulkResumeById({ selected, reloadPage })(dispatch);
|
|
121
|
+
|
|
183
122
|
expect(reloadPage).toHaveBeenCalled();
|
|
184
|
-
expect(dispatch.mock.calls).
|
|
123
|
+
expect(dispatch.mock.calls[0][0]).toEqual({
|
|
124
|
+
type: TASKS_RESUME_REQUEST,
|
|
125
|
+
});
|
|
126
|
+
expect(dispatch.mock.calls[1][0]).toEqual({
|
|
127
|
+
type: TASKS_RESUME_SUCCESS,
|
|
128
|
+
});
|
|
129
|
+
expectToastDispatch(dispatch, 2, {
|
|
130
|
+
message: 'I am resumed Task execution was resumed',
|
|
131
|
+
type: 'success',
|
|
132
|
+
});
|
|
133
|
+
expectToastDispatch(dispatch, 3, {
|
|
134
|
+
message: 'I am failed Task execution could not be resumed',
|
|
135
|
+
type: 'error',
|
|
136
|
+
});
|
|
137
|
+
expect(API.post).toHaveBeenCalledWith(
|
|
138
|
+
'/foreman_tasks/api/tasks/bulk_resume',
|
|
139
|
+
{ task_ids: [task.id] }
|
|
140
|
+
);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('does not reload when nothing was resumed', async () => {
|
|
144
|
+
const selected = [{ ...task, available_actions: { resumable: true } }];
|
|
145
|
+
API.post.mockResolvedValue({
|
|
146
|
+
data: {
|
|
147
|
+
skipped: [{ action: 'I am skipped' }],
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
const reloadPage = jest.fn();
|
|
151
|
+
const dispatch = jest.fn();
|
|
152
|
+
|
|
153
|
+
await bulkResumeById({ selected, reloadPage })(dispatch);
|
|
154
|
+
|
|
155
|
+
expect(reloadPage).not.toHaveBeenCalled();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('handles skipped tasks in the API response', async () => {
|
|
159
|
+
const selected = [{ ...task, available_actions: { resumable: true } }];
|
|
160
|
+
API.post.mockResolvedValue({
|
|
161
|
+
data: {
|
|
162
|
+
skipped: [{ action: 'I am skipped' }],
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
const dispatch = jest.fn();
|
|
166
|
+
|
|
167
|
+
await bulkResumeById({ selected, reloadPage: jest.fn() })(dispatch);
|
|
168
|
+
|
|
169
|
+
expect(dispatch.mock.calls[0][0]).toEqual({
|
|
170
|
+
type: TASKS_RESUME_REQUEST,
|
|
171
|
+
});
|
|
172
|
+
expect(dispatch.mock.calls[1][0]).toEqual({
|
|
173
|
+
type: TASKS_RESUME_SUCCESS,
|
|
174
|
+
});
|
|
175
|
+
expectToastDispatch(dispatch, 2, {
|
|
176
|
+
message: 'I am skipped Task execution task has to be resumable',
|
|
177
|
+
type: 'warning',
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('handles API failure', async () => {
|
|
182
|
+
const selected = [{ ...task, available_actions: { resumable: true } }];
|
|
183
|
+
API.post.mockRejectedValue(new Error('Network Error'));
|
|
184
|
+
const dispatch = jest.fn();
|
|
185
|
+
|
|
186
|
+
await bulkResumeById({ selected, reloadPage: jest.fn() })(dispatch);
|
|
187
|
+
|
|
188
|
+
expect(dispatch.mock.calls[0][0]).toEqual({
|
|
189
|
+
type: TASKS_RESUME_REQUEST,
|
|
190
|
+
});
|
|
191
|
+
expect(dispatch.mock.calls[1][0]).toEqual({
|
|
192
|
+
type: TASKS_RESUME_FAILURE,
|
|
193
|
+
error: expect.any(Error),
|
|
194
|
+
});
|
|
195
|
+
expectToastDispatch(dispatch, 2, {
|
|
196
|
+
message: 'Cannot resume tasks at the moment Error: Network Error',
|
|
197
|
+
type: 'error',
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('warns when selected tasks are not resumable', async () => {
|
|
202
|
+
const selected = [
|
|
203
|
+
{ ...task, available_actions: { resumable: false, cancellable: false } },
|
|
204
|
+
];
|
|
205
|
+
const dispatch = jest.fn();
|
|
206
|
+
|
|
207
|
+
await bulkResumeById({ selected, reloadPage: jest.fn() })(dispatch);
|
|
208
|
+
|
|
209
|
+
expect(API.post).not.toHaveBeenCalled();
|
|
210
|
+
expectToastDispatch(dispatch, 0, {
|
|
211
|
+
message: 'Not all the selected tasks can be resumed',
|
|
212
|
+
type: 'warning',
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('warns when the user cannot edit resumable tasks', async () => {
|
|
217
|
+
const selected = [
|
|
218
|
+
{
|
|
219
|
+
...task,
|
|
220
|
+
available_actions: { resumable: true },
|
|
221
|
+
can_edit: false,
|
|
222
|
+
},
|
|
223
|
+
];
|
|
224
|
+
const dispatch = jest.fn();
|
|
225
|
+
|
|
226
|
+
await bulkResumeById({ selected, reloadPage: jest.fn() })(dispatch);
|
|
227
|
+
|
|
228
|
+
expect(API.post).not.toHaveBeenCalled();
|
|
229
|
+
expectToastDispatch(dispatch, 0, {
|
|
230
|
+
message: 'Not all the selected tasks can be resumed',
|
|
231
|
+
type: 'warning',
|
|
232
|
+
});
|
|
185
233
|
});
|
|
186
|
-
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
describe('bulkCancelById', () => {
|
|
237
|
+
it('dispatches success toasts and reloads when tasks are cancelled', async () => {
|
|
187
238
|
const selected = [{ ...task, available_actions: { cancellable: true } }];
|
|
188
|
-
API.post.
|
|
239
|
+
API.post.mockResolvedValue({
|
|
189
240
|
data: {
|
|
190
241
|
cancelled: [{ action: 'I am cancelled' }],
|
|
191
242
|
},
|
|
192
|
-
})
|
|
243
|
+
});
|
|
193
244
|
const reloadPage = jest.fn();
|
|
194
|
-
const action = bulkCancelById({ selected, reloadPage });
|
|
195
245
|
const dispatch = jest.fn();
|
|
196
|
-
|
|
246
|
+
|
|
247
|
+
await bulkCancelById({ selected, reloadPage })(dispatch);
|
|
248
|
+
|
|
197
249
|
expect(reloadPage).toHaveBeenCalled();
|
|
198
|
-
expect(dispatch.mock.calls).
|
|
250
|
+
expect(dispatch.mock.calls[0][0]).toEqual({
|
|
251
|
+
type: TASKS_CANCEL_REQUEST,
|
|
252
|
+
});
|
|
253
|
+
expect(dispatch.mock.calls[1][0]).toEqual({
|
|
254
|
+
type: TASKS_CANCEL_SUCCESS,
|
|
255
|
+
});
|
|
256
|
+
expectToastDispatch(dispatch, 2, {
|
|
257
|
+
message: 'I am cancelled Task execution was cancelled',
|
|
258
|
+
type: 'success',
|
|
259
|
+
});
|
|
199
260
|
});
|
|
200
|
-
|
|
261
|
+
|
|
262
|
+
it('handles skipped tasks in the API response', async () => {
|
|
263
|
+
const selected = [{ ...task, available_actions: { cancellable: true } }];
|
|
264
|
+
API.post.mockResolvedValue({
|
|
265
|
+
data: {
|
|
266
|
+
skipped: [{ action: 'I am skipped' }],
|
|
267
|
+
},
|
|
268
|
+
});
|
|
269
|
+
const dispatch = jest.fn();
|
|
270
|
+
|
|
271
|
+
await bulkCancelById({ selected, reloadPage: jest.fn() })(dispatch);
|
|
272
|
+
|
|
273
|
+
expectToastDispatch(dispatch, 2, {
|
|
274
|
+
message: 'I am skipped Task execution task has to be cancellable',
|
|
275
|
+
type: 'warning',
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('warns when selected tasks are not cancellable', async () => {
|
|
280
|
+
const selected = [{ ...task, available_actions: { cancellable: false } }];
|
|
281
|
+
const dispatch = jest.fn();
|
|
282
|
+
|
|
283
|
+
await bulkCancelById({ selected, reloadPage: jest.fn() })(dispatch);
|
|
284
|
+
|
|
285
|
+
expect(API.post).not.toHaveBeenCalled();
|
|
286
|
+
expectToastDispatch(dispatch, 0, {
|
|
287
|
+
message: 'Not all the selected tasks can be cancelled',
|
|
288
|
+
type: 'warning',
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it('warns when the user cannot edit cancellable tasks', async () => {
|
|
293
|
+
const selected = [
|
|
294
|
+
{
|
|
295
|
+
...task,
|
|
296
|
+
available_actions: { cancellable: true },
|
|
297
|
+
can_edit: false,
|
|
298
|
+
},
|
|
299
|
+
];
|
|
300
|
+
const dispatch = jest.fn();
|
|
301
|
+
|
|
302
|
+
await bulkCancelById({ selected, reloadPage: jest.fn() })(dispatch);
|
|
303
|
+
|
|
304
|
+
expect(API.post).not.toHaveBeenCalled();
|
|
305
|
+
expectToastDispatch(dispatch, 0, {
|
|
306
|
+
message: 'Not all the selected tasks can be cancelled',
|
|
307
|
+
type: 'warning',
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
describe('bulkForceCancelById', () => {
|
|
313
|
+
it('dispatches success and warning toasts and reloads on success', async () => {
|
|
201
314
|
const selected = [
|
|
202
315
|
{
|
|
203
316
|
...task,
|
|
@@ -205,23 +318,162 @@ describe('TasksBulkActions', () => {
|
|
|
205
318
|
can_edit: true,
|
|
206
319
|
},
|
|
207
320
|
];
|
|
208
|
-
|
|
209
|
-
API.post.mockImplementation(() => ({
|
|
321
|
+
API.post.mockResolvedValue({
|
|
210
322
|
data: {
|
|
211
323
|
stopped_length: 2,
|
|
212
324
|
skipped_length: 4,
|
|
213
325
|
},
|
|
214
|
-
}));
|
|
215
|
-
const reloadPage = jest.fn();
|
|
216
|
-
const action = bulkForceCancelById({
|
|
217
|
-
selected,
|
|
218
|
-
reloadPage,
|
|
219
326
|
});
|
|
327
|
+
const reloadPage = jest.fn();
|
|
220
328
|
const dispatch = jest.fn();
|
|
221
|
-
|
|
329
|
+
|
|
330
|
+
await bulkForceCancelById({ selected, reloadPage })(dispatch);
|
|
331
|
+
|
|
222
332
|
expect(reloadPage).toHaveBeenCalled();
|
|
223
|
-
expect(dispatch.mock.calls).
|
|
333
|
+
expect(dispatch.mock.calls[0][0]).toEqual({
|
|
334
|
+
type: TASKS_FORCE_CANCEL_REQUEST,
|
|
335
|
+
});
|
|
336
|
+
expect(dispatch.mock.calls[1][0]).toEqual({
|
|
337
|
+
type: TASKS_FORCE_CANCEL_SUCCESS,
|
|
338
|
+
});
|
|
339
|
+
expectToastDispatch(dispatch, 2, {
|
|
340
|
+
message: '2 task(s) cancelled with force',
|
|
341
|
+
type: 'success',
|
|
342
|
+
});
|
|
343
|
+
expectToastDispatch(dispatch, 3, {
|
|
344
|
+
message: '4 task(s) are already stopped',
|
|
345
|
+
type: 'warning',
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it('handles API failure', async () => {
|
|
350
|
+
const selected = [
|
|
351
|
+
{
|
|
352
|
+
...task,
|
|
353
|
+
state: 'running',
|
|
354
|
+
can_edit: true,
|
|
355
|
+
},
|
|
356
|
+
];
|
|
357
|
+
API.post.mockRejectedValue(new Error('Network Error'));
|
|
358
|
+
const dispatch = jest.fn();
|
|
359
|
+
|
|
360
|
+
await bulkForceCancelById({ selected, reloadPage: jest.fn() })(dispatch);
|
|
361
|
+
|
|
362
|
+
expect(dispatch.mock.calls[0][0]).toEqual({
|
|
363
|
+
type: TASKS_FORCE_CANCEL_REQUEST,
|
|
364
|
+
});
|
|
365
|
+
expect(dispatch.mock.calls[1][0]).toEqual({
|
|
366
|
+
type: TASKS_FORCE_CANCEL_FAILURE,
|
|
367
|
+
error: expect.any(Error),
|
|
368
|
+
});
|
|
369
|
+
expectToastDispatch(dispatch, 2, {
|
|
370
|
+
message: 'Cannot force cancel tasks at the moment Error: Network Error',
|
|
371
|
+
type: 'error',
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it('warns when all selected tasks are already stopped', async () => {
|
|
376
|
+
const selected = [
|
|
377
|
+
{
|
|
378
|
+
...task,
|
|
379
|
+
available_actions: { resumable: false },
|
|
380
|
+
state: 'stopped',
|
|
381
|
+
},
|
|
382
|
+
];
|
|
383
|
+
const dispatch = jest.fn();
|
|
384
|
+
|
|
385
|
+
await bulkForceCancelById({ selected, reloadPage: jest.fn() })(dispatch);
|
|
386
|
+
|
|
387
|
+
expect(API.post).not.toHaveBeenCalled();
|
|
388
|
+
expectToastDispatch(dispatch, 0, {
|
|
389
|
+
message: '1 task(s) are already stopped',
|
|
390
|
+
type: 'warning',
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
it('warns when the user lacks permission to force cancel', async () => {
|
|
395
|
+
const selected = [
|
|
396
|
+
{
|
|
397
|
+
...task,
|
|
398
|
+
state: 'running',
|
|
399
|
+
available_actions: { resumable: false },
|
|
400
|
+
can_edit: false,
|
|
401
|
+
},
|
|
402
|
+
];
|
|
403
|
+
const dispatch = jest.fn();
|
|
404
|
+
|
|
405
|
+
await bulkForceCancelById({ selected, reloadPage: jest.fn() })(dispatch);
|
|
406
|
+
|
|
407
|
+
expect(API.post).not.toHaveBeenCalled();
|
|
408
|
+
expectToastDispatch(dispatch, 0, {
|
|
409
|
+
message: 'User has no permission for 1 task(s)',
|
|
410
|
+
type: 'warning',
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
describe('bulk search actions', () => {
|
|
416
|
+
it('bulkCancelBySearch dispatches request and info toast', async () => {
|
|
417
|
+
const dispatch = jest.fn();
|
|
418
|
+
|
|
419
|
+
await bulkCancelBySearch({
|
|
420
|
+
query: '',
|
|
421
|
+
parentTaskID: 'parent',
|
|
422
|
+
})(dispatch);
|
|
423
|
+
|
|
424
|
+
expect(dispatch.mock.calls[0][0]).toEqual({
|
|
425
|
+
type: TASKS_CANCEL_REQUEST,
|
|
426
|
+
});
|
|
427
|
+
expectToastDispatch(dispatch, 1, {
|
|
428
|
+
message: 'Canceling selected tasks, this might take a while',
|
|
429
|
+
type: 'info',
|
|
430
|
+
});
|
|
431
|
+
expect(API.post).toHaveBeenCalledWith(
|
|
432
|
+
'/foreman_tasks/api/tasks/bulk_cancel',
|
|
433
|
+
{ search: 'parent_task_id=parent' }
|
|
434
|
+
);
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
it('bulkResumeBySearch dispatches request and info toast', async () => {
|
|
438
|
+
const dispatch = jest.fn();
|
|
439
|
+
|
|
440
|
+
await bulkResumeBySearch({
|
|
441
|
+
query: '',
|
|
442
|
+
parentTaskID: 'parent',
|
|
443
|
+
})(dispatch);
|
|
444
|
+
|
|
445
|
+
expect(dispatch.mock.calls[0][0]).toEqual({
|
|
446
|
+
type: TASKS_RESUME_REQUEST,
|
|
447
|
+
});
|
|
448
|
+
expectToastDispatch(dispatch, 1, {
|
|
449
|
+
message: 'Resuming selected tasks, this might take a while',
|
|
450
|
+
type: 'info',
|
|
451
|
+
});
|
|
452
|
+
expect(API.post).toHaveBeenCalledWith(
|
|
453
|
+
'/foreman_tasks/api/tasks/bulk_resume',
|
|
454
|
+
{ search: 'parent_task_id=parent' }
|
|
455
|
+
);
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
it('bulkForceCancelBySearch dispatches request and info toast', async () => {
|
|
459
|
+
const dispatch = jest.fn();
|
|
460
|
+
|
|
461
|
+
await bulkForceCancelBySearch({
|
|
462
|
+
query: '',
|
|
463
|
+
parentTaskID: 'parent',
|
|
464
|
+
})(dispatch);
|
|
465
|
+
|
|
466
|
+
expect(dispatch.mock.calls[0][0]).toEqual({
|
|
467
|
+
type: TASKS_FORCE_CANCEL_REQUEST,
|
|
468
|
+
});
|
|
469
|
+
expectToastDispatch(dispatch, 1, {
|
|
470
|
+
message: 'Canceling with force selected tasks, this might take a while',
|
|
471
|
+
type: 'info',
|
|
472
|
+
});
|
|
473
|
+
expect(API.post).toHaveBeenCalledWith(
|
|
474
|
+
'/foreman_tasks/api/tasks/bulk_stop',
|
|
475
|
+
{ search: 'parent_task_id=parent' }
|
|
476
|
+
);
|
|
224
477
|
});
|
|
225
478
|
});
|
|
226
|
-
testActionSnapshotWithFixtures(fixtures);
|
|
227
479
|
});
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: foreman-tasks
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 14.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ivan Nečas
|
|
@@ -92,7 +92,6 @@ extra_rdoc_files:
|
|
|
92
92
|
- LICENSE
|
|
93
93
|
- README.md
|
|
94
94
|
files:
|
|
95
|
-
- ".eslintrc"
|
|
96
95
|
- ".github/workflows/js_tests.yml"
|
|
97
96
|
- ".github/workflows/release.yml"
|
|
98
97
|
- ".github/workflows/ruby_tests.yml"
|
|
@@ -221,7 +220,6 @@ files:
|
|
|
221
220
|
- app/views/foreman_tasks/tasks/dashboard/_tasks_status.html.erb
|
|
222
221
|
- app/views/tasks_mailer/long_tasks.html.erb
|
|
223
222
|
- app/views/tasks_mailer/long_tasks.text.erb
|
|
224
|
-
- babel.config.js
|
|
225
223
|
- bin/dynflow-executor
|
|
226
224
|
- bin/foreman-tasks
|
|
227
225
|
- config/foreman-tasks.yaml.example
|
|
@@ -262,6 +260,7 @@ files:
|
|
|
262
260
|
- db/seeds.d/95-mail_notifications.rb
|
|
263
261
|
- deploy/foreman-tasks.service
|
|
264
262
|
- deploy/foreman-tasks.sysconfig
|
|
263
|
+
- eslint.spelling.config.js
|
|
265
264
|
- extra/dynflow-debug.sh
|
|
266
265
|
- extra/dynflow-executor.example
|
|
267
266
|
- extra/foreman-tasks-cleanup.sh
|
|
@@ -469,7 +468,6 @@ files:
|
|
|
469
468
|
- webpack/ForemanTasks/Components/TasksTable/__tests__/TasksIndexPage.test.js
|
|
470
469
|
- webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTable.fixtures.js
|
|
471
470
|
- webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTableHelpers.test.js
|
|
472
|
-
- webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksBulkActions.test.js.snap
|
|
473
471
|
- webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js
|
|
474
472
|
- webpack/ForemanTasks/Components/common/ClickConfirmation/index.js
|
|
475
473
|
- webpack/ForemanTasks/Components/common/ToastsHelpers/ToastTypesConstants.js
|
data/.eslintrc
DELETED
data/babel.config.js
DELETED