Skip to content

Commit

Permalink
Merge branch 'main' into auth-validationData-type-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
iartemiev authored Apr 13, 2021
2 parents d5ed713 + c4ccc17 commit f252195
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`amplify-auth-fields spec: Render logic -> should render custom type fields 1`] = `
<amplify-auth-fields>
<mock:shadow-root>
<div class="auth-fields">
<amplify-form-field label="date" type="date"></amplify-form-field>
</div>
</mock:shadow-root>
</amplify-auth-fields>
`;

exports[`amplify-auth-fields spec: Render logic -> should render with a \`username\` and \`password\` field 1`] = `
<amplify-auth-fields formfields="username,password">
<amplify-auth-fields>
<mock:shadow-root>
<div class="auth-fields"></div>
<div class="auth-fields">
<amplify-username-field></amplify-username-field>
<amplify-password-field></amplify-password-field>
</div>
</mock:shadow-root>
</amplify-auth-fields>
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('amplify-auth-fields spec:', () => {
it('should return form fields as being defined when passing `username` and `password` as parameter', () => {
const constructFormFieldOptionsMock = jest.spyOn(authFields, 'constructFormFieldOptions');
const result = ['username', 'password'];

authFields.formFields = ['username', 'password'];

authFields.constructFormFieldOptions();
Expand All @@ -48,10 +48,14 @@ describe('amplify-auth-fields spec:', () => {
const usernameField = ['username', 'password'];

const page = await newSpecPage({
components: [AmplifyAuthFields],
html: `<amplify-auth-fields formFields=${usernameField}></amplify-auth-fields>`
components: [AmplifyAuthFields]
});

const component = page.doc.createElement("amplify-auth-fields");
(component as any).formFields = usernameField;
page.body.appendChild(component);
await page.waitForChanges();

expect(page.root).toMatchSnapshot();
});

Expand All @@ -63,5 +67,20 @@ describe('amplify-auth-fields spec:', () => {

expect(page.root).toMatchSnapshot();
});

it('should render custom type fields', async () => {
const customField = [{'label': 'date', 'type': 'date'}];

const page = await newSpecPage({
components: [AmplifyAuthFields]
});

const component = page.doc.createElement("amplify-auth-fields");
(component as any).formFields = customField;
page.body.appendChild(component);
await page.waitForChanges();

expect(page.root).toMatchSnapshot();
});
});
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { h } from '@stencil/core';
import { FormFieldType, PhoneFormFieldType } from './amplify-auth-fields-interface';
import { TextFieldTypes } from '../../common/types/ui-types';

const componentFieldMapping = {
username: (ff: FormFieldType) => (
Expand Down Expand Up @@ -64,6 +65,7 @@ const componentFieldMapping = {
default: (ff: FormFieldType) => (
<amplify-form-field
label={ff.label}
type={ff.type as TextFieldTypes}
placeholder={ff.placeholder}
required={ff.required}
handleInputChange={ff.handleInputChange}
Expand Down

0 comments on commit f252195

Please sign in to comment.