Skip to content

Commit

Permalink
Fixing tests with modalEdit by removing some hacks with nested wizard…
Browse files Browse the repository at this point in the history
…s and modal edit components.
  • Loading branch information
travist committed Nov 25, 2024
1 parent 08b39fe commit bb70b36
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 31 deletions.
5 changes: 0 additions & 5 deletions src/Webform.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,11 +670,6 @@ export default class Webform extends NestedDataComponent {
if (this.onSetForm) {
this.onSetForm(_.cloneDeep(this._form), form);
}

if (this.parent?.component?.modalEdit) {
this.formReadyResolve();
return Promise.resolve();
}
} catch (err) {
console.warn(err);
// If provided form is not a valid JSON object, do not set it too
Expand Down
19 changes: 4 additions & 15 deletions src/WebformBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1275,25 +1275,14 @@ export default class WebformBuilder extends Component {
findRepeatablePaths() {
const repeatablePaths = [];
const keys = new Map();

eachComponent(this.form.components, (comp, path) => {
if (!comp.key) {
return;
}

if (keys.has(comp.key)) {
if (keys.get(comp.key).includes(path)) {
repeatablePaths.push(path);
}
else {
keys.set(comp.key, [...keys.get(comp.key), path]);
}
eachComponent(this.form.components, (comp, path, components, parent, paths) => {
if (keys.has(paths.dataPath)) {
repeatablePaths.push(paths.dataPath);
}
else {
keys.set(comp.key, [path]);
keys.set(paths.dataPath, true);
}
}, true);

return repeatablePaths;
}

Expand Down
7 changes: 0 additions & 7 deletions src/Wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,13 +1036,6 @@ export default class Wizard extends Webform {
}
}

redraw() {
if (this.parent?.component?.modalEdit) {
return this.parent.redraw();
}
return super.redraw();
}

rebuild() {
const currentPage = this.page;
const setCurrentPage = () => this.setPage(currentPage);
Expand Down
2 changes: 1 addition & 1 deletion src/components/_classes/component/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ export default class Component extends Element {
/* eslint-enable max-statements */

get componentsMap() {
return this.root.childComponentsMap;
return this.root?.childComponentsMap || {};
}

get data() {
Expand Down
1 change: 1 addition & 0 deletions src/components/form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ export default class FormComponent extends Component {
const modalShouldBeOpened = this.componentModal ? this.componentModal.isOpened : false;
const currentValue = modalShouldBeOpened ? this.componentModal.currentValue : this.dataValue;
this.componentModal = new ComponentModal(this, element, modalShouldBeOpened, currentValue, this._referenceAttributeName);
this.subForm.element = this.componentModal.refs.modalContents;
this.setOpenModalElement();
}

Expand Down
5 changes: 2 additions & 3 deletions test/unit/Wizard.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,8 @@ describe('Wizard tests', () => {
assert.deepEqual(wizard.submission.data, submission.data, 'Should get wizard submission data');

wizard.everyComponent((comp) => {
const expectedValue = _.get(submission.data, comp.path, 'no data');

if (expectedValue !== 'no data') {
if (comp.hasInput) {
const expectedValue = _.get(submission.data, comp.path, undefined);
assert.deepEqual(comp.getValue(), expectedValue, `Should set value for ${comp.component.type} inside wizard`);
assert.deepEqual(comp.dataValue, expectedValue, `Should set value for ${comp.component.type} inside wizard`);
}
Expand Down

0 comments on commit bb70b36

Please sign in to comment.