From 9d13557244d8dc6dfd3c8fb02bf3ffb0ddd793ae Mon Sep 17 00:00:00 2001 From: Nathan Hunzaker Date: Thu, 29 Jun 2017 13:44:05 -0400 Subject: [PATCH] Add test to ensure extra zeros are covered by tests (#10033) * Add test to ensure extra zeros are covered by tests * Add DOM test fixture for trailing zeros * Drop quotes to improve clarity --- .../number-inputs/NumberInputExtraZeroes.js | 30 +++++++++++++++++++ .../fixtures/number-inputs/index.js | 25 ++++++++++++++++ scripts/fiber/tests-passing.txt | 1 + .../wrappers/__tests__/ReactDOMInput-test.js | 17 +++++++++++ 4 files changed, 73 insertions(+) create mode 100644 fixtures/dom/src/components/fixtures/number-inputs/NumberInputExtraZeroes.js diff --git a/fixtures/dom/src/components/fixtures/number-inputs/NumberInputExtraZeroes.js b/fixtures/dom/src/components/fixtures/number-inputs/NumberInputExtraZeroes.js new file mode 100644 index 0000000000..88c250131e --- /dev/null +++ b/fixtures/dom/src/components/fixtures/number-inputs/NumberInputExtraZeroes.js @@ -0,0 +1,30 @@ +const React = window.React; + +import Fixture from '../../Fixture'; + +class NumberInputExtraZeroes extends React.Component { + state = { value: '3.0000' } + changeValue = () => { + this.setState({ + value: '3.0000' + }); + } + onChange = event => { + this.setState({ value: event.target.value }); + } + render() { + const { value } = this.state + return ( + +
{this.props.children}
+ +
+ + +
+
+ ); + } +} + +export default NumberInputExtraZeroes; diff --git a/fixtures/dom/src/components/fixtures/number-inputs/index.js b/fixtures/dom/src/components/fixtures/number-inputs/index.js index 7e08aa2202..246760d044 100644 --- a/fixtures/dom/src/components/fixtures/number-inputs/index.js +++ b/fixtures/dom/src/components/fixtures/number-inputs/index.js @@ -4,6 +4,7 @@ import FixtureSet from '../../FixtureSet'; import TestCase from '../../TestCase'; import NumberTestCase from './NumberTestCase'; import NumberInputDecimal from './NumberInputDecimal'; +import NumberInputExtraZeroes from './NumberInputExtraZeroes'; function NumberInputs() { return ( @@ -173,6 +174,30 @@ function NumberInputs() { + + + +
  • Change the text to 4.0000
  • +
  • Click "Reset to 3.0000"
  • +
    + + + The field should read 3.0000, not 3 + + + + +

    + Notes: Firefox drops extraneous zeroes when + assigned. Zeroes are preserved when editing, however + directly assigning a new value will drop zeroes. This is + a bug in Firefox that we can not control for. +

    +
    ); } diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt index 2e36948c29..8a981f3b23 100644 --- a/scripts/fiber/tests-passing.txt +++ b/scripts/fiber/tests-passing.txt @@ -1657,6 +1657,7 @@ src/renderers/dom/shared/wrappers/__tests__/ReactDOMInput-test.js * does change the string "2" to "2.0" with no change handler * changes the number 2 to "2.0" using a change handler * does change the string ".98" to "0.98" with no change handler +* distinguishes precision for extra zeroes in string number values * should display `defaultValue` of number 0 * only assigns defaultValue if it changes * should display "true" for `defaultValue` of `true` diff --git a/src/renderers/dom/shared/wrappers/__tests__/ReactDOMInput-test.js b/src/renderers/dom/shared/wrappers/__tests__/ReactDOMInput-test.js index f69b3c91b1..b90923c772 100644 --- a/src/renderers/dom/shared/wrappers/__tests__/ReactDOMInput-test.js +++ b/src/renderers/dom/shared/wrappers/__tests__/ReactDOMInput-test.js @@ -251,6 +251,23 @@ describe('ReactDOMInput', () => { expect(node.value).toEqual('0.98'); }); + it('distinguishes precision for extra zeroes in string number values', () => { + class Stub extends React.Component { + state = { + value: '3.0000', + }; + render() { + return ; + } + } + + var stub = ReactTestUtils.renderIntoDocument(); + var node = ReactDOM.findDOMNode(stub); + stub.setState({value: '3'}); + + expect(node.value).toEqual('3'); + }); + it('should display `defaultValue` of number 0', () => { var stub = ; stub = ReactTestUtils.renderIntoDocument(stub);