From 3a4cc4ef5eb69ce648029435880e78e1483f038d Mon Sep 17 00:00:00 2001 From: David Ellingsworth Date: Tue, 16 Apr 2019 17:40:24 -0400 Subject: [PATCH] Add test coverage for CustomFileInput --- src/__tests__/CustomInput.spec.js | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/__tests__/CustomInput.spec.js b/src/__tests__/CustomInput.spec.js index e0f3ef361..7eec0ce97 100644 --- a/src/__tests__/CustomInput.spec.js +++ b/src/__tests__/CustomInput.spec.js @@ -264,6 +264,45 @@ describe('Custom Inputs', () => { expect(ref.current).not.toBeNull(); expect(ref.current).toBeInstanceOf(HTMLInputElement); }); + + describe('onChange', () => { + it('calls props.onChange if it exists', () => { + const onChange = jest.fn(); + const file = mount(); + + file.find('input').hostNodes().simulate('change'); + expect(onChange).toHaveBeenCalled(); + }); + }); + + it('removes fakepath from file name', () => { + const file = mount(); + + file.find('input').hostNodes().simulate('change', { + target:{ + value:'C:\\fakepath\\test.txt' + } + }); + + expect(file.find('.custom-file-label').text()).toBe('test.txt'); + }); + + it('lists multiple files when supported', () => { + const file = mount(); + + file.find('input').hostNodes().simulate('change', { + target:{ + value:'C:\\fakepath\\file1.txt', + files:[ + {name:"file1.txt"}, + {name:'file2.txt'}, + {name:'file3.txt'}, + ] + } + }) + + expect(file.find('.custom-file-label').text()).toBe('file1.txt, file2.txt, file3.txt'); + }) }); describe('CustomRange', () => {