Skip to content

Commit 1e077e8

Browse files
DianaKorladinovaViktorKorladinovtaban03jandadav
authored
feat: Wizard NodeJS & Micronaut enablers' configurations (#1733)
* Allows for more inputs where multiple configurations can be present. Updated input data for the Plain Java Enabler. TBD: testing. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * WizardInputs test coverage now at 100%. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Multiple configs of same category now visually divided, wizard-reducer test coverage raised to 100% Signed-off-by: ViktorKorladinov <v.korladinov@gmail.com> * Squashed bug occurring after loading already wrapped in array category content. Signed-off-by: ViktorKorladinov <v.korladinov@gmail.com> * Plain Java Enabler data configuration. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Wizard reducer refactoring. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Raised wizard reducer coverage to 100%. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Foundation for YAML generation. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * YAML now shows in its own tab. TBD: lots of bug squashing. Signed-off-by: ViktorKorladinov <v.korladinov@gmail.com> * YAML Visualizer test Signed-off-by: ViktorKorladinov <v.korladinov@gmail.com> * Wizard actions and reducer test coverage raised to 100%. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Fixed Next / Save button bug, added 'Copy' button the the YAML result tab. Signed-off-by: ViktorKorladinov <v.korladinov@gmail.com> * Test coverage for wizard files raised to 100%. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Styling of YAML code Signed-off-by: ViktorKorladinov <v.korladinov@gmail.com> * Added a missing function after merge. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Hotfix. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Fixed npm warning on yaml package Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Moved the yaml dependency to the correct package.json Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Spring Enabler category configuration Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Created a defaults file and configured spring defaults. Signed-off-by: ViktorKorladinov <v.korladinov@gmail.com> * Injecting default values operational. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Raised test coverage to 100% & added a missing category for the Spring Enabler. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Moved different components into separate sub-folders, reduced size of wizard-config.jsx by dividing the data inside into 2 files - wizard_categories.jsx and wizard_onboarding_methods.jsx. Signed-off-by: ViktorKorladinov <v.korladinov@gmail.com> * WizardNavigation component now able to group multiple categories under a single tab. Test coverage raised to 100%. Signed-off-by: ViktorKorladinov <v.korladinov@gmail.com> * Added comments to wizard-actions and all components' functions that weren't self-explanatory. Signed-off-by: ViktorKorladinov <v.korladinov@gmail.com> * Fixed several bugs after merging. TBD: improve test coverage. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Test coverage of wizard files raised to 100%. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Added comments to wizard-reducer, hopefully reduced cognitive complexity Signed-off-by: ViktorKorladinov <v.korladinov@gmail.com> * Test fixes Signed-off-by: ViktorKorladinov <v.korladinov@gmail.com> * Mechanism for handling optional fields and checking for empty compulsory fields. TBD: Fix tests. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Wizard now shows true/false options as checkboxes Signed-off-by: ViktorKorladinov <v.korladinov@gmail.com> * Boolean property fully works. TBD: mountains of testing : ) Signed-off-by: ViktorKorladinov <v.korladinov@gmail.com> * UI now alerts when a compulsory field is left empty & optional fields are marked as such Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Option property fully works. Fake events substitute the events Select fires. Signed-off-by: ViktorKorladinov <v.korladinov@gmail.com> * Improved test coverage. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Test coverage for WizardInputs raised. Signed-off-by: ViktorKorladinov <v.korladinov@gmail.com> * Redid functions for unfilled compulsory fields. TBD: fix tests Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Fixed failing tests & improved test coverage. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * maxLength and lowercase properties functional. Signed-off-by: ViktorKorladinov <v.korladinov@gmail.com> * Tab reorganization. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Hotfix. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Dependencies now functional. Signed-off-by: ViktorKorladinov <v.korladinov@gmail.com> * Tabs now indicate if they have an unfilled field & improved test coverage. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Test coverage of WizardInputs raised Signed-off-by: ViktorKorladinov <v.korladinov@gmail.com> * Added mechanism for generating warnings when deleting filled fields & improved test coverage. TBD: Add the actual warnings Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Hotfixes of unfilled validation Signed-off-by: ViktorKorladinov <v.korladinov@gmail.com> * Fixed failing tests. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Restructuring. TBD: fix tests. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Raised coverage of WizardNavigation, WizardInputs and WizardDialog to 100. Signed-off-by: ViktorKorladinov <v.korladinov@gmail.com> * Fixed wizard-reducer tests. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Fixed some code smells. Signed-off-by: ViktorKorladinov <v.korladinov@gmail.com> * Indentation dependency now available. TBD: fix tests. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Array wrapping of some YAML categories for static onboarding. TBD: fix tests. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Fixed & added tests. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Wizard dialog 'Next' button fix. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Post-merge fixes. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Node Enabler configuration. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Array indentation mechanism for Micronaut & fixed some tests. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Micronaut default values. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Raised test coverage of wizard-reducer and wizard-actions to 100%. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Divided category configurations into separate files to improve readability Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Fixed the code smell (hopefully). Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Fixed the code smell (hopefully). Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Fixed the code smell (hopefully). Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * Security hotspots. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> * remove extra configuration Signed-off-by: jandadav <janda.david@gmail.com> * Updated Node JS configuration. Signed-off-by: DianaKorladinova <chanchunche@gmail.com> Co-authored-by: ViktorKorladinov <v.korladinov@gmail.com> Co-authored-by: Andrea Tabone <andrea.tabone@broadcom.com> Co-authored-by: jandadav <janda.david@gmail.com>
1 parent 2976db5 commit 1e077e8

15 files changed

+918
-369
lines changed

api-catalog-ui/frontend/src/actions/wizard-actions.jsx

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ export const insert = (parent, content) => {
9797
*/
9898
export function handleIndentationDependency(inputData, indentationDependency, indentation) {
9999
let result = indentation;
100-
inputData.forEach(category => {
101-
if (Array.isArray(category.content)) {
100+
if (indentationDependency !== undefined) {
101+
inputData.forEach(category => {
102102
category.content.forEach(inpt => {
103103
Object.keys(inpt).forEach(k => {
104104
if (k === indentationDependency) {
@@ -107,18 +107,25 @@ export function handleIndentationDependency(inputData, indentationDependency, in
107107
}
108108
});
109109
});
110-
} else {
111-
Object.keys(category.content).forEach(k => {
112-
if (k === indentationDependency) {
113-
result = result.concat('/', category.content[k].value);
114-
return result;
115-
}
116-
});
117-
}
118-
});
110+
});
111+
}
119112
return result;
120113
}
121114

115+
export function handleArrayIndentation(arrIndent, content) {
116+
let finalContent = [];
117+
if (arrIndent !== undefined) {
118+
let index = 0;
119+
content.forEach(set => {
120+
finalContent[index] = { [arrIndent]: set };
121+
index += 1;
122+
});
123+
} else {
124+
finalContent = content;
125+
}
126+
return finalContent;
127+
}
128+
122129
/**
123130
* Receives a single category and translates it to an object the yaml library can correctly convert to yaml
124131
* @param category a category
@@ -152,6 +159,7 @@ export const addCategoryToYamlObject = (category, parent, inputData) => {
152159
Object.keys(o).forEach(key => {
153160
content[index][key] = category.content[index][key].value;
154161
});
162+
content = handleArrayIndentation(category.arrIndent, content);
155163
index += 1;
156164
});
157165
}
@@ -160,10 +168,7 @@ export const addCategoryToYamlObject = (category, parent, inputData) => {
160168
if (!category.indentation) {
161169
insert(result, content);
162170
} else {
163-
let indent = category.indentation;
164-
if (category.indentationDependency !== undefined) {
165-
indent = handleIndentationDependency(inputData, category.indentationDependency, category.indentation);
166-
}
171+
const indent = handleIndentationDependency(inputData, category.indentationDependency, category.indentation);
167172
const arr = indent.split('/');
168173
arr.reverse().forEach(key => {
169174
if (key.length > 0)

api-catalog-ui/frontend/src/actions/wizard-actions.test.jsx

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/* eslint-disable no-undef */
1111
import * as constants from '../constants/wizard-constants';
1212
import * as actions from './wizard-actions';
13-
import { addCategoryToYamlObject, handleIndentationDependency, insert } from './wizard-actions';
13+
import { addCategoryToYamlObject, handleArrayIndentation, handleIndentationDependency, insert } from './wizard-actions';
1414

1515
describe('>>> Wizard actions tests', () => {
1616
it('should get next category', () => {
@@ -106,7 +106,7 @@ describe('>>> Wizard actions tests', () => {
106106
const inputData = [
107107
{
108108
text: 'Category 1',
109-
content: { test: { value: '', question: 'Why', }, },
109+
content: [{ test: { value: '', question: 'Why', }, }],
110110
},
111111
{
112112
text: 'Category 2',
@@ -121,31 +121,14 @@ describe('>>> Wizard actions tests', () => {
121121
const result = handleIndentationDependency(inputData, indentationDepenedency, indentation);
122122
expect(result).toEqual('indent/val');
123123
})
124-
it('should handle indentation dependencies when content is not an array', () => {
125-
const inputData = [
126-
{
127-
text: 'Category 1',
128-
content: { test: { value: '', question: 'Why', }, },
129-
},
130-
{
131-
text: 'Category 2',
132-
content: {
133-
test2: { value: 'val', question: 'Why not?', },
134-
},
135-
},
136-
];
137-
const indentation = 'indent';
138-
const indentationDepenedency = 'test2';
139-
const result = handleIndentationDependency(inputData, indentationDepenedency, indentation);
140-
expect(result).toEqual('indent/val');
141-
})
142124
it('should add categories to the YAML object and handle indentation', () => {
143125
const category = {
144126
text: 'Category 1',
145127
content: [{ test: { value: 'yaml' } }],
146-
multiple: false,
128+
multiple: true,
147129
indentation: 'category1',
148130
indentationDependency: 'test2',
131+
arrIndent: 'indent',
149132
};
150133
const inputData = [
151134
{
@@ -155,7 +138,7 @@ describe('>>> Wizard actions tests', () => {
155138
];
156139
let result = { test3: 'test 3' };
157140
result = addCategoryToYamlObject(category, result, inputData);
158-
expect(result).toEqual({ category1: { val: { test: 'yaml' } }, test3: 'test 3' });
141+
expect(result).toEqual({ category1: { val: [{indent: { test: 'yaml'} }] }, test3: 'test 3' });
159142
});
160143
it('should add categories to the YAML object and handle empty indentation', () => {
161144
const category = {
@@ -173,28 +156,13 @@ describe('>>> Wizard actions tests', () => {
173156
it('should not add categories to the YAML object if they are not shown', () => {
174157
const category = {
175158
text: 'Category 1',
176-
content: [{
177-
test: { value: 'yaml', show: false}
178-
}],
159+
content: [{ test: { value: 'yaml', show: false} }],
179160
multiple: false,
180161
indentation: '/',
181162
};
182163
let result = { test2: 'test 2' };
183164
result = addCategoryToYamlObject(category, result);
184165
expect(result).toEqual({ test2: 'test 2' });});
185-
it('should not add categories to the YAML object if they are not shown', () => {
186-
const category = {
187-
text: 'Category 1',
188-
content: [{
189-
test: { value: 'yaml', show: false}
190-
}],
191-
multiple: false,
192-
indentation: '/',
193-
};
194-
let result = { test2: 'test 2' };
195-
result = addCategoryToYamlObject(category, result);
196-
expect(result).toEqual({ test2: 'test 2' });
197-
});
198166
it('should change the category', () => {
199167
const expectedAction = {
200168
type: constants.CHANGE_CATEGORY,
@@ -243,5 +211,10 @@ describe('>>> Wizard actions tests', () => {
243211
};
244212
expect(actions.validateInput('Nav', true)).toEqual(expectedAction);
245213
});
246-
214+
it('should add indentation before wrapping in an array', () => {
215+
const content = [{ test: ''}];
216+
const arrIndent = 'indent';
217+
const result = handleArrayIndentation(arrIndent,content);
218+
expect(result).toEqual([{indent: {test: ''}}]);
219+
})
247220
});

api-catalog-ui/frontend/src/components/Wizard/WizardComponents/WizardInputs.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ class WizardInputs extends Component {
101101
Object.keys(myObject).forEach(key => {
102102
newObject[key] = { ...myObject[key] };
103103
newObject[key].interactedWith = false;
104-
newObject[key].value = '';
104+
if (typeof newObject[key].value !== 'boolean') {
105+
newObject[key].value = '';
106+
}
105107
newObject[key].question = myObject[key].question;
106108
});
107109
const contentCopy = [...this.props.data.content];

api-catalog-ui/frontend/src/components/Wizard/WizardComponents/WizardInputs.test.jsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,23 @@ describe('>>> WizardInputs tests', () => {
242242
instance.addFields();
243243
expect(updateWizardData).toHaveBeenCalled();
244244
});
245+
it('should add more fields when value is boolean', () => {
246+
const updateWizardData = jest.fn();
247+
const dummyData = {
248+
text: 'Dummy Data',
249+
content: [{
250+
test: { value: true, question: '', show: true },
251+
test2: { value: '', question: '', show: true },
252+
}],
253+
multiple: true,
254+
};
255+
const wrapper = enzyme.shallow(
256+
<WizardInputs updateWizardData={updateWizardData} data={dummyData} />
257+
);
258+
const instance = wrapper.instance();
259+
instance.addFields();
260+
expect(updateWizardData).toHaveBeenCalled();
261+
});
245262
it('should delete added input fields', () => {
246263
const deleteCategoryConfig = jest.fn();
247264
const validateInput = jest.fn();

0 commit comments

Comments
 (0)