diff --git a/test/formTypes/subform.test.js b/test/formTypes/subform.test.js index 61ae402..29ab92a 100644 --- a/test/formTypes/subform.test.js +++ b/test/formTypes/subform.test.js @@ -103,6 +103,26 @@ describe('Field: subform', () => { const setDefaultEl = new DOMWrapper(document.querySelector('.Everright-formEditor-ConfigSubformDefaultValueComponent')) expect(setDefaultEl.findAll(utils.getTestId('SubformLayout:item'))).toHaveLength(0) }) + test('Only one child: field Required', async () => { + const newField = _.cloneDeep(field) + field.columns[0].options.required = true + newField.columns[0] = newField.columns[0].id + const subForm = erGeneratorData(_.cloneDeep(erComponentsConfig.fieldsConfig[2].list[5]), true, 'en') + const list = _.cloneDeep(subForm) + list.columns[0] = subForm.columns[0].id + subForm.columns[0].list[0].push(newField) + const data = wrapLayoutDataByLayoutType([list], [subForm.columns[0], field.columns[0]]) + await previewWrapper.findComponent({ ref: 'EReditorRef' }).vm.setData(data) + expect(previewWrapper.find(utils.getTestId('SubformLayout:addButton')).exists()).toBe(true) + expect(previewWrapper.findAll(utils.getTestId('SubformLayout:item'))).toHaveLength(0) + await previewWrapper.find(utils.getTestId('SubformLayout:addButton')).find('button').trigger('click') + expect(previewWrapper.findAll(utils.getTestId('SubformLayout:item'))).toHaveLength(1) + previewWrapper.find('[data-test="er-complete-button"] button').trigger('click') + await flushPromises() + expect([list.columns[0], newField.columns[0]]).toStrictEqual(previewWrapper.findAll('[data-field-id]').map(element => element.element.dataset.fieldId)) + expect(previewWrapper.find(`[data-field-id="${list.columns[0]}"] .el-form-item`).classes()).not.toContain('is-required') + expect(previewWrapper.find(`[data-field-id="${newField.columns[0]}"] .el-form-item`).classes()).toContain('is-required') + }) test('Only one child: has 2 default contents', async () => { const values = ['1', '2'] const newField = _.cloneDeep(field)