From bad41b42130ecc787760198e6325b53a945632d6 Mon Sep 17 00:00:00 2001 From: Maxime Quandalle Date: Tue, 4 Jun 2019 11:13:38 +0200 Subject: [PATCH] Ajout d'un test CurrencyInput autogrow --- source/components/CurrencyInput/CurrencyInput.js | 2 +- .../CurrencyInput/CurrencyInput.test.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/source/components/CurrencyInput/CurrencyInput.js b/source/components/CurrencyInput/CurrencyInput.js index 3587bb885..af778c9ac 100644 --- a/source/components/CurrencyInput/CurrencyInput.js +++ b/source/components/CurrencyInput/CurrencyInput.js @@ -38,7 +38,7 @@ class CurrencyInput extends Component { // Only trigger the `onChange` event if the value has changed -- and not // only its formating, we don't want to call it when a dot is added in `12.` // for instance - if (!this.handleNextChange) { + if (!this.handleNextChange || !this.onChange) { return } this.handleNextChange = false diff --git a/source/components/CurrencyInput/CurrencyInput.test.js b/source/components/CurrencyInput/CurrencyInput.test.js index cd492910e..9776acac1 100644 --- a/source/components/CurrencyInput/CurrencyInput.test.js +++ b/source/components/CurrencyInput/CurrencyInput.test.js @@ -118,10 +118,23 @@ describe('CurrencyInput', () => { it('should not call onChange the value is the same as the current input value', () => { let onChange = spy() - const wrapper = mount( {}} />) + const wrapper = mount() const input = wrapper.find('input') input.simulate('change', { target: { value: '2000', focus: () => {} } }) wrapper.setProps({ value: '2000' }) expect(onChange).not.to.have.been.called }) + + it('should adapt its size to its content', () => { + const wrapper = mount() + // It would be better to use `input.offsetWidth` but it's not supported by + // Enzyme/JSDOM + const getInlineWidth = () => + getComputedStyle( + wrapper.find('.currencyInput__container').getDOMNode() + ).getPropertyValue('width') + expect(getInlineWidth()).to.equal('') + wrapper.setProps({ value: '1000000' }) + expect(Number(getInlineWidth().replace(/em$/, ''))).to.be.greaterThan(5) + }) })