diff --git a/src/tests/createHeadlessForm.test.js b/src/tests/createHeadlessForm.test.js index 41584642..375205cd 100644 --- a/src/tests/createHeadlessForm.test.js +++ b/src/tests/createHeadlessForm.test.js @@ -15,7 +15,6 @@ import { schemaInputTypeRadioOptionsWithDetails, schemaInputTypeSelectSoloDeprecated, schemaInputTypeSelectSolo, - schemaInputTypeSelectString, schemaInputTypeSelectMultipleDeprecated, schemaInputTypeSelectMultiple, schemaInputTypeSelectMultipleOptional, @@ -432,7 +431,7 @@ describe('createHeadlessForm', () => { }); describe('field support', () => { - function assertOptionsAllowed({ handleValidation, fieldName, validOptions, isString = false }) { + function assertOptionsAllowed({ handleValidation, fieldName, validOptions }) { const validateForm = (vals) => friendlyError(handleValidation(vals)); // All allowed options are valid @@ -440,34 +439,27 @@ describe('createHeadlessForm', () => { expect(validateForm({ [fieldName]: value })).toBeUndefined(); }); - if (!isString) { - // Any other arbitrary value is not valid. - expect(validateForm({ [fieldName]: 'blah-blah' })).toEqual({ - [fieldName]: 'The option "blah-blah" is not valid.', - }); - - // Given undefined, it says it's a required field. - expect(validateForm({})).toEqual({ - [fieldName]: 'Required field', - }); + // Any other arbitrary value is not valid. + expect(validateForm({ [fieldName]: 'blah-blah' })).toEqual({ + [fieldName]: 'The option "blah-blah" is not valid.', + }); - // As required field, empty string ("") is also considered empty. @BUG RMT-518 - // Expectation: The error to be "The option '' is not valid." - expect(validateForm({ [fieldName]: '' })).toEqual({ - [fieldName]: 'Required field', - }); + // Given undefined, it says it's a required field. + expect(validateForm({})).toEqual({ + [fieldName]: 'Required field', + }); - // As required field, null is also considered empty @BUG RMT-518 - // Expectation: The error to be "The option null is not valid." - expect(validateForm({ [fieldName]: null })).toEqual({ - [fieldName]: 'Required field', - }); - } + // As required field, empty string ("") is also considered empty. @BUG RMT-518 + // Expectation: The error to be "The option '' is not valid." + expect(validateForm({ [fieldName]: '' })).toEqual({ + [fieldName]: 'Required field', + }); - if (isString) { - // Any other arbitrary value is valid. - expect(validateForm({ [fieldName]: 'blah-blah' })).toBeUndefined(); - } + // As required field, null is also considered empty @BUG RMT-518 + // Expectation: The error to be "The option null is not valid." + expect(validateForm({ [fieldName]: null })).toEqual({ + [fieldName]: 'Required field', + }); } it('support "text" field type', () => { @@ -639,41 +631,6 @@ describe('createHeadlessForm', () => { }); }); - it('supports "select" field type with string option', () => { - const { fields, handleValidation } = createHeadlessForm(schemaInputTypeSelectString); - const fieldSelect = fields[0]; - expect(fieldSelect).toMatchObject({ - name: 'browsers', - label: 'Browsers (solo)', - description: 'This solo select also includes a disabled option.', - options: [ - { - value: 'chr', - label: 'Chrome', - }, - { - value: 'ff', - label: 'Firefox', - }, - { - value: 'ie', - label: 'Internet Explorer', - disabled: true, - }, - { value: undefined, type: 'string', label: '{Create another}' }, - ], - }); - - expect(fieldSelect).not.toHaveProperty('multiple'); - - assertOptionsAllowed({ - handleValidation, - fieldName: 'browsers', - validOptions: ['chr', 'ff', 'ie'], - isString: true, - }); - }); - it('supports "select" field type with multiple options @deprecated', () => { const result = createHeadlessForm(schemaInputTypeSelectMultipleDeprecated); expect(result).toMatchObject({ diff --git a/src/tests/helpers.js b/src/tests/helpers.js index e2056ca1..984b65e3 100644 --- a/src/tests/helpers.js +++ b/src/tests/helpers.js @@ -238,11 +238,6 @@ export const mockSelectInputSolo = { }, }; -export const mockSelectInputSoloCreatable = { - ...mockSelectInputSolo, - oneOf: [...mockSelectInputSolo.oneOf, { type: 'string', title: '{Create another}' }], -}; - export const mockSelectInputMultiple = { title: 'Browsers (multiple)', description: 'This multi-select also includes a disabled option.', @@ -942,10 +937,6 @@ export const schemaInputTypeSelectSolo = JSONSchemaBuilder() .setRequiredFields(['browsers']) .build(); -export const schemaInputTypeSelectString = JSONSchemaBuilder().addInput({ - browsers: mockSelectInputSoloCreatable, -}); - /** @deprecated */ export const schemaInputTypeSelectMultipleDeprecated = JSONSchemaBuilder() .addInput({ diff --git a/src/yupSchema.js b/src/yupSchema.js index 11b2ecc6..d92369b8 100644 --- a/src/yupSchema.js +++ b/src/yupSchema.js @@ -60,10 +60,7 @@ const validateMaxDate = (value, minDate) => { const yupSchemas = { text: validateOnlyStrings, - radioOrSelect: (options, isString) => { - if (isString) { - return string().nullable(); - } + radioOrSelect: (options) => { return string() .nullable() .transform((value) => { @@ -215,9 +212,8 @@ const getYupSchema = ({ inputType, ...field }) => { const jsonType = getJsonTypeInArray(field.jsonType); if (field.options?.length > 0) { - const isString = field.options?.findIndex((option) => option.type === 'string') > -1; const optionValues = getOptions(field); - return yupSchemas.radioOrSelect(optionValues, isString); + return yupSchemas.radioOrSelect(optionValues); } if (field.format === 'date') {