foreman_templates 7.0.1 → 7.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.babelrc +16 -0
- data/lib/foreman_templates/version.rb +1 -1
- data/package.json +68 -0
- data/webpack/ForemanTemplates.js +29 -0
- data/webpack/Routes.js +33 -0
- data/webpack/__mocks__/foremanReact/common/helpers.js +27 -0
- data/webpack/__mocks__/foremanReact/components/Pagination/PaginationWrapper.js +2 -0
- data/webpack/__mocks__/foremanReact/components/common/forms/CommonForm.js +2 -0
- data/webpack/__mocks__/foremanReact/components/common/forms/Form.js +2 -0
- data/webpack/__mocks__/foremanReact/components/common/forms/TextField.js +2 -0
- data/webpack/__mocks__/foremanReact/redux/actions/common/forms.js +1 -0
- data/webpack/__mocks__/foremanReact/routes/common/PageLayout/PageLayout.js +2 -0
- data/webpack/__tests__/__snapshots__/helpers.test.js.snap +5 -0
- data/webpack/__tests__/helpers.test.js +17 -0
- data/webpack/components/NewTemplateSync/NewTemplateSync.js +60 -0
- data/webpack/components/NewTemplateSync/NewTemplateSync.scss +19 -0
- data/webpack/components/NewTemplateSync/NewTemplateSyncActions.js +39 -0
- data/webpack/components/NewTemplateSync/NewTemplateSyncReducer.js +34 -0
- data/webpack/components/NewTemplateSync/NewTemplateSyncSelectors.js +7 -0
- data/webpack/components/NewTemplateSync/__fixtures__/templateSyncSettings.fixtures.js +71 -0
- data/webpack/components/NewTemplateSync/__tests__/NewTemplateSync.test.js +31 -0
- data/webpack/components/NewTemplateSync/__tests__/NewTemplateSyncReducer.test.js +55 -0
- data/webpack/components/NewTemplateSync/__tests__/NewTemplateSyncSelectors.test.js +28 -0
- data/webpack/components/NewTemplateSync/__tests__/__snapshots__/NewTemplateSync.test.js.snap +53 -0
- data/webpack/components/NewTemplateSync/__tests__/__snapshots__/NewTemplateSyncReducer.test.js.snap +74 -0
- data/webpack/components/NewTemplateSync/__tests__/__snapshots__/NewTemplateSyncSelectors.test.js.snap +59 -0
- data/webpack/components/NewTemplateSync/components/ButtonTooltip.js +23 -0
- data/webpack/components/NewTemplateSync/components/NewTemplateSyncForm/NewTemplateSyncForm.js +145 -0
- data/webpack/components/NewTemplateSync/components/NewTemplateSyncForm/NewTemplateSyncFormConstants.js +1 -0
- data/webpack/components/NewTemplateSync/components/NewTemplateSyncForm/NewTemplateSyncFormSelectors.js +24 -0
- data/webpack/components/NewTemplateSync/components/NewTemplateSyncForm/__tests__/NewTemplateSyncForm.test.js +42 -0
- data/webpack/components/NewTemplateSync/components/NewTemplateSyncForm/__tests__/NewTemplateSyncFormSelectors.test.js +37 -0
- data/webpack/components/NewTemplateSync/components/NewTemplateSyncForm/__tests__/__snapshots__/NewTemplateSyncForm.test.js.snap +176 -0
- data/webpack/components/NewTemplateSync/components/NewTemplateSyncForm/__tests__/__snapshots__/NewTemplateSyncFormSelectors.test.js.snap +42 -0
- data/webpack/components/NewTemplateSync/components/NewTemplateSyncForm/index.js +44 -0
- data/webpack/components/NewTemplateSync/components/SyncSettingField.js +54 -0
- data/webpack/components/NewTemplateSync/components/SyncSettingFields.js +69 -0
- data/webpack/components/NewTemplateSync/components/SyncTypeRadios.js +52 -0
- data/webpack/components/NewTemplateSync/components/TextButtonField/BlankOption.js +19 -0
- data/webpack/components/NewTemplateSync/components/TextButtonField/CheckboxField.js +15 -0
- data/webpack/components/NewTemplateSync/components/TextButtonField/FieldType.js +46 -0
- data/webpack/components/NewTemplateSync/components/TextButtonField/InputField.js +14 -0
- data/webpack/components/NewTemplateSync/components/TextButtonField/RenderField.js +74 -0
- data/webpack/components/NewTemplateSync/components/TextButtonField/SelectField.js +24 -0
- data/webpack/components/NewTemplateSync/components/TextButtonField/index.js +69 -0
- data/webpack/components/NewTemplateSync/components/__tests__/SyncSettingField.test.js +34 -0
- data/webpack/components/NewTemplateSync/components/__tests__/SyncSettingFields.test.js +33 -0
- data/webpack/components/NewTemplateSync/components/__tests__/SyncTypeRadios.test.js +20 -0
- data/webpack/components/NewTemplateSync/components/__tests__/TextButtonField.test.js +65 -0
- data/webpack/components/NewTemplateSync/components/__tests__/__snapshots__/SyncSettingField.test.js.snap +131 -0
- data/webpack/components/NewTemplateSync/components/__tests__/__snapshots__/SyncSettingFields.test.js.snap +94 -0
- data/webpack/components/NewTemplateSync/components/__tests__/__snapshots__/SyncTypeRadios.test.js.snap +46 -0
- data/webpack/components/NewTemplateSync/components/__tests__/__snapshots__/TextButtonField.test.js.snap +112 -0
- data/webpack/components/NewTemplateSync/index.js +32 -0
- data/webpack/components/PageNotFound.js +13 -0
- data/webpack/components/PermissionDenied.js +33 -0
- data/webpack/components/TemplateSyncResult/TemplateSyncResult.js +61 -0
- data/webpack/components/TemplateSyncResult/TemplateSyncResult.scss +39 -0
- data/webpack/components/TemplateSyncResult/TemplateSyncResultActions.js +4 -0
- data/webpack/components/TemplateSyncResult/TemplateSyncResultHelpers.js +6 -0
- data/webpack/components/TemplateSyncResult/TemplateSyncResultReducer.js +33 -0
- data/webpack/components/TemplateSyncResult/TemplateSyncResultSelectors.js +1 -0
- data/webpack/components/TemplateSyncResult/__fixtures__/templateSyncResult.fixtures.js +86 -0
- data/webpack/components/TemplateSyncResult/__tests__/TemplateSyncResult.test.js +37 -0
- data/webpack/components/TemplateSyncResult/__tests__/TemplateSyncResultReducer.test.js +48 -0
- data/webpack/components/TemplateSyncResult/__tests__/__snapshots__/TemplateSyncResult.test.js.snap +112 -0
- data/webpack/components/TemplateSyncResult/__tests__/__snapshots__/TemplateSyncResultReducer.test.js.snap +88 -0
- data/webpack/components/TemplateSyncResult/components/EmptySyncResult.js +25 -0
- data/webpack/components/TemplateSyncResult/components/FinishedSyncResult.js +77 -0
- data/webpack/components/TemplateSyncResult/components/ListViewHeader.js +38 -0
- data/webpack/components/TemplateSyncResult/components/SyncResultList.js +41 -0
- data/webpack/components/TemplateSyncResult/components/SyncedTemplate/EmptyInfoItem.js +16 -0
- data/webpack/components/TemplateSyncResult/components/SyncedTemplate/IconInfoItem.js +21 -0
- data/webpack/components/TemplateSyncResult/components/SyncedTemplate/InfoItem.js +34 -0
- data/webpack/components/TemplateSyncResult/components/SyncedTemplate/LinkInfoItem.js +37 -0
- data/webpack/components/TemplateSyncResult/components/SyncedTemplate/StringInfoItem.js +50 -0
- data/webpack/components/TemplateSyncResult/components/SyncedTemplate/helpers.js +128 -0
- data/webpack/components/TemplateSyncResult/components/SyncedTemplate/index.js +33 -0
- data/webpack/components/TemplateSyncResult/components/__tests__/SyncResultList.test.js +27 -0
- data/webpack/components/TemplateSyncResult/components/__tests__/SyncedTemplate.test.js +30 -0
- data/webpack/components/TemplateSyncResult/components/__tests__/__snapshots__/SyncResultList.test.js.snap +102 -0
- data/webpack/components/TemplateSyncResult/components/__tests__/__snapshots__/SyncedTemplate.test.js.snap +548 -0
- data/webpack/components/TemplateSyncResult/index.js +13 -0
- data/webpack/consts.js +6 -0
- data/webpack/index.js +11 -0
- data/webpack/reducer.js +6 -0
- data/webpack/testSetup.js +11 -0
- data/webpack/withProtectedView.js +16 -0
- metadata +89 -2
data/webpack/components/NewTemplateSync/__tests__/__snapshots__/NewTemplateSyncReducer.test.js.snap
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
|
+
|
3
|
+
exports[`NewTemplateSyncReducer should return initial state 1`] = `
|
4
|
+
Object {
|
5
|
+
"error": "",
|
6
|
+
"exportSettings": Array [],
|
7
|
+
"importSettings": Array [],
|
8
|
+
"loadingSettings": false,
|
9
|
+
}
|
10
|
+
`;
|
11
|
+
|
12
|
+
exports[`NewTemplateSyncReducer should start loading on setting values request 1`] = `
|
13
|
+
Object {
|
14
|
+
"error": "",
|
15
|
+
"exportSettings": Array [],
|
16
|
+
"importSettings": Array [],
|
17
|
+
"loadingSettings": true,
|
18
|
+
}
|
19
|
+
`;
|
20
|
+
|
21
|
+
exports[`NewTemplateSyncReducer should stop loading on setting values success 1`] = `
|
22
|
+
Object {
|
23
|
+
"error": "",
|
24
|
+
"exportSettings": Array [
|
25
|
+
Object {
|
26
|
+
"id": 47,
|
27
|
+
"name": "filter",
|
28
|
+
"settingsType": "string",
|
29
|
+
"value": "",
|
30
|
+
},
|
31
|
+
Object {
|
32
|
+
"id": 48,
|
33
|
+
"name": "negate",
|
34
|
+
"settingsType": "bool",
|
35
|
+
"value": false,
|
36
|
+
},
|
37
|
+
Object {
|
38
|
+
"id": 49,
|
39
|
+
"name": "repo",
|
40
|
+
"settingsType": "string",
|
41
|
+
"value": "https://github.com/theforeman/community-templates.git",
|
42
|
+
},
|
43
|
+
],
|
44
|
+
"importSettings": Array [
|
45
|
+
Object {
|
46
|
+
"id": 45,
|
47
|
+
"name": "associate",
|
48
|
+
"selection": Array [
|
49
|
+
Object {
|
50
|
+
"label": "New",
|
51
|
+
"value": "new",
|
52
|
+
},
|
53
|
+
Object {
|
54
|
+
"label": "Never",
|
55
|
+
"value": "never",
|
56
|
+
},
|
57
|
+
Object {
|
58
|
+
"label": "Always",
|
59
|
+
"value": "always",
|
60
|
+
},
|
61
|
+
],
|
62
|
+
"settingsType": "string",
|
63
|
+
"value": "new",
|
64
|
+
},
|
65
|
+
Object {
|
66
|
+
"id": 46,
|
67
|
+
"name": "force",
|
68
|
+
"settingsType": "bool",
|
69
|
+
"value": false,
|
70
|
+
},
|
71
|
+
],
|
72
|
+
"loadingSettings": false,
|
73
|
+
}
|
74
|
+
`;
|
@@ -0,0 +1,59 @@
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
|
+
|
3
|
+
exports[`NewTemplateSyncSelectors should return export settings 1`] = `
|
4
|
+
Array [
|
5
|
+
Object {
|
6
|
+
"id": 47,
|
7
|
+
"name": "filter",
|
8
|
+
"settingsType": "string",
|
9
|
+
"value": "",
|
10
|
+
},
|
11
|
+
Object {
|
12
|
+
"id": 48,
|
13
|
+
"name": "negate",
|
14
|
+
"settingsType": "bool",
|
15
|
+
"value": false,
|
16
|
+
},
|
17
|
+
Object {
|
18
|
+
"id": 49,
|
19
|
+
"name": "repo",
|
20
|
+
"settingsType": "string",
|
21
|
+
"value": "https://github.com/theforeman/community-templates.git",
|
22
|
+
},
|
23
|
+
]
|
24
|
+
`;
|
25
|
+
|
26
|
+
exports[`NewTemplateSyncSelectors should return import settings 1`] = `
|
27
|
+
Array [
|
28
|
+
Object {
|
29
|
+
"id": 45,
|
30
|
+
"name": "associate",
|
31
|
+
"selection": Array [
|
32
|
+
Object {
|
33
|
+
"label": "New",
|
34
|
+
"value": "new",
|
35
|
+
},
|
36
|
+
Object {
|
37
|
+
"label": "Never",
|
38
|
+
"value": "never",
|
39
|
+
},
|
40
|
+
Object {
|
41
|
+
"label": "Always",
|
42
|
+
"value": "always",
|
43
|
+
},
|
44
|
+
],
|
45
|
+
"settingsType": "string",
|
46
|
+
"value": "new",
|
47
|
+
},
|
48
|
+
Object {
|
49
|
+
"id": 46,
|
50
|
+
"name": "force",
|
51
|
+
"settingsType": "bool",
|
52
|
+
"value": false,
|
53
|
+
},
|
54
|
+
]
|
55
|
+
`;
|
56
|
+
|
57
|
+
exports[`NewTemplateSyncSelectors should return loading error 1`] = `"Error"`;
|
58
|
+
|
59
|
+
exports[`NewTemplateSyncSelectors should return loading settings 1`] = `true`;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { Tooltip, Icon, OverlayTrigger } from 'patternfly-react';
|
3
|
+
import PropTypes from 'prop-types';
|
4
|
+
|
5
|
+
const ButtonTooltip = props => {
|
6
|
+
const tooltip = (
|
7
|
+
<Tooltip id={`${props.tooltipId}-tooltip-id`}>
|
8
|
+
<span>Use default value from settings</span>
|
9
|
+
</Tooltip>
|
10
|
+
);
|
11
|
+
|
12
|
+
return (
|
13
|
+
<OverlayTrigger overlay={tooltip} trigger={['hover', 'focus']}>
|
14
|
+
<Icon type="fa" name="refresh" />
|
15
|
+
</OverlayTrigger>
|
16
|
+
);
|
17
|
+
};
|
18
|
+
|
19
|
+
ButtonTooltip.propTypes = {
|
20
|
+
tooltipId: PropTypes.string.isRequired,
|
21
|
+
};
|
22
|
+
|
23
|
+
export default ButtonTooltip;
|
@@ -0,0 +1,145 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { change } from 'redux-form';
|
3
|
+
import PropTypes from 'prop-types';
|
4
|
+
|
5
|
+
import Form from 'foremanReact/components/common/forms/Form';
|
6
|
+
|
7
|
+
import SyncSettingsFields from '../SyncSettingFields';
|
8
|
+
import SyncTypeRadios from '../SyncTypeRadios';
|
9
|
+
import { NEW_TEMPLATE_SYNC_FORM_NAME } from './NewTemplateSyncFormConstants';
|
10
|
+
|
11
|
+
const submit = syncType => (formValues, dispatch, props) => {
|
12
|
+
const { submitForm, importUrl, exportUrl, history, currentFields } = props;
|
13
|
+
const url = syncType === 'import' ? importUrl : exportUrl;
|
14
|
+
const currentFieldNames = Object.keys(currentFields);
|
15
|
+
const postValues = Object.keys(formValues).reduce((memo, key) => {
|
16
|
+
if (currentFieldNames.includes(key)) {
|
17
|
+
memo[key] = formValues[key];
|
18
|
+
}
|
19
|
+
return memo;
|
20
|
+
}, {});
|
21
|
+
|
22
|
+
return submitForm({
|
23
|
+
url,
|
24
|
+
values: postValues,
|
25
|
+
message: `Templates were ${syncType}ed.`,
|
26
|
+
item: 'TemplateSync',
|
27
|
+
}).then(args => {
|
28
|
+
history.replace({ pathname: '/template_syncs/result' });
|
29
|
+
});
|
30
|
+
};
|
31
|
+
|
32
|
+
const redirectToResult = history => () =>
|
33
|
+
history.push({ pathname: '/template_syncs/result' });
|
34
|
+
|
35
|
+
class NewTemplateSyncForm extends React.Component {
|
36
|
+
allowedSyncType = (userPermissions, radioAttrs) =>
|
37
|
+
this.props.userPermissions[radioAttrs.permission];
|
38
|
+
|
39
|
+
constructor(props) {
|
40
|
+
super(props);
|
41
|
+
|
42
|
+
this.radioButtons = [
|
43
|
+
{ label: 'Import', value: 'import', permission: 'import' },
|
44
|
+
{ label: 'Export', value: 'export', permission: 'export' },
|
45
|
+
];
|
46
|
+
|
47
|
+
this.state = {
|
48
|
+
syncType: this.radioButtons.find(radioAttrs =>
|
49
|
+
this.allowedSyncType(props.userPermissions, radioAttrs)
|
50
|
+
).value,
|
51
|
+
};
|
52
|
+
}
|
53
|
+
|
54
|
+
updateSyncType = event => {
|
55
|
+
this.setState({ syncType: event.target.value });
|
56
|
+
};
|
57
|
+
|
58
|
+
permitRadioButtons = buttons =>
|
59
|
+
buttons.filter(buttonAttrs =>
|
60
|
+
this.allowedSyncType(this.props.userPermissions, buttonAttrs)
|
61
|
+
);
|
62
|
+
|
63
|
+
initRadioButtons = syncType =>
|
64
|
+
this.permitRadioButtons(this.radioButtons).map(buttonAttrs => ({
|
65
|
+
get checked() {
|
66
|
+
return this.value === syncType;
|
67
|
+
},
|
68
|
+
onChange: this.updateSyncType,
|
69
|
+
...buttonAttrs,
|
70
|
+
}));
|
71
|
+
|
72
|
+
render() {
|
73
|
+
const {
|
74
|
+
submitting,
|
75
|
+
error,
|
76
|
+
handleSubmit,
|
77
|
+
importSettings,
|
78
|
+
exportSettings,
|
79
|
+
dispatch,
|
80
|
+
history,
|
81
|
+
validationData,
|
82
|
+
valid,
|
83
|
+
} = this.props;
|
84
|
+
|
85
|
+
const resetToDefault = ((dispatchFn, changeFn, nameOfForm) => (
|
86
|
+
fieldName,
|
87
|
+
value
|
88
|
+
) => {
|
89
|
+
dispatchFn(changeFn(nameOfForm, fieldName, value));
|
90
|
+
})(dispatch, change, NEW_TEMPLATE_SYNC_FORM_NAME);
|
91
|
+
|
92
|
+
return (
|
93
|
+
<Form
|
94
|
+
onSubmit={handleSubmit(submit(this.state.syncType))}
|
95
|
+
disabled={submitting || (!valid && !error)}
|
96
|
+
submitting={submitting}
|
97
|
+
error={error}
|
98
|
+
onCancel={redirectToResult(history)}
|
99
|
+
errorTitle={
|
100
|
+
error && error.severity === 'danger' ? __('Error! ') : __('Warning! ')
|
101
|
+
}
|
102
|
+
>
|
103
|
+
<SyncTypeRadios
|
104
|
+
name="syncType"
|
105
|
+
controlLabel="Action type"
|
106
|
+
radios={this.initRadioButtons(this.state.syncType)}
|
107
|
+
disabled={submitting}
|
108
|
+
/>
|
109
|
+
<SyncSettingsFields
|
110
|
+
importSettings={importSettings}
|
111
|
+
exportSettings={exportSettings}
|
112
|
+
syncType={this.state.syncType}
|
113
|
+
resetField={resetToDefault}
|
114
|
+
disabled={submitting}
|
115
|
+
validationData={validationData}
|
116
|
+
/>
|
117
|
+
</Form>
|
118
|
+
);
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
NewTemplateSyncForm.propTypes = {
|
123
|
+
importSettings: PropTypes.array,
|
124
|
+
exportSettings: PropTypes.array,
|
125
|
+
userPermissions: PropTypes.object.isRequired,
|
126
|
+
submitting: PropTypes.bool,
|
127
|
+
error: PropTypes.object,
|
128
|
+
handleSubmit: PropTypes.func.isRequired,
|
129
|
+
dispatch: PropTypes.func,
|
130
|
+
history: PropTypes.object,
|
131
|
+
validationData: PropTypes.object,
|
132
|
+
valid: PropTypes.bool.isRequired,
|
133
|
+
};
|
134
|
+
|
135
|
+
NewTemplateSyncForm.defaultProps = {
|
136
|
+
importSettings: [],
|
137
|
+
exportSettings: [],
|
138
|
+
validationData: {},
|
139
|
+
error: undefined,
|
140
|
+
dispatch: () => {},
|
141
|
+
submitting: false,
|
142
|
+
history: {},
|
143
|
+
};
|
144
|
+
|
145
|
+
export default NewTemplateSyncForm;
|
@@ -0,0 +1 @@
|
|
1
|
+
export const NEW_TEMPLATE_SYNC_FORM_NAME = 'newTemplateSync';
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { createSelector } from 'reselect';
|
2
|
+
|
3
|
+
import {
|
4
|
+
selectImportSettings,
|
5
|
+
selectExportSettings,
|
6
|
+
} from '../../NewTemplateSyncSelectors';
|
7
|
+
|
8
|
+
export const selectInitialFormValues = createSelector(
|
9
|
+
selectImportSettings,
|
10
|
+
selectExportSettings,
|
11
|
+
(importSettings, exportSettings) =>
|
12
|
+
importSettings
|
13
|
+
.concat(exportSettings)
|
14
|
+
.reduce(
|
15
|
+
(memo, item) => Object.assign(memo, { [item.name]: item.value }),
|
16
|
+
{}
|
17
|
+
)
|
18
|
+
);
|
19
|
+
|
20
|
+
const selectFormState = (formName, state) =>
|
21
|
+
state.form && state.form[formName] ? state.form[formName] : {};
|
22
|
+
|
23
|
+
export const selectRegisteredFields = (formName, state) =>
|
24
|
+
selectFormState(formName, state).registeredFields || {};
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
|
2
|
+
|
3
|
+
import NewTemplateSyncForm from '../NewTemplateSyncForm';
|
4
|
+
|
5
|
+
import {
|
6
|
+
importSettings,
|
7
|
+
exportSettings,
|
8
|
+
} from '../../../__fixtures__/templateSyncSettings.fixtures';
|
9
|
+
|
10
|
+
const noop = () => {};
|
11
|
+
|
12
|
+
const commonFixture = {
|
13
|
+
importUrl: '/import',
|
14
|
+
exportUrl: '/export',
|
15
|
+
validationData: {},
|
16
|
+
userPermissions: {
|
17
|
+
import: true,
|
18
|
+
export: true,
|
19
|
+
},
|
20
|
+
handleSubmit: noop,
|
21
|
+
valid: true,
|
22
|
+
importSettings,
|
23
|
+
exportSettings,
|
24
|
+
};
|
25
|
+
|
26
|
+
const fixtures = {
|
27
|
+
'should render when for import settings': {
|
28
|
+
loadingSettings: false,
|
29
|
+
...commonFixture,
|
30
|
+
},
|
31
|
+
'should render for export settings': {
|
32
|
+
loadingSettings: true,
|
33
|
+
...commonFixture,
|
34
|
+
userPermissions: {
|
35
|
+
import: false,
|
36
|
+
export: true,
|
37
|
+
},
|
38
|
+
},
|
39
|
+
};
|
40
|
+
|
41
|
+
describe('NewTemplateSyncForm', () =>
|
42
|
+
testComponentSnapshotsWithFixtures(NewTemplateSyncForm, fixtures));
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { testSelectorsSnapshotWithFixtures } from 'react-redux-test-utils';
|
2
|
+
|
3
|
+
import { NEW_TEMPLATE_SYNC_FORM_NAME } from '../NewTemplateSyncFormConstants';
|
4
|
+
import {
|
5
|
+
registeredImportSettings,
|
6
|
+
initialValues,
|
7
|
+
stateFactory,
|
8
|
+
importSettings,
|
9
|
+
exportSettings,
|
10
|
+
} from '../../../__fixtures__/templateSyncSettings.fixtures';
|
11
|
+
|
12
|
+
import {
|
13
|
+
selectInitialFormValues,
|
14
|
+
selectRegisteredFields,
|
15
|
+
} from '../NewTemplateSyncFormSelectors';
|
16
|
+
|
17
|
+
const formStateFactory = obj => ({
|
18
|
+
form: {
|
19
|
+
[NEW_TEMPLATE_SYNC_FORM_NAME]: obj,
|
20
|
+
},
|
21
|
+
});
|
22
|
+
|
23
|
+
const fixtures = {
|
24
|
+
'should return registered fields': () =>
|
25
|
+
selectRegisteredFields(
|
26
|
+
NEW_TEMPLATE_SYNC_FORM_NAME,
|
27
|
+
formStateFactory(registeredImportSettings)
|
28
|
+
),
|
29
|
+
'should return initial form values': () =>
|
30
|
+
selectInitialFormValues({
|
31
|
+
...stateFactory({ importSettings, exportSettings }),
|
32
|
+
...formStateFactory(initialValues),
|
33
|
+
}),
|
34
|
+
};
|
35
|
+
|
36
|
+
describe('NewTemplateSyncFormSelectors', () =>
|
37
|
+
testSelectorsSnapshotWithFixtures(fixtures));
|
@@ -0,0 +1,176 @@
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
|
+
|
3
|
+
exports[`NewTemplateSyncForm should render for export settings 1`] = `
|
4
|
+
<Form
|
5
|
+
disabled={false}
|
6
|
+
errorTitle="Warning! "
|
7
|
+
onCancel={[Function]}
|
8
|
+
submitting={false}
|
9
|
+
>
|
10
|
+
<SyncTypeRadios
|
11
|
+
controlLabel="Action type"
|
12
|
+
disabled={false}
|
13
|
+
name="syncType"
|
14
|
+
radios={
|
15
|
+
Array [
|
16
|
+
Object {
|
17
|
+
"checked": true,
|
18
|
+
"label": "Export",
|
19
|
+
"onChange": [Function],
|
20
|
+
"permission": "export",
|
21
|
+
"value": "export",
|
22
|
+
},
|
23
|
+
]
|
24
|
+
}
|
25
|
+
/>
|
26
|
+
<SyncSettingsFields
|
27
|
+
disabled={false}
|
28
|
+
exportSettings={
|
29
|
+
Array [
|
30
|
+
Object {
|
31
|
+
"id": 47,
|
32
|
+
"name": "filter",
|
33
|
+
"settingsType": "string",
|
34
|
+
"value": "",
|
35
|
+
},
|
36
|
+
Object {
|
37
|
+
"id": 48,
|
38
|
+
"name": "negate",
|
39
|
+
"settingsType": "bool",
|
40
|
+
"value": false,
|
41
|
+
},
|
42
|
+
Object {
|
43
|
+
"id": 49,
|
44
|
+
"name": "repo",
|
45
|
+
"settingsType": "string",
|
46
|
+
"value": "https://github.com/theforeman/community-templates.git",
|
47
|
+
},
|
48
|
+
]
|
49
|
+
}
|
50
|
+
importSettings={
|
51
|
+
Array [
|
52
|
+
Object {
|
53
|
+
"id": 45,
|
54
|
+
"name": "associate",
|
55
|
+
"selection": Array [
|
56
|
+
Object {
|
57
|
+
"label": "New",
|
58
|
+
"value": "new",
|
59
|
+
},
|
60
|
+
Object {
|
61
|
+
"label": "Never",
|
62
|
+
"value": "never",
|
63
|
+
},
|
64
|
+
Object {
|
65
|
+
"label": "Always",
|
66
|
+
"value": "always",
|
67
|
+
},
|
68
|
+
],
|
69
|
+
"settingsType": "string",
|
70
|
+
"value": "new",
|
71
|
+
},
|
72
|
+
Object {
|
73
|
+
"id": 46,
|
74
|
+
"name": "force",
|
75
|
+
"settingsType": "bool",
|
76
|
+
"value": false,
|
77
|
+
},
|
78
|
+
]
|
79
|
+
}
|
80
|
+
resetField={[Function]}
|
81
|
+
syncType="export"
|
82
|
+
validationData={Object {}}
|
83
|
+
/>
|
84
|
+
</Form>
|
85
|
+
`;
|
86
|
+
|
87
|
+
exports[`NewTemplateSyncForm should render when for import settings 1`] = `
|
88
|
+
<Form
|
89
|
+
disabled={false}
|
90
|
+
errorTitle="Warning! "
|
91
|
+
onCancel={[Function]}
|
92
|
+
submitting={false}
|
93
|
+
>
|
94
|
+
<SyncTypeRadios
|
95
|
+
controlLabel="Action type"
|
96
|
+
disabled={false}
|
97
|
+
name="syncType"
|
98
|
+
radios={
|
99
|
+
Array [
|
100
|
+
Object {
|
101
|
+
"checked": true,
|
102
|
+
"label": "Import",
|
103
|
+
"onChange": [Function],
|
104
|
+
"permission": "import",
|
105
|
+
"value": "import",
|
106
|
+
},
|
107
|
+
Object {
|
108
|
+
"checked": false,
|
109
|
+
"label": "Export",
|
110
|
+
"onChange": [Function],
|
111
|
+
"permission": "export",
|
112
|
+
"value": "export",
|
113
|
+
},
|
114
|
+
]
|
115
|
+
}
|
116
|
+
/>
|
117
|
+
<SyncSettingsFields
|
118
|
+
disabled={false}
|
119
|
+
exportSettings={
|
120
|
+
Array [
|
121
|
+
Object {
|
122
|
+
"id": 47,
|
123
|
+
"name": "filter",
|
124
|
+
"settingsType": "string",
|
125
|
+
"value": "",
|
126
|
+
},
|
127
|
+
Object {
|
128
|
+
"id": 48,
|
129
|
+
"name": "negate",
|
130
|
+
"settingsType": "bool",
|
131
|
+
"value": false,
|
132
|
+
},
|
133
|
+
Object {
|
134
|
+
"id": 49,
|
135
|
+
"name": "repo",
|
136
|
+
"settingsType": "string",
|
137
|
+
"value": "https://github.com/theforeman/community-templates.git",
|
138
|
+
},
|
139
|
+
]
|
140
|
+
}
|
141
|
+
importSettings={
|
142
|
+
Array [
|
143
|
+
Object {
|
144
|
+
"id": 45,
|
145
|
+
"name": "associate",
|
146
|
+
"selection": Array [
|
147
|
+
Object {
|
148
|
+
"label": "New",
|
149
|
+
"value": "new",
|
150
|
+
},
|
151
|
+
Object {
|
152
|
+
"label": "Never",
|
153
|
+
"value": "never",
|
154
|
+
},
|
155
|
+
Object {
|
156
|
+
"label": "Always",
|
157
|
+
"value": "always",
|
158
|
+
},
|
159
|
+
],
|
160
|
+
"settingsType": "string",
|
161
|
+
"value": "new",
|
162
|
+
},
|
163
|
+
Object {
|
164
|
+
"id": 46,
|
165
|
+
"name": "force",
|
166
|
+
"settingsType": "bool",
|
167
|
+
"value": false,
|
168
|
+
},
|
169
|
+
]
|
170
|
+
}
|
171
|
+
resetField={[Function]}
|
172
|
+
syncType="import"
|
173
|
+
validationData={Object {}}
|
174
|
+
/>
|
175
|
+
</Form>
|
176
|
+
`;
|
@@ -0,0 +1,42 @@
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
|
+
|
3
|
+
exports[`NewTemplateSyncFormSelectors should return initial form values 1`] = `
|
4
|
+
Object {
|
5
|
+
"associate": "new",
|
6
|
+
"filter": "",
|
7
|
+
"force": false,
|
8
|
+
"negate": false,
|
9
|
+
"repo": "https://github.com/theforeman/community-templates.git",
|
10
|
+
}
|
11
|
+
`;
|
12
|
+
|
13
|
+
exports[`NewTemplateSyncFormSelectors should return registered fields 1`] = `
|
14
|
+
Object {
|
15
|
+
"associate": Object {
|
16
|
+
"id": 45,
|
17
|
+
"name": "associate",
|
18
|
+
"selection": Array [
|
19
|
+
Object {
|
20
|
+
"label": "New",
|
21
|
+
"value": "new",
|
22
|
+
},
|
23
|
+
Object {
|
24
|
+
"label": "Never",
|
25
|
+
"value": "never",
|
26
|
+
},
|
27
|
+
Object {
|
28
|
+
"label": "Always",
|
29
|
+
"value": "always",
|
30
|
+
},
|
31
|
+
],
|
32
|
+
"settingsType": "string",
|
33
|
+
"value": "new",
|
34
|
+
},
|
35
|
+
"force": Object {
|
36
|
+
"id": 46,
|
37
|
+
"name": "force",
|
38
|
+
"settingsType": "bool",
|
39
|
+
"value": false,
|
40
|
+
},
|
41
|
+
}
|
42
|
+
`;
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import { connect } from 'react-redux';
|
2
|
+
import { reduxForm } from 'redux-form';
|
3
|
+
|
4
|
+
import * as FormActions from 'foremanReact/redux/actions/common/forms';
|
5
|
+
|
6
|
+
import { NEW_TEMPLATE_SYNC_FORM_NAME } from './NewTemplateSyncFormConstants';
|
7
|
+
import NewTemplateSyncForm from './NewTemplateSyncForm';
|
8
|
+
|
9
|
+
import {
|
10
|
+
selectImportSettings,
|
11
|
+
selectExportSettings,
|
12
|
+
} from '../../NewTemplateSyncSelectors';
|
13
|
+
import {
|
14
|
+
selectInitialFormValues,
|
15
|
+
selectRegisteredFields,
|
16
|
+
} from './NewTemplateSyncFormSelectors';
|
17
|
+
|
18
|
+
const mapStateToProps = (state, ownProps) => {
|
19
|
+
const importSettings = selectImportSettings(state);
|
20
|
+
|
21
|
+
const exportSettings = selectExportSettings(state);
|
22
|
+
|
23
|
+
const initialFormValues = selectInitialFormValues(state);
|
24
|
+
|
25
|
+
const currentFields = selectRegisteredFields(
|
26
|
+
NEW_TEMPLATE_SYNC_FORM_NAME,
|
27
|
+
state
|
28
|
+
);
|
29
|
+
|
30
|
+
return {
|
31
|
+
initialValues: { ...initialFormValues },
|
32
|
+
importSettings,
|
33
|
+
exportSettings,
|
34
|
+
currentFields,
|
35
|
+
};
|
36
|
+
};
|
37
|
+
|
38
|
+
const form = reduxForm({ form: NEW_TEMPLATE_SYNC_FORM_NAME })(
|
39
|
+
NewTemplateSyncForm
|
40
|
+
);
|
41
|
+
export default connect(
|
42
|
+
mapStateToProps,
|
43
|
+
FormActions
|
44
|
+
)(form);
|