Skip to content

Commit

Permalink
test(subform): only one child: field Required
Browse files Browse the repository at this point in the history
  • Loading branch information
Liberty-liu committed Sep 10, 2023
1 parent 42031c5 commit ba7cd63
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/formTypes/subform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ba7cd63

Please sign in to comment.