-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix clear logic to work in both controlled and uncontrolled
+ tests - significantly easier to test in Cypress/E2E than Jest/jsdom + bonus perf memoization
- Loading branch information
Showing
2 changed files
with
80 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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, { useState } from 'react'; | ||
import { EuiTextArea } from './text_area'; | ||
|
||
describe('EuiTextArea', () => { | ||
describe('isClearable', () => { | ||
it('works for uncontrolled components', () => { | ||
cy.realMount(<EuiTextArea isClearable />); | ||
|
||
cy.get('textarea').type('hello world'); | ||
cy.get('textarea').should('have.value', 'hello world'); | ||
|
||
cy.get('[data-test-subj="clearTextAreaButton"]').click(); | ||
cy.get('textarea').should('have.value', ''); | ||
}); | ||
|
||
it('works for controlled components', () => { | ||
const ControlledTextArea = ({}) => { | ||
const [value, setValue] = useState(''); | ||
return ( | ||
<EuiTextArea | ||
value={value} | ||
onChange={(e) => setValue(e.target.value)} | ||
isClearable | ||
/> | ||
); | ||
}; | ||
cy.realMount(<ControlledTextArea />); | ||
|
||
cy.get('textarea').type('hello world'); | ||
cy.get('textarea').should('have.value', 'hello world'); | ||
|
||
cy.get('[data-test-subj="clearTextAreaButton"]').click(); | ||
cy.get('textarea').should('have.value', ''); | ||
}); | ||
}); | ||
}); |
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