diff --git a/source/components/CurrencyInput/CurrencyInput.test.js b/source/components/CurrencyInput/CurrencyInput.test.js index 2abaa2ce5..f1e0f6eb4 100644 --- a/source/components/CurrencyInput/CurrencyInput.test.js +++ b/source/components/CurrencyInput/CurrencyInput.test.js @@ -12,7 +12,7 @@ describe('CurrencyInput', () => { it('should accept both . and , as decimal separator', () => { let onChange = spy() - const input = getInput() + const input = getInput() input.simulate('change', { target: { value: '12.1' } }) expect(onChange).to.have.been.calledWith( match.hasNested('target.value', '12.1') @@ -25,7 +25,7 @@ describe('CurrencyInput', () => { it('should not accept negative number', () => { let onChange = spy() - const input = getInput() + const input = getInput() input.simulate('change', { target: { value: '-12' } }) expect(onChange).to.have.been.calledWith( match.hasNested('target.value', '12') @@ -34,7 +34,7 @@ describe('CurrencyInput', () => { it('should not accept anything else than number', () => { let onChange = spy() - const input = getInput() + const input = getInput() input.simulate('change', { target: { value: '*1/2abc3' } }) expect(onChange).to.have.been.calledWith( match.hasNested('target.value', '123') @@ -46,20 +46,20 @@ describe('CurrencyInput', () => { }) it('should not call onChange while the decimal part is being written', () => { let onChange = spy() - const input = getInput() + const input = getInput() input.simulate('change', { target: { value: '111,' } }) expect(onChange).not.to.have.been.called }) it('should change the position of the currency symbol depending on the language', () => { - const inputFr = shallow() + const inputFr = shallow() expect( inputFr .children() .last() .text() ).to.includes('€') - const inputEn = shallow() + const inputEn = shallow() expect( inputEn .children() @@ -72,7 +72,7 @@ describe('CurrencyInput', () => { const clock = useFakeTimers() let onChange = spy() const input = getInput( - + ) input.simulate('change', { target: { value: '1' } }) expect(onChange).not.to.have.been.called @@ -86,4 +86,26 @@ describe('CurrencyInput', () => { ) clock.restore() }) + + it('should initialize with value of the storeValue prop', () => { + const input = getInput() + expect(input.prop('value')).to.eq(1) + }) + + it('should update its value if the storeValue prop changes', () => { + const wrapper = shallow() + wrapper.setProps({ storeValue: 2 }) + expect(wrapper.state('value')).to.equal(2) + }) + it('should not update state if the storeValue is the same as the current input value', () => { + const wrapper = shallow( + {}} /> + ) + const input = wrapper.find('input') + input.simulate('change', { target: { value: '2000' } }) + const state1 = wrapper.state() + wrapper.setProps({ storeValue: '2000' }) + const state2 = wrapper.state() + expect(state1).to.equal(state2) + }) })