diff --git a/packages/codegen-ui-react/lib/__tests__/__snapshots__/studio-ui-codegen-react-forms.test.ts.snap b/packages/codegen-ui-react/lib/__tests__/__snapshots__/studio-ui-codegen-react-forms.test.ts.snap index 0c12080ef..988e54768 100644 --- a/packages/codegen-ui-react/lib/__tests__/__snapshots__/studio-ui-codegen-react-forms.test.ts.snap +++ b/packages/codegen-ui-react/lib/__tests__/__snapshots__/studio-ui-codegen-react-forms.test.ts.snap @@ -2322,7 +2322,7 @@ export default function CustomDataForm(props) { const initialValues = { name: \\"John Doe\\", email: \\"johndoe@amplify.com\\", - city: undefined, + city: \\"\\", category: undefined, pages: 0, phone: \\"+1-401-152-6995\\", @@ -2719,7 +2719,7 @@ export default function CustomDataForm(props) { const initialValues = { name: \\"John Doe\\", email: \\"johndoe@amplify.com\\", - city: undefined, + city: \\"\\", category: undefined, pages: 0, phone: \\"+1-401-152-6995\\", @@ -3625,7 +3625,7 @@ export default function CustomDataForm(props) { name: \\"John Doe\\", email: \\"johndoe@amplify.com\\", \\"metadata-field\\": \\"\\", - city: undefined, + city: \\"\\", category: undefined, pages: 0, }; @@ -8201,7 +8201,7 @@ export default function NestedJson(props) { props; const initialValues = { firstName: \\"\\", - \\"last-Name\\": undefined, + \\"last-Name\\": \\"\\", lastName: [], bio: {}, }; @@ -12748,15 +12748,14 @@ export default function TagCreateForm(props) { setCurrentPostsValue(undefined); setCurrentPostsDisplayValue(\\"\\"); setStatuses(initialValues.statuses); - setCurrentStatusesValue(undefined); + setCurrentStatusesValue(\\"\\"); setErrors({}); }; const [currentPostsDisplayValue, setCurrentPostsDisplayValue] = React.useState(\\"\\"); const [currentPostsValue, setCurrentPostsValue] = React.useState(undefined); const PostsRef = React.createRef(); - const [currentStatusesValue, setCurrentStatusesValue] = - React.useState(undefined); + const [currentStatusesValue, setCurrentStatusesValue] = React.useState(\\"\\"); const statusesRef = React.createRef(); const getIDValue = { Posts: (r) => JSON.stringify({ id: r?.id }), @@ -12997,7 +12996,7 @@ export default function TagCreateForm(props) { values = result?.statuses ?? values; } setStatuses(values); - setCurrentStatusesValue(undefined); + setCurrentStatusesValue(\\"\\"); }} currentFieldValue={currentStatusesValue} label={\\"Statuses\\"} @@ -13007,7 +13006,7 @@ export default function TagCreateForm(props) { getBadgeText={getDisplayValue.statuses} setFieldValue={setCurrentStatusesValue} inputFieldRef={statusesRef} - defaultFieldValue={undefined} + defaultFieldValue={\\"\\"} > JSON.stringify({ id: r?.id }), @@ -15151,7 +15149,7 @@ export default function TagCreateForm(props) { values = result?.statuses ?? values; } setStatuses(values); - setCurrentStatusesValue(undefined); + setCurrentStatusesValue(\\"\\"); }} currentFieldValue={currentStatusesValue} label={\\"Statuses\\"} @@ -15161,7 +15159,7 @@ export default function TagCreateForm(props) { getBadgeText={getDisplayValue.statuses} setFieldValue={setCurrentStatusesValue} inputFieldRef={statusesRef} - defaultFieldValue={undefined} + defaultFieldValue={\\"\\"} > JSON.stringify({ id: r?.id }), @@ -18342,7 +18339,7 @@ export default function TagUpdateForm(props) { values = result?.statuses ?? values; } setStatuses(values); - setCurrentStatusesValue(undefined); + setCurrentStatusesValue(\\"\\"); }} currentFieldValue={currentStatusesValue} label={\\"Statuses\\"} @@ -18352,7 +18349,7 @@ export default function TagUpdateForm(props) { getBadgeText={getDisplayValue.statuses} setFieldValue={setCurrentStatusesValue} inputFieldRef={statusesRef} - defaultFieldValue={undefined} + defaultFieldValue={\\"\\"} > { getInputByLabel('Email').type('jd@yahoo.com'); cy.contains(ErrorMessageMap.validEmail).should('not.exist'); + cy.get('select').select('Green').should('have.value', 'Green'); + cy.contains('Clear').click(); + cy.get('select').should('have.value', ''); + // validates on blur & extends with onValidate prop getInputByLabel('Name').type('S'); blurField(); @@ -74,6 +78,7 @@ describe('FormTests - CustomDog', () => { blurField(); getInputByLabel('IP Address').type('192.0.2.146'); blurField(); + cy.get('select').select('Blue'); typeInAutocomplete('Ret{downArrow}{enter}'); cy.contains('Submit').click(); cy.contains('submitted: true'); @@ -81,6 +86,7 @@ describe('FormTests - CustomDog', () => { cy.contains('age: 3'); cy.contains('email: spot@yahoo.com'); cy.contains('ip: 192.0.2.146'); + cy.contains('color: Blue'); cy.contains('Retriever'); }); }); diff --git a/packages/test-generator/integration-test-templates/cypress/e2e/form/DSAllSupportedFormFields-spec.cy.ts b/packages/test-generator/integration-test-templates/cypress/e2e/form/DSAllSupportedFormFields-spec.cy.ts index b8d8912c9..ba58e041b 100644 --- a/packages/test-generator/integration-test-templates/cypress/e2e/form/DSAllSupportedFormFields-spec.cy.ts +++ b/packages/test-generator/integration-test-templates/cypress/e2e/form/DSAllSupportedFormFields-spec.cy.ts @@ -443,22 +443,22 @@ describe('FormTests - DSAllSupportedFormFields', () => { const record = JSON.parse(recordElement.text()); expect(record.stringArray).to.deep.equal([]); - expect('int' in record).to.equal(false); - expect('float' in record).to.equal(false); - expect('awsDate' in record).to.equal(false); - expect('awsTime' in record).to.equal(false); - expect('awsDateTime' in record).to.equal(false); - expect('awsTimestamp' in record).to.equal(false); - expect('awsEmail' in record).to.equal(false); - expect('awsUrl' in record).to.equal(false); - expect('awsIPAddress' in record).to.equal(false); - expect('awsJson' in record).to.equal(false); - expect('awsPhone' in record).to.equal(false); - expect('enum' in record).to.equal(false); - expect('nonModelField' in record).to.equal(false); + expect(record.int).to.equal(null); + expect(record.float).to.equal(null); + expect(record.awsDate).to.equal(null); + expect(record.awsTime).to.equal(null); + expect(record.awsDateTime).to.equal(null); + expect(record.awsTimestamp).to.equal(null); + expect(record.awsEmail).to.equal(null); + expect(record.awsUrl).to.equal(null); + expect(record.awsIPAddress).to.equal(null); + expect(record.awsJson).to.equal(null); + expect(record.awsPhone).to.equal(null); + expect(record.enum).to.equal(null); + expect(record.nonModelField).to.equal(null); expect(record.nonModelFieldArray).to.deep.equal([]); - expect('HasOneUser' in record).to.equal(false); - expect('BelongsToOwner' in record).to.equal(false); + expect(record.HasOneUser).to.equal(undefined); + expect(record.BelongsToOwner).to.equal(undefined); expect(record.HasManyStudents).to.deep.equal([]); expect(record.ManyToManyTags).to.deep.equal([]); }); diff --git a/packages/test-generator/integration-test-templates/src/FormTests/CustomDog.tsx b/packages/test-generator/integration-test-templates/src/FormTests/CustomDog.tsx index fe6e72ccb..a1da649b3 100644 --- a/packages/test-generator/integration-test-templates/src/FormTests/CustomDog.tsx +++ b/packages/test-generator/integration-test-templates/src/FormTests/CustomDog.tsx @@ -45,6 +45,7 @@ export default function () { {`email: ${customFormCreateDogResults.email}`} {`ip: ${customFormCreateDogResults.ip}`} {`ip: ${customFormCreateDogResults.breed}`} + {`color: ${customFormCreateDogResults.color}`} ); diff --git a/packages/test-generator/lib/forms/custom-form-create-dog.json b/packages/test-generator/lib/forms/custom-form-create-dog.json index 26a022859..31c1e0065 100644 --- a/packages/test-generator/lib/forms/custom-form-create-dog.json +++ b/packages/test-generator/lib/forms/custom-form-create-dog.json @@ -54,6 +54,17 @@ }, "required": false } + }, + "color": { + "label": "Color", + "inputType": { + "type": "SelectField", + "bindingProperties": {}, + "valueMappings": { + "bindingProperties": {}, + "values": [{"value": {"value": "Red"}}, {"value": {"value": "Blue"}}, {"value": {"value": "Green"}}] + } + } } }, "sectionalElements": {