-
Notifications
You must be signed in to change notification settings - Fork 24
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 #338 from kettanaito/307-validation-grouped-fields
Introduces selectors API for grouped fields
- Loading branch information
Showing
32 changed files
with
1,212 additions
and
595 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
describe('Field types', function() { | ||
before(() => { | ||
cy.loadStory(['Basics', 'Interaction', 'Uncontrolled fields']) | ||
}) | ||
|
||
it('Sets "type: text" on inputs by default', () => { | ||
cy.getField('inputOne').should('have.attr', 'type', 'text') | ||
cy.getField('inputTwo').should('have.attr', 'type', 'text') | ||
cy.getField('inputTwo').should('have.attr', 'type', 'text') | ||
}) | ||
|
||
it('Sets custom "type" for Radio, Checkbox', () => { | ||
cy.getField('radio') | ||
.first() | ||
.should('have.attr', 'type', 'radio') | ||
cy.getField('checkboxOne').should('have.attr', 'type', 'checkbox') | ||
}) | ||
|
||
it('Sets no "type" on Select, Textarea', () => { | ||
cy.getField('select').should('not.have.attr', 'type') | ||
cy.getField('textareaOne').should('not.have.attr', 'type') | ||
}) | ||
|
||
describe('Custom field types', () => { | ||
before(() => { | ||
cy.loadStory(['Other', 'Full examples', 'Registration form']) | ||
}) | ||
|
||
it('Sets custom "type" for inputs', () => { | ||
cy.getField('userEmail').should('have.attr', 'type', 'email') | ||
cy.getField('userPassword').should('have.attr', 'type', 'password') | ||
}) | ||
|
||
it('Allows deviation of "type" on custom fields (BirthDate)', () => { | ||
cy.getField('birthDate') | ||
.first() | ||
.should('have.attr', 'type', 'text') | ||
}) | ||
}) | ||
}) |
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
44 changes: 44 additions & 0 deletions
44
cypress/integration/validation/other/ConditionalSchema.spec.js
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,44 @@ | ||
const useFirstSchema = () => cy.get('#btn-one').click() | ||
const useSecondSchema = () => cy.get('#btn-two').click() | ||
|
||
describe('Conditional schema', function() { | ||
before(() => { | ||
cy.loadStory(['Validation', 'Other', 'Conditional schema']) | ||
}) | ||
|
||
it('Properly validates with initial schema', () => { | ||
cy.getField('fieldOne') | ||
.valid(false) | ||
.invalid(false) | ||
.type('fo') | ||
.invalid() | ||
.type('o') | ||
.expected() | ||
.clear() | ||
.type('bar') | ||
.expected(false) | ||
|
||
cy.getField('fieldTwo') | ||
.hasValue('bar') | ||
.expected(false) | ||
}) | ||
|
||
it('Properly validates after schema is changed on runtime', () => { | ||
useSecondSchema() | ||
cy.getField('fieldOne') | ||
.expected() | ||
.clear() | ||
.type('foo') | ||
.expected(false) | ||
|
||
useFirstSchema() | ||
cy.getField('fieldOne').expected() | ||
}) | ||
|
||
it('Resets validation state of fields not present in next schema', () => { | ||
useSecondSchema() | ||
cy.getField('fieldTwo') | ||
.valid(false) | ||
.invalid(false) | ||
}) | ||
}) |
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,3 +1,4 @@ | ||
describe('Misc', () => { | ||
describe('Other', () => { | ||
require('./ConditionalSchema.spec') | ||
require('./AjaxPrefilling.spec') | ||
}) |
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
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
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,62 @@ | ||
import React from 'react' | ||
import { Form } from 'react-advanced-form' | ||
import { Input } from '@examples/fields' | ||
import Button from '@examples/shared/Button' | ||
|
||
const schemaOne = { | ||
name: { | ||
fieldOne: ({ value }) => value === 'foo', | ||
fieldTwo: ({ value }) => value !== 'bar', | ||
}, | ||
} | ||
|
||
const schemaTwo = { | ||
name: { | ||
fieldOne: ({ value }) => value === 'bar', | ||
}, | ||
} | ||
|
||
export default class ConditionalSchema extends React.Component { | ||
state = { | ||
flag: true, | ||
} | ||
|
||
render() { | ||
const { flag } = this.state | ||
const rules = flag ? schemaOne : schemaTwo | ||
|
||
return ( | ||
<React.Fragment> | ||
<h1>Conditional schema</h1> | ||
|
||
<Form rules={rules}> | ||
<Input | ||
name="fieldOne" | ||
label="Field one" | ||
hint={ | ||
<span> | ||
Validates differently based on <code>form.props.rules</code> | ||
</span> | ||
} | ||
required | ||
/> | ||
|
||
<Input name="fieldTwo" initialValue="bar" /> | ||
|
||
<Button | ||
id="btn-one" | ||
onClick={() => this.setState(({ flag }) => ({ flag: true }))} | ||
> | ||
Use first schema | ||
</Button> | ||
<Button | ||
id="btn-two" | ||
onClick={() => this.setState(({ flag }) => ({ flag: false }))} | ||
> | ||
Use second schema | ||
</Button> | ||
</Form> | ||
</React.Fragment> | ||
) | ||
} | ||
} |
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
Oops, something went wrong.