-
Notifications
You must be signed in to change notification settings - Fork 844
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EuiFieldNumber] Fix browser invalid state not showing an icon or set…
…ting `aria-invalid` Browsers natively set their own custom `validity` based on min/max/value/step/etc - we should hook into these and extend them (as opposed to overriding them) + switch Jest tests from Enzyme to RTL while here
- Loading branch information
Showing
6 changed files
with
161 additions
and
33 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,55 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
/// <reference types="cypress" /> | ||
/// <reference types="cypress-real-events" /> | ||
/// <reference types="../../../../cypress/support" /> | ||
|
||
import React from 'react'; | ||
import { EuiFieldNumber } from './field_number'; | ||
|
||
describe('EuiFieldNumber', () => { | ||
describe('isNativelyInvalid', () => { | ||
const checkIsValid = () => { | ||
cy.get('[aria-invalid="true"]').should('not.exist'); | ||
cy.get('.euiFormControlLayoutIcons').should('not.exist'); | ||
}; | ||
const checkIsInvalid = () => { | ||
cy.get('[aria-invalid="true"]').should('exist'); | ||
cy.get('.euiFormControlLayoutIcons').should('exist'); | ||
}; | ||
|
||
it('when the value is not a valid number', () => { | ||
cy.mount(<EuiFieldNumber />); | ||
checkIsValid(); | ||
cy.get('input').click().realType('-.'); | ||
checkIsInvalid(); | ||
}); | ||
|
||
it('sets invalid state when the value is less than the passed min', () => { | ||
cy.mount(<EuiFieldNumber min={0} />); | ||
checkIsValid(); | ||
cy.get('input').click().type('-10'); | ||
checkIsInvalid(); | ||
}); | ||
|
||
it('sets invalid state when the value is greater than the passed max', () => { | ||
cy.mount(<EuiFieldNumber max={100} />); | ||
checkIsValid(); | ||
cy.get('input').click().type('101'); | ||
checkIsInvalid(); | ||
}); | ||
|
||
it('sets invalid state when the value is not a valid step', () => { | ||
cy.mount(<EuiFieldNumber step={3} />); | ||
checkIsValid(); | ||
cy.get('input').click().type('2'); | ||
checkIsInvalid(); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.