-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from LuisValgoi/feat-formik-refactored
[ISSUE-9] Feature of Formik + Yup Sample
- Loading branch information
Showing
60 changed files
with
1,000 additions
and
144 deletions.
There are no files selected for viewing
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
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
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,10 +1,14 @@ | ||
const { MemoryRouter } = require('react-router-dom'); | ||
|
||
module.exports = { | ||
data: { | ||
todos: { | ||
id: 'UG9rZW1vbjowMDE=', | ||
number: '001', | ||
description: '001', | ||
name: 'Task 1', | ||
completed: false, | ||
completed: true, | ||
priority: 'HIGH', | ||
type: 'PERSONAL', | ||
}, | ||
}, | ||
}; |
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
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
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,6 +1,6 @@ | ||
{ | ||
"*/v1/user/logged": "/GET_USER_LOGGED", | ||
"*/v1/todo/detail/:id": "/GET_TODO_BY_ID", | ||
"*/v1/todo/all\\?page=0": "/GET_TODO_LIST", | ||
"*/v1/todo/all\\?page=1": "/GET_TODO_LIST_PAGE_1" | ||
"*/v1/todo/all\\?page=1": "/GET_TODO_LIST_PAGE_1", | ||
"*/v1/todo/:id": "/GET_TODO_BY_ID" | ||
} |
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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,19 @@ | ||
import React from 'react'; | ||
|
||
import { FlexBox, FlexBoxDirection } from '@ui5/webcomponents-react'; | ||
import Label from '../Label/Label'; | ||
|
||
const FieldBase = ({ labelText, ...props }) => { | ||
return ( | ||
<FlexBox data-testid="fieldbase-wrapper" direction={props.direction ? props.direction : FlexBoxDirection.Column} {...props}> | ||
{labelText && ( | ||
<Label required={props.required} for={props.for} showColon={props.showColon}> | ||
{labelText} | ||
</Label> | ||
)} | ||
{props.children} | ||
</FlexBox> | ||
); | ||
}; | ||
|
||
export default FieldBase; |
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,40 @@ | ||
import React from 'react'; | ||
|
||
import '@testing-library/jest-dom/extend-expect'; | ||
import { render, screen } from '../../../util/TestSetup'; | ||
|
||
import FieldBase from '../FieldBase/FieldBase'; | ||
|
||
describe('FieldBase.js Test Suite', () => { | ||
beforeEach(() => { | ||
render( | ||
<FieldBase labelText="Text Content"> | ||
<p data-testid="inner-component-wrapper">Some Inner Text</p> | ||
</FieldBase>, | ||
); | ||
}); | ||
|
||
test('should match snapshot', () => { | ||
const { asFragment } = render( | ||
<FieldBase labelText="Text Content"> | ||
<p data-testid="inner-component-wrapper"></p> | ||
</FieldBase>, | ||
); | ||
|
||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
|
||
test('should render', () => { | ||
const component = screen.getByTestId('fieldbase-wrapper'); | ||
|
||
expect(component).toBeInTheDocument(); | ||
}); | ||
|
||
test('should render with Inner Component with Text Content as text', () => { | ||
const component = screen.getByTestId('fieldbase-wrapper'); | ||
const innerComponent = screen.getByTestId('inner-component-wrapper'); | ||
|
||
expect(component).toBeInTheDocument(); | ||
expect(innerComponent).toHaveTextContent('Some Inner Text'); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
src/components/Form/FieldBase/__snapshots__/FieldBase.test.js.snap
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,31 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`FieldBase.js Test Suite should match snapshot 1`] = ` | ||
<DocumentFragment> | ||
<div | ||
class="FlexBox-flexBox-0-2-1 FlexBox-flexBoxDirectionColumn-0-2-8 FlexBox-justifyContentStart-0-2-3 FlexBox-alignItemsStretch-0-2-15 FlexBox-flexWrapNoWrap-0-2-17" | ||
data-testid="fieldbase-wrapper" | ||
> | ||
Label { | ||
"_domRefReadyPromise": Promise { | ||
"_deferredResolve": [Function], | ||
}, | ||
"_firePropertyChange": false, | ||
"_fullyConnected": false, | ||
"_inDOM": false, | ||
"_monitoredChildProps": Map {}, | ||
"_shouldInvalidateParent": false, | ||
"_state": Object { | ||
"for": "", | ||
"required": false, | ||
"showColon": false, | ||
"wrap": true, | ||
}, | ||
"_upToDate": false, | ||
} | ||
<p | ||
data-testid="inner-component-wrapper" | ||
/> | ||
</div> | ||
</DocumentFragment> | ||
`; |
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,24 @@ | ||
import React from 'react'; | ||
|
||
import { spacing } from '@ui5/webcomponents-react-base'; | ||
import { Input as UI5Input, ValueState } from '@ui5/webcomponents-react'; | ||
import FieldBase from '../FieldBase/FieldBase'; | ||
|
||
const Input = ({ field, form: { touched, errors }, labelText, style, ...props }) => { | ||
const errorMsg = touched[field.name] && errors[field.name]; | ||
const errorState = errorMsg ? ValueState.Error : ValueState.None; | ||
|
||
const innerStyle = { | ||
...style, | ||
...spacing.sapUiTinyMarginBottom, | ||
width: '100%', | ||
}; | ||
|
||
return ( | ||
<FieldBase labelText={labelText} required={props.required} for={props.for} showColon={props.showColon}> | ||
<UI5Input data-testid="input-wrapper" valueState={errorState} valueStateMessage={<span>{errorMsg}</span>} style={innerStyle} {...props} {...field} /> | ||
</FieldBase> | ||
); | ||
}; | ||
|
||
export default Input; |
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,32 @@ | ||
import React from 'react'; | ||
|
||
import '@testing-library/jest-dom/extend-expect'; | ||
import { render, screen } from '../../../util/TestSetup'; | ||
|
||
import Input from '../Input/Input'; | ||
|
||
describe('Input.js Test Suite', () => { | ||
test('should match snapshot', () => { | ||
const { asFragment } = render(<Input labelText="Text Content" name="description" field={{ name: 'description' }} form={{ touched: { name: 'description' }, errors: { name: 'description' } }} />); | ||
|
||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
|
||
test('should have rendered with the fieldbase', () => { | ||
render(<Input labelText="Text Content" name="description" field={{ name: 'description' }} form={{ touched: { name: 'description' }, errors: { name: 'description' } }} />); | ||
|
||
const fieldbase = screen.getByTestId('fieldbase-wrapper'); | ||
const component = screen.getByTestId('input-wrapper'); | ||
|
||
expect(fieldbase).toBeInTheDocument(); | ||
expect(component).toBeInTheDocument(); | ||
}); | ||
|
||
test('should have attribute name as description if passed', () => { | ||
render(<Input labelText="Text Content" name="description" field={{ name: 'description' }} form={{ touched: { name: 'description' }, errors: { name: 'description' } }} />); | ||
|
||
const component = screen.getByTestId('input-wrapper'); | ||
|
||
expect(component).toHaveProperty('name', 'description'); | ||
}); | ||
}); |
Oops, something went wrong.