foreman_webhooks 5.0.3 → 6.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/Rakefile +0 -15
- data/app/models/webhook.rb +1 -1
- data/lib/foreman_webhooks/engine.rb +1 -1
- data/lib/foreman_webhooks/version.rb +1 -1
- data/webpack/ForemanWebhooks/Routes/ForemanWebhooksRoutes.js +1 -1
- data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/Components/WebhookFormTabs.js +4 -6
- data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookTable/Components/Formatters/__tests__/actionCellFormatter.test.js +109 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookTable/Components/Formatters/__tests__/enabledCellFormatter.test.js +38 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookTable/Components/Formatters/__tests__/nameToEditFormatter.test.js +82 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookTable/Components/Formatters/actionCellFormatter.js +23 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/{WebhooksIndexPage/Components/WebhooksTable/Components/EnabledCell.js → Components/WebhookTable/Components/Formatters/enabledCellFormatter.js} +6 -1
- data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookTable/Components/Formatters/nameToEditFormatter.js +33 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookCreateModal.js +1 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookDeleteModal.js +5 -1
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookEditModal.js +1 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookTestModal.js +1 -2
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/WebhooksIndexPage.js +120 -16
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/__tests__/WebhooksIndexPage.test.js +130 -22
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/__tests__/integration.test.js +10 -3
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/__tests__/mocks/MockForemanTableIndexPage.js +37 -0
- data/webpack/ForemanWebhooks/Routes/Webhooks/constants.js +3 -3
- data/webpack/test_setup.js +3 -0
- metadata +18 -96
- data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/Components/FieldConstructor.js +0 -312
- data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/Components/__tests__/FieldConstructor.test.js +0 -216
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/Components/EmptyWebhooksTable/index.js +0 -29
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/Components/Formatters/__tests__/__snapshots__/enabledCellFormatter.test.js.snap +0 -7
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/Components/Formatters/__tests__/enabledCellFormatter.test.js +0 -7
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/Components/Formatters/actionCellFormatter.js +0 -20
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/Components/Formatters/enabledCellFormatter.js +0 -6
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/Components/Formatters/index.js +0 -3
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/Components/Formatters/nameToEditFormatter.js +0 -19
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/Components/NameToEditCell.js +0 -42
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/Components/__tests__/EnabledCell.test.js +0 -14
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/Components/__tests__/__snapshots__/EnabledCell.test.js.snap +0 -5
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/WebhooksTable.js +0 -121
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/WebhooksTableSchema.js +0 -48
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/__tests__/WebhooksTable.test.js +0 -64
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/__tests__/__snapshots__/WebhooksTable.test.js.snap +0 -250
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/index.js +0 -76
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/__tests__/__snapshots__/WebhooksIndexPage.test.js.snap +0 -17
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/index.js +0 -3
- data/webpack/__mocks__/foremanReact/Root/Context/ForemanContext.js +0 -1
- data/webpack/__mocks__/foremanReact/common/HOC.js +0 -30
- data/webpack/__mocks__/foremanReact/common/I18n.js +0 -7
- data/webpack/__mocks__/foremanReact/common/helpers.js +0 -7
- data/webpack/__mocks__/foremanReact/common/urlHelpers.js +0 -8
- data/webpack/__mocks__/foremanReact/components/ForemanModal/ForemanModalActions.js +0 -2
- data/webpack/__mocks__/foremanReact/components/ForemanModal/ForemanModalHooks.js +0 -10
- data/webpack/__mocks__/foremanReact/components/ForemanModal/index.js +0 -23
- data/webpack/__mocks__/foremanReact/components/Layout/LayoutActions.js +0 -2
- data/webpack/__mocks__/foremanReact/components/Loading/Loading.js +0 -2
- data/webpack/__mocks__/foremanReact/components/Loading/index.js +0 -3
- data/webpack/__mocks__/foremanReact/components/PF4/TableIndexPage/TableIndexPage.js +0 -10
- data/webpack/__mocks__/foremanReact/components/Pagination/index.js +0 -4
- data/webpack/__mocks__/foremanReact/components/common/ActionButtons/ActionButtons.js +0 -3
- data/webpack/__mocks__/foremanReact/components/common/EmptyState.js +0 -5
- data/webpack/__mocks__/foremanReact/components/common/forms/ForemanForm.js +0 -9
- data/webpack/__mocks__/foremanReact/components/common/forms/FormField.js +0 -3
- data/webpack/__mocks__/foremanReact/components/common/table.js +0 -26
- data/webpack/__mocks__/foremanReact/constants.js +0 -24
- data/webpack/__mocks__/foremanReact/history.js +0 -3
- data/webpack/__mocks__/foremanReact/redux/API/APISelectors.js +0 -6
- data/webpack/__mocks__/foremanReact/redux/API/index.js +0 -10
- data/webpack/__mocks__/foremanReact/redux/actions/common/forms.js +0 -1
- data/webpack/__mocks__/foremanReact/redux/actions/toasts.js +0 -8
- data/webpack/__mocks__/foremanReact/routes/common/PageLayout/PageLayout.js +0 -10
- /data/webpack/ForemanWebhooks/Routes/Webhooks/{WebhooksIndexPage/Components/WebhooksTable → Components/WebhookTable}/Components/ActionButtons/ActionButton.js +0 -0
data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/Components/FieldConstructor.js
DELETED
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-lines */
|
|
2
|
-
import React, { useEffect, useState } from 'react';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
import AutocompleteInput from 'foremanReact/components/common/AutocompleteInput/AutocompleteInput';
|
|
5
|
-
import { translate as __ } from 'foremanReact/common/I18n';
|
|
6
|
-
import {
|
|
7
|
-
ExclamationCircleIcon,
|
|
8
|
-
HelpIcon,
|
|
9
|
-
PencilAltIcon,
|
|
10
|
-
} from '@patternfly/react-icons';
|
|
11
|
-
import {
|
|
12
|
-
TextInput,
|
|
13
|
-
Checkbox,
|
|
14
|
-
Button,
|
|
15
|
-
FormHelperText,
|
|
16
|
-
HelperText,
|
|
17
|
-
HelperTextItem,
|
|
18
|
-
Icon,
|
|
19
|
-
TextArea,
|
|
20
|
-
FormGroup,
|
|
21
|
-
Popover,
|
|
22
|
-
Grid,
|
|
23
|
-
GridItem,
|
|
24
|
-
} from '@patternfly/react-core';
|
|
25
|
-
|
|
26
|
-
const FormField = ({
|
|
27
|
-
name,
|
|
28
|
-
type,
|
|
29
|
-
required,
|
|
30
|
-
options,
|
|
31
|
-
validated,
|
|
32
|
-
value,
|
|
33
|
-
disabled,
|
|
34
|
-
setValue,
|
|
35
|
-
placeholder,
|
|
36
|
-
errMsg,
|
|
37
|
-
fieldId,
|
|
38
|
-
setIsPasswordDisabled,
|
|
39
|
-
...props
|
|
40
|
-
}) => {
|
|
41
|
-
const [fieldValidated, setFieldValidated] = useState('default');
|
|
42
|
-
const [firstLoad, setFirstLoad] = useState(true);
|
|
43
|
-
|
|
44
|
-
const requiredValidate = () => {
|
|
45
|
-
if (firstLoad || !required) return;
|
|
46
|
-
if (!value || value === '' || validated === 'error')
|
|
47
|
-
setFieldValidated('error');
|
|
48
|
-
else setFieldValidated('success');
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const localHandler = (_event, newValue) => {
|
|
52
|
-
setValue(name, newValue);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
setFirstLoad(false);
|
|
57
|
-
}, []);
|
|
58
|
-
|
|
59
|
-
useEffect(() => {
|
|
60
|
-
requiredValidate();
|
|
61
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
62
|
-
}, [value]);
|
|
63
|
-
|
|
64
|
-
if (type === 'checkbox') {
|
|
65
|
-
return (
|
|
66
|
-
<>
|
|
67
|
-
<Checkbox
|
|
68
|
-
ouiaId={name}
|
|
69
|
-
id={fieldId ?? `id-${name}`}
|
|
70
|
-
isChecked={value || false}
|
|
71
|
-
onChange={(_, newValue) => {
|
|
72
|
-
setValue(name, newValue);
|
|
73
|
-
}}
|
|
74
|
-
isDisabled={disabled}
|
|
75
|
-
isRequired={required}
|
|
76
|
-
type={type}
|
|
77
|
-
validated={fieldValidated}
|
|
78
|
-
/>
|
|
79
|
-
<ValidationComponent localValidated={fieldValidated} errMsg={errMsg} />
|
|
80
|
-
</>
|
|
81
|
-
);
|
|
82
|
-
} else if (type === 'textarea') {
|
|
83
|
-
return (
|
|
84
|
-
<>
|
|
85
|
-
<TextArea
|
|
86
|
-
rows={6}
|
|
87
|
-
name={name}
|
|
88
|
-
id={fieldId ?? `id-${name}`}
|
|
89
|
-
value={value ?? ''}
|
|
90
|
-
onChange={(_, newValue) => setValue(name, newValue)}
|
|
91
|
-
isRequired={required}
|
|
92
|
-
isDisabled={disabled}
|
|
93
|
-
type={type}
|
|
94
|
-
validated={fieldValidated}
|
|
95
|
-
placeholder={placeholder}
|
|
96
|
-
/>
|
|
97
|
-
<ValidationComponent localValidated={fieldValidated} errMsg={errMsg} />
|
|
98
|
-
</>
|
|
99
|
-
);
|
|
100
|
-
} else if (options.length !== 0) {
|
|
101
|
-
return (
|
|
102
|
-
<>
|
|
103
|
-
<AutocompleteInput
|
|
104
|
-
options={options}
|
|
105
|
-
selected={value ?? ''}
|
|
106
|
-
onSelect={newValue => setValue(name, newValue)}
|
|
107
|
-
onChange={() => requiredValidate()}
|
|
108
|
-
name={name}
|
|
109
|
-
placeholder={placeholder}
|
|
110
|
-
validationStatus={fieldValidated}
|
|
111
|
-
validationMsg={errMsg}
|
|
112
|
-
fieldId={fieldId}
|
|
113
|
-
/>
|
|
114
|
-
</>
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
return (
|
|
118
|
-
<>
|
|
119
|
-
{name === 'password' && disabled && setIsPasswordDisabled ? (
|
|
120
|
-
<Grid hasGutter={false}>
|
|
121
|
-
<GridItem span={11}>
|
|
122
|
-
<TextInput
|
|
123
|
-
name={name}
|
|
124
|
-
value={value ?? ''}
|
|
125
|
-
id={fieldId ?? `id-${name}`}
|
|
126
|
-
onChange={localHandler}
|
|
127
|
-
isDisabled={disabled}
|
|
128
|
-
isRequired={required}
|
|
129
|
-
type={type}
|
|
130
|
-
validated={fieldValidated}
|
|
131
|
-
placeholder={placeholder}
|
|
132
|
-
onBlur={requiredValidate}
|
|
133
|
-
autoComplete="off"
|
|
134
|
-
/>
|
|
135
|
-
</GridItem>
|
|
136
|
-
<GridItem span={1}>
|
|
137
|
-
<Button
|
|
138
|
-
ouiaId={`reset-${name}`}
|
|
139
|
-
onClick={() => setIsPasswordDisabled(!disabled)}
|
|
140
|
-
variant="control"
|
|
141
|
-
icon={<PencilAltIcon />}
|
|
142
|
-
/>
|
|
143
|
-
</GridItem>
|
|
144
|
-
</Grid>
|
|
145
|
-
) : (
|
|
146
|
-
<TextInput
|
|
147
|
-
name={name}
|
|
148
|
-
value={value ?? ''}
|
|
149
|
-
id={fieldId ?? `id-${name}`}
|
|
150
|
-
onChange={localHandler}
|
|
151
|
-
isRequired={required}
|
|
152
|
-
type={type}
|
|
153
|
-
validated={fieldValidated}
|
|
154
|
-
onBlur={requiredValidate}
|
|
155
|
-
autoComplete={type === 'password' ? 'new-password' : null}
|
|
156
|
-
/>
|
|
157
|
-
)}
|
|
158
|
-
|
|
159
|
-
<ValidationComponent localValidated={fieldValidated} errMsg={errMsg} />
|
|
160
|
-
</>
|
|
161
|
-
);
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
const ValidationComponent = ({ localValidated, errMsg }) => (
|
|
165
|
-
<>
|
|
166
|
-
{localValidated === 'error' && (
|
|
167
|
-
<FormHelperText>
|
|
168
|
-
<HelperText>
|
|
169
|
-
<HelperTextItem
|
|
170
|
-
icon={
|
|
171
|
-
<Icon>
|
|
172
|
-
<ExclamationCircleIcon />
|
|
173
|
-
</Icon>
|
|
174
|
-
}
|
|
175
|
-
variant={localValidated}
|
|
176
|
-
>
|
|
177
|
-
{errMsg ?? __('Field is required')}
|
|
178
|
-
</HelperTextItem>
|
|
179
|
-
</HelperText>
|
|
180
|
-
</FormHelperText>
|
|
181
|
-
)}
|
|
182
|
-
</>
|
|
183
|
-
);
|
|
184
|
-
|
|
185
|
-
const FieldConstructor = ({
|
|
186
|
-
label,
|
|
187
|
-
value,
|
|
188
|
-
required,
|
|
189
|
-
labelHelp,
|
|
190
|
-
fieldId,
|
|
191
|
-
name,
|
|
192
|
-
...props
|
|
193
|
-
}) => (
|
|
194
|
-
<FormGroup
|
|
195
|
-
isInline
|
|
196
|
-
fieldId={fieldId ?? `id-${name}`}
|
|
197
|
-
label={label}
|
|
198
|
-
isRequired={required}
|
|
199
|
-
labelIcon={
|
|
200
|
-
labelHelp ? (
|
|
201
|
-
<Popover
|
|
202
|
-
bodyContent={
|
|
203
|
-
typeof labelHelp === 'string' ? (
|
|
204
|
-
<div dangerouslySetInnerHTML={{ __html: labelHelp }} />
|
|
205
|
-
) : (
|
|
206
|
-
labelHelp
|
|
207
|
-
)
|
|
208
|
-
}
|
|
209
|
-
>
|
|
210
|
-
<Button
|
|
211
|
-
ouiaId={`label-${label}`}
|
|
212
|
-
type="button"
|
|
213
|
-
variant="plain"
|
|
214
|
-
onClick={e => e.preventDefault()}
|
|
215
|
-
>
|
|
216
|
-
<Icon>
|
|
217
|
-
<HelpIcon />
|
|
218
|
-
</Icon>
|
|
219
|
-
</Button>
|
|
220
|
-
</Popover>
|
|
221
|
-
) : (
|
|
222
|
-
''
|
|
223
|
-
)
|
|
224
|
-
}
|
|
225
|
-
>
|
|
226
|
-
<FormField
|
|
227
|
-
value={value}
|
|
228
|
-
required={required}
|
|
229
|
-
name={name}
|
|
230
|
-
{...props}
|
|
231
|
-
fieldId={fieldId}
|
|
232
|
-
/>
|
|
233
|
-
</FormGroup>
|
|
234
|
-
);
|
|
235
|
-
|
|
236
|
-
FieldConstructor.propTypes = {
|
|
237
|
-
label: PropTypes.string.isRequired,
|
|
238
|
-
required: PropTypes.bool,
|
|
239
|
-
labelHelp: PropTypes.oneOfType([
|
|
240
|
-
PropTypes.string,
|
|
241
|
-
PropTypes.object,
|
|
242
|
-
PropTypes.node,
|
|
243
|
-
]),
|
|
244
|
-
setValue: PropTypes.func.isRequired,
|
|
245
|
-
name: PropTypes.string.isRequired,
|
|
246
|
-
disabled: PropTypes.bool,
|
|
247
|
-
value: PropTypes.oneOfType([
|
|
248
|
-
PropTypes.string,
|
|
249
|
-
PropTypes.object,
|
|
250
|
-
PropTypes.bool,
|
|
251
|
-
PropTypes.number,
|
|
252
|
-
]),
|
|
253
|
-
fieldId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
FieldConstructor.defaultProps = {
|
|
257
|
-
labelHelp: undefined,
|
|
258
|
-
required: false,
|
|
259
|
-
disabled: false,
|
|
260
|
-
value: '',
|
|
261
|
-
fieldId: undefined,
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
FormField.propTypes = {
|
|
265
|
-
disabled: PropTypes.bool,
|
|
266
|
-
setValue: PropTypes.func.isRequired,
|
|
267
|
-
name: PropTypes.string.isRequired,
|
|
268
|
-
type: PropTypes.string.isRequired,
|
|
269
|
-
label: PropTypes.string,
|
|
270
|
-
required: PropTypes.bool,
|
|
271
|
-
allowClear: PropTypes.bool,
|
|
272
|
-
options: PropTypes.arrayOf(
|
|
273
|
-
PropTypes.shape({
|
|
274
|
-
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
|
|
275
|
-
.isRequired,
|
|
276
|
-
label: PropTypes.string.isRequired,
|
|
277
|
-
})
|
|
278
|
-
),
|
|
279
|
-
validated: PropTypes.string,
|
|
280
|
-
placeholder: PropTypes.string,
|
|
281
|
-
errMsg: PropTypes.string,
|
|
282
|
-
value: PropTypes.oneOfType([
|
|
283
|
-
PropTypes.bool,
|
|
284
|
-
PropTypes.string,
|
|
285
|
-
PropTypes.number,
|
|
286
|
-
]),
|
|
287
|
-
fieldId: PropTypes.string,
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
FormField.defaultProps = {
|
|
291
|
-
label: '',
|
|
292
|
-
errMsg: null,
|
|
293
|
-
placeholder: '',
|
|
294
|
-
validated: 'default',
|
|
295
|
-
required: false,
|
|
296
|
-
allowClear: false,
|
|
297
|
-
options: [],
|
|
298
|
-
disabled: false,
|
|
299
|
-
value: '',
|
|
300
|
-
fieldId: undefined,
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
ValidationComponent.propTypes = {
|
|
304
|
-
localValidated: PropTypes.string.isRequired,
|
|
305
|
-
errMsg: PropTypes.string,
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
ValidationComponent.defaultProps = {
|
|
309
|
-
errMsg: null,
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
export default FieldConstructor;
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
-
import userEvent from '@testing-library/user-event';
|
|
4
|
-
import '@testing-library/jest-dom';
|
|
5
|
-
import FieldConstructor from '../FieldConstructor';
|
|
6
|
-
|
|
7
|
-
const defaultProps = {
|
|
8
|
-
name: 'test-field',
|
|
9
|
-
setValue: jest.fn(),
|
|
10
|
-
label: 'Test Field',
|
|
11
|
-
value: '',
|
|
12
|
-
type: 'text',
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
describe('FieldConstructor RTL Tests', () => {
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
jest.clearAllMocks();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
describe('Text Input Fields', () => {
|
|
21
|
-
test('renders text input field', () => {
|
|
22
|
-
render(<FieldConstructor {...defaultProps} type="text" />);
|
|
23
|
-
|
|
24
|
-
expect(screen.getByText('Test Field')).toBeInTheDocument();
|
|
25
|
-
expect(document.getElementById('id-test-field')).toHaveAttribute(
|
|
26
|
-
'type',
|
|
27
|
-
'text'
|
|
28
|
-
);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('renders password input field', () => {
|
|
32
|
-
render(<FieldConstructor {...defaultProps} type="password" />);
|
|
33
|
-
|
|
34
|
-
expect(screen.getByText('Test Field')).toBeInTheDocument();
|
|
35
|
-
expect(document.getElementById('id-test-field')).toHaveAttribute(
|
|
36
|
-
'type',
|
|
37
|
-
'password'
|
|
38
|
-
);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('calls setValue when text input changes', () => {
|
|
42
|
-
render(<FieldConstructor {...defaultProps} type="text" />);
|
|
43
|
-
|
|
44
|
-
const input = document.getElementById('id-test-field');
|
|
45
|
-
fireEvent.change(input, { target: { value: 'test value' } });
|
|
46
|
-
|
|
47
|
-
expect(defaultProps.setValue).toHaveBeenCalledWith(
|
|
48
|
-
'test-field',
|
|
49
|
-
'test value'
|
|
50
|
-
);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('renders with initial value', () => {
|
|
54
|
-
render(
|
|
55
|
-
<FieldConstructor {...defaultProps} type="text" value="initial value" />
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
expect(document.getElementById('id-test-field')).toHaveValue(
|
|
59
|
-
'initial value'
|
|
60
|
-
);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('renders as enabled when loading', () => {
|
|
64
|
-
render(<FieldConstructor {...defaultProps} type="text" isLoading />);
|
|
65
|
-
|
|
66
|
-
expect(document.getElementById('id-test-field')).toBeEnabled();
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
describe('Textarea Fields', () => {
|
|
71
|
-
test('renders textarea field', () => {
|
|
72
|
-
render(<FieldConstructor {...defaultProps} type="textarea" />);
|
|
73
|
-
|
|
74
|
-
expect(screen.getByText('Test Field')).toBeInTheDocument();
|
|
75
|
-
expect(document.getElementById('id-test-field').tagName).toBe('TEXTAREA');
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test('calls setValue when textarea changes', () => {
|
|
79
|
-
render(<FieldConstructor {...defaultProps} type="textarea" />);
|
|
80
|
-
|
|
81
|
-
const textarea = document.getElementById('id-test-field');
|
|
82
|
-
fireEvent.change(textarea, { target: { value: 'textarea content' } });
|
|
83
|
-
|
|
84
|
-
expect(defaultProps.setValue).toHaveBeenCalledWith(
|
|
85
|
-
'test-field',
|
|
86
|
-
'textarea content'
|
|
87
|
-
);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test('renders with specified rows', () => {
|
|
91
|
-
render(<FieldConstructor {...defaultProps} type="textarea" rows={5} />);
|
|
92
|
-
|
|
93
|
-
expect(document.getElementsByTagName('textarea')).toHaveLength(1);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe('Checkbox Fields', () => {
|
|
98
|
-
test('renders checkbox field', () => {
|
|
99
|
-
render(<FieldConstructor {...defaultProps} type="checkbox" />);
|
|
100
|
-
|
|
101
|
-
expect(screen.getByText('Test Field')).toBeInTheDocument();
|
|
102
|
-
expect(document.getElementById('id-test-field')).toHaveAttribute(
|
|
103
|
-
'type',
|
|
104
|
-
'checkbox'
|
|
105
|
-
);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test('renders unchecked checkbox', () => {
|
|
109
|
-
render(
|
|
110
|
-
<FieldConstructor {...defaultProps} type="checkbox" value={false} />
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
expect(document.getElementById('id-test-field')).not.toBeChecked();
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
describe('Autocomplete render test', () => {
|
|
118
|
-
test('renders autocomplete', () => {
|
|
119
|
-
const props = {
|
|
120
|
-
...defaultProps,
|
|
121
|
-
onChange: defaultProps.setValue,
|
|
122
|
-
options: [
|
|
123
|
-
{ value: 'host_created.event.foreman', label: 'Host Created' },
|
|
124
|
-
{ value: 'host_updated.event.foreman', label: 'Host Updated' },
|
|
125
|
-
],
|
|
126
|
-
};
|
|
127
|
-
render(<FieldConstructor {...props} type="select" />);
|
|
128
|
-
|
|
129
|
-
expect(screen.getByRole('combobox')).toBeInTheDocument();
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
describe('Label Help', () => {
|
|
134
|
-
test('renders help icon when labelHelp is provided', () => {
|
|
135
|
-
render(
|
|
136
|
-
<FieldConstructor {...defaultProps} labelHelp="This is help text" />
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
expect(screen.getByRole('button')).toBeInTheDocument();
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test('does not render help icon when labelHelp is not provided', () => {
|
|
143
|
-
render(<FieldConstructor {...defaultProps} />);
|
|
144
|
-
|
|
145
|
-
expect(screen.queryByRole('button')).not.toBeInTheDocument();
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
test('renders help icon with JSX content', async () => {
|
|
149
|
-
const helpContent = <div>JSX help content</div>;
|
|
150
|
-
render(<FieldConstructor {...defaultProps} labelHelp={helpContent} />);
|
|
151
|
-
|
|
152
|
-
const button = screen.getByRole('button');
|
|
153
|
-
expect(button).toBeInTheDocument();
|
|
154
|
-
|
|
155
|
-
userEvent.click(button);
|
|
156
|
-
|
|
157
|
-
expect(await screen.findByText('JSX help content')).toBeInTheDocument();
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
describe('Validation', () => {
|
|
162
|
-
test('renders error message when validated is error', async () => {
|
|
163
|
-
render(
|
|
164
|
-
<>
|
|
165
|
-
<FieldConstructor {...defaultProps} required type="text" />
|
|
166
|
-
<button>Dummy</button>
|
|
167
|
-
</>
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
const input = document.getElementById('id-test-field');
|
|
171
|
-
await userEvent.click(input);
|
|
172
|
-
expect(input).toHaveFocus();
|
|
173
|
-
|
|
174
|
-
await userEvent.tab();
|
|
175
|
-
expect(input).not.toHaveFocus();
|
|
176
|
-
|
|
177
|
-
expect(screen.getByText('Field is required')).toBeInTheDocument();
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
test('does not render error message when validated is not error', () => {
|
|
181
|
-
render(
|
|
182
|
-
<FieldConstructor {...defaultProps} type="text" validated="success" />
|
|
183
|
-
);
|
|
184
|
-
|
|
185
|
-
expect(screen.queryByText('Field is required')).not.toBeInTheDocument();
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
describe('Edge Cases', () => {
|
|
190
|
-
test('handles undefined value', () => {
|
|
191
|
-
render(
|
|
192
|
-
<FieldConstructor {...defaultProps} type="text" value={undefined} />
|
|
193
|
-
);
|
|
194
|
-
|
|
195
|
-
expect(document.getElementById('id-test-field')).toHaveValue('');
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
test('handles null value', () => {
|
|
199
|
-
render(<FieldConstructor {...defaultProps} type="text" value={null} />);
|
|
200
|
-
|
|
201
|
-
expect(document.getElementById('id-test-field')).toHaveValue('');
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
test('handles numeric value', () => {
|
|
205
|
-
render(<FieldConstructor {...defaultProps} type="text" value={123} />);
|
|
206
|
-
|
|
207
|
-
expect(document.getElementById('id-test-field')).toHaveValue('123');
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
test('handles boolean value for checkbox', () => {
|
|
211
|
-
render(<FieldConstructor {...defaultProps} type="checkbox" value />);
|
|
212
|
-
|
|
213
|
-
expect(document.getElementById('id-test-field')).toBeChecked();
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { translate as __ } from 'foremanReact/common/I18n';
|
|
4
|
-
import DefaultEmptyState from 'foremanReact/components/common/EmptyState';
|
|
5
|
-
|
|
6
|
-
const EmptyWebhooksTable = ({ message: { type, text } }) => (
|
|
7
|
-
<DefaultEmptyState
|
|
8
|
-
icon={type === 'error' ? 'error-circle-o' : 'add-circle-o'}
|
|
9
|
-
header={type === 'error' ? __('Error') : __('No Results')}
|
|
10
|
-
description={text}
|
|
11
|
-
documentation={null}
|
|
12
|
-
/>
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
EmptyWebhooksTable.propTypes = {
|
|
16
|
-
message: PropTypes.shape({
|
|
17
|
-
type: PropTypes.oneOf(['empty', 'error']),
|
|
18
|
-
text: PropTypes.string,
|
|
19
|
-
}),
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
EmptyWebhooksTable.defaultProps = {
|
|
23
|
-
message: {
|
|
24
|
-
type: 'empty',
|
|
25
|
-
text: __('Try to create a new webhook'),
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export default EmptyWebhooksTable;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { cellFormatter } from 'foremanReact/components/common/table';
|
|
3
|
-
import { ActionButton } from '../ActionButtons/ActionButton';
|
|
4
|
-
|
|
5
|
-
const actionCellFormatter = webhookActions => (
|
|
6
|
-
_,
|
|
7
|
-
{ rowData: { id, name, canEdit, canDelete } }
|
|
8
|
-
) =>
|
|
9
|
-
cellFormatter(
|
|
10
|
-
canEdit && (
|
|
11
|
-
<ActionButton
|
|
12
|
-
canDelete={canDelete}
|
|
13
|
-
id={id}
|
|
14
|
-
name={name}
|
|
15
|
-
webhookActions={webhookActions}
|
|
16
|
-
/>
|
|
17
|
-
)
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
export default actionCellFormatter;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import NameToEditCell from '../NameToEditCell';
|
|
3
|
-
|
|
4
|
-
const nameToEditFormatter = (controllerPluralize, onClick) => (
|
|
5
|
-
value,
|
|
6
|
-
{ rowData: { canEdit, id, name } }
|
|
7
|
-
) => (
|
|
8
|
-
<NameToEditCell
|
|
9
|
-
active={canEdit}
|
|
10
|
-
id={id}
|
|
11
|
-
name={encodeURI(name)}
|
|
12
|
-
controller={controllerPluralize}
|
|
13
|
-
onClick={onClick}
|
|
14
|
-
>
|
|
15
|
-
{value}
|
|
16
|
-
</NameToEditCell>
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
export default nameToEditFormatter;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { Button } from '@patternfly/react-core';
|
|
4
|
-
|
|
5
|
-
const NameToEditCell = ({ active, id, name, controller, onClick, children }) =>
|
|
6
|
-
active ? (
|
|
7
|
-
<Button
|
|
8
|
-
ouiaId="name-edit-active-button"
|
|
9
|
-
variant="link"
|
|
10
|
-
isInline
|
|
11
|
-
component="span"
|
|
12
|
-
onClick={() => onClick(id)}
|
|
13
|
-
>
|
|
14
|
-
{children}
|
|
15
|
-
</Button>
|
|
16
|
-
) : (
|
|
17
|
-
<Button
|
|
18
|
-
ouiaId="name-edit-disabled-button"
|
|
19
|
-
variant="link"
|
|
20
|
-
isInline
|
|
21
|
-
isDisabled
|
|
22
|
-
component="span"
|
|
23
|
-
>
|
|
24
|
-
{children}
|
|
25
|
-
</Button>
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
NameToEditCell.propTypes = {
|
|
29
|
-
active: PropTypes.bool,
|
|
30
|
-
id: PropTypes.number.isRequired,
|
|
31
|
-
name: PropTypes.string.isRequired,
|
|
32
|
-
controller: PropTypes.string.isRequired,
|
|
33
|
-
onClick: PropTypes.func.isRequired,
|
|
34
|
-
children: PropTypes.node,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
NameToEditCell.defaultProps = {
|
|
38
|
-
active: false,
|
|
39
|
-
children: null,
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export default NameToEditCell;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
|
|
2
|
-
import EnabledCell from '../EnabledCell';
|
|
3
|
-
|
|
4
|
-
const fixtures = {
|
|
5
|
-
'should render blank cell': {
|
|
6
|
-
condition: false,
|
|
7
|
-
},
|
|
8
|
-
'should render marked cell': {
|
|
9
|
-
condition: true,
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
describe('EnabledCell', () =>
|
|
14
|
-
testComponentSnapshotsWithFixtures(EnabledCell, fixtures));
|