-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Cuong Vu
authored
Jul 17, 2020
1 parent
ca548ff
commit e1ea44c
Showing
9 changed files
with
617 additions
and
315 deletions.
There are no files selected for viewing
512 changes: 389 additions & 123 deletions
512
...nents/pages/settings/forms/__tests__/__snapshots__/contact-information-form.test.tsx.snap
Large diffs are not rendered by default.
Oops, something went wrong.
116 changes: 52 additions & 64 deletions
116
...er-portal/src/components/pages/settings/forms/__tests__/contact-information-form.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,72 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
import { | ||
defaultInitialValues, | ||
generateInitialValues, | ||
ContactInformationForm, | ||
ContactInformationFormProps, | ||
mapPropsContactInformation, | ||
EnhanceContactInformationProps, | ||
ContactInformationValues, | ||
handleSubmitContactInformation, | ||
} from '../contact-information-form' | ||
import { mockFormikAction } from '@/utils/mock-formik' | ||
import { developerStub } from '@/sagas/__stubs__/developer' | ||
import appState from '@/reducers/__stubs__/app-state' | ||
import { DeveloperModel } from '@reapit/foundations-ts-definitions' | ||
|
||
const developerInfo: DeveloperModel | null = appState.settings.developerInfomation | ||
|
||
const valuesMock: ContactInformationValues = { | ||
name: 'name', | ||
jobTitle: 'jobTitle', | ||
telephone: '12341234', | ||
companyName: 'companyName', | ||
} | ||
|
||
describe('ContactInformationForm', () => { | ||
it('should match snapshot', () => { | ||
const mockProps = { | ||
isSubmitting: false, | ||
isValidating: false, | ||
isValid: true, | ||
} as ContactInformationFormProps | ||
const wrapper = shallow(<ContactInformationForm {...mockProps} />) | ||
const wrapper = shallow( | ||
<ContactInformationForm developerInformation={developerInfo} updateDeveloperInformation={jest.fn()} />, | ||
) | ||
expect(wrapper).toMatchSnapshot() | ||
}) | ||
it('should match snapshot', () => { | ||
const mockProps = { | ||
isSubmitting: true, | ||
isValidating: true, | ||
isValid: false, | ||
} as ContactInformationFormProps | ||
const wrapper = shallow(<ContactInformationForm {...mockProps} />) | ||
|
||
it('should match snapshot with developerInfomation = null', () => { | ||
const wrapper = shallow( | ||
<ContactInformationForm developerInformation={null} updateDeveloperInformation={jest.fn()} />, | ||
) | ||
expect(wrapper).toMatchSnapshot() | ||
}) | ||
describe('mapPropsContactInformation', () => { | ||
it('should run correctly', () => { | ||
const mockProps: EnhanceContactInformationProps = { | ||
developerInformation: developerStub, | ||
updateDeveloperInformation: jest.fn(), | ||
} | ||
const result = mapPropsContactInformation(mockProps) | ||
const output = { | ||
jobTitle: mockProps.developerInformation?.jobTitle || '', | ||
telephone: mockProps.developerInformation?.telephone || '', | ||
companyName: mockProps.developerInformation?.company || '', | ||
name: mockProps.developerInformation?.name || '', | ||
} | ||
expect(result).toEqual(output) | ||
}) | ||
}) | ||
|
||
it('should return to fall back', () => { | ||
const mockProps: EnhanceContactInformationProps = { | ||
developerInformation: developerStub, | ||
updateDeveloperInformation: jest.fn(), | ||
} | ||
const result = mapPropsContactInformation(mockProps) | ||
const output = { | ||
jobTitle: mockProps.developerInformation?.jobTitle || '', | ||
telephone: mockProps.developerInformation?.telephone || '', | ||
companyName: mockProps.developerInformation?.company || '', | ||
name: mockProps.developerInformation?.name || '', | ||
} | ||
expect(result).toEqual(output) | ||
describe('handleSubmitContactInformation', () => { | ||
it('should run correctly', () => { | ||
const updateDeveloperInformation = jest.fn() | ||
const setSubmitting = jest.fn() | ||
const fn = handleSubmitContactInformation(updateDeveloperInformation) | ||
fn(valuesMock, { setSubmitting } as any) | ||
expect(setSubmitting).toHaveBeenCalledWith(true) | ||
expect(updateDeveloperInformation).toHaveBeenCalledWith(valuesMock) | ||
}) | ||
}) | ||
|
||
describe('generateInitialValues', () => { | ||
it('should return correctly', () => { | ||
const result = generateInitialValues({ | ||
developerInfo, | ||
defaultInitialValues, | ||
}) | ||
const { name, company: companyName, telephone, jobTitle } = developerInfo as DeveloperModel | ||
const expectedResult = { | ||
name, | ||
companyName, | ||
telephone, | ||
jobTitle, | ||
} | ||
expect(result).toEqual(expectedResult) | ||
}) | ||
describe('handleSubmitContactInformation', () => { | ||
it('should call setSubmitting', () => { | ||
const mockValues: ContactInformationValues = { | ||
companyName: 'Reapit Ltd', | ||
name: 'Reapit Ltd', | ||
jobTitle: 'Head of Cloud', | ||
telephone: '01234 567890', | ||
} | ||
const mockForm = { | ||
...mockFormikAction, | ||
} | ||
const mockProps: EnhanceContactInformationProps = { | ||
developerInformation: developerStub, | ||
updateDeveloperInformation: jest.fn(), | ||
} | ||
handleSubmitContactInformation(mockValues, { ...mockForm, props: mockProps }) | ||
expect(mockForm.setSubmitting).toBeCalledWith(true) | ||
expect(mockProps.updateDeveloperInformation).toBeCalled() | ||
|
||
it('should return correctly with developerInfo null', () => { | ||
const result = generateInitialValues({ | ||
developerInfo: null, | ||
defaultInitialValues, | ||
}) | ||
expect(result).toEqual(defaultInitialValues) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/developer-portal/src/components/pages/settings/forms/form-schema/form-fields.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { FormFieldInfo } from '@reapit/elements' | ||
|
||
type FieldContactInformation = 'companyNameField' | 'nameField' | 'jobTitleField' | 'telephoneField' | ||
|
||
export const formFieldsContactInfomation: Record<FieldContactInformation, FormFieldInfo> = { | ||
companyNameField: { | ||
name: 'companyName', | ||
label: 'Company Name', | ||
errorMessage: 'Company name is not valid', | ||
}, | ||
nameField: { | ||
name: 'name', | ||
label: 'Full Name', | ||
errorMessage: 'Full name is not valid', | ||
}, | ||
jobTitleField: { | ||
name: 'jobTitle', | ||
label: 'Job Title', | ||
errorMessage: 'Job title is not valid', | ||
}, | ||
telephoneField: { | ||
name: 'telephone', | ||
label: 'Telephone', | ||
errorMessage: 'Telephone is not valid', | ||
}, | ||
} |
Oops, something went wrong.