From 06d9813a7b4c389660e6edd64b594a7eed30b67d Mon Sep 17 00:00:00 2001 From: Joe Prang Date: Thu, 2 Jan 2020 14:21:52 +0000 Subject: [PATCH 1/3] Add type=button to input button to prevent triggering of form submission when toggling the select dropdown. While testing a form with a Select component, we found that when clicking the toggle for the Select component it was triggering the form submission (as opposed to clicking the "Submit" button. This was due to the fact that no type attribute was specified on the button element that triggers the dropdown of select inputs. This commit adds this type attribute to fix this. It also adds some additional data-qaids to enable easier testing of Select Inputs. --- src/molecules/Select/Input.test.tsx | 14 ++++++++---- src/molecules/Select/Input.tsx | 3 ++- src/molecules/Select/Select.test.tsx | 6 ++++- .../Select/__snapshots__/Input.test.tsx.snap | 13 +++++++++++ .../Select/__snapshots__/Select.test.tsx.snap | 22 +++++++++++++++++++ 5 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/molecules/Select/Input.test.tsx b/src/molecules/Select/Input.test.tsx index 70fbd7a2..4852ba83 100644 --- a/src/molecules/Select/Input.test.tsx +++ b/src/molecules/Select/Input.test.tsx @@ -25,7 +25,9 @@ const setup = ( describe('Select ', () => { it('it renders correctly', () => { - expect(setup()).toMatchSnapshot(); + expect( + setup(false, 'I am a placeholder', false, 'testDataId') + ).toMatchSnapshot(); }); it('it has the correct style properties when isOpen is false', () => { @@ -56,10 +58,14 @@ describe('Select ', () => { expect(placeholder).toBe('I am a placeholder'); }); - it('it adds a data-qaid', () => { + it('it adds a data-qaid on the InputWrapper, InputStyle, and Button', () => { let wrapper = setup(true, 'cat', true, 'testDataId'); - let qaid = wrapper.find('Input').props()['data-qaid']; - expect(qaid).toBe('testDataId'); + let wrapperQaid = wrapper.find('Input').props()['data-qaid']; + expect(wrapperQaid).toBe('testDataId'); + let inputQaid = wrapper.find('input').props()['data-qaid']; + expect(inputQaid).toBe('testDataId-input'); + let buttonQaid = wrapper.find('button').props()['data-qaid']; + expect(buttonQaid).toBe('testDataId-toggle'); }); it('it handles no data-qaid', () => { diff --git a/src/molecules/Select/Input.tsx b/src/molecules/Select/Input.tsx index 3d6ea30c..46c4b704 100644 --- a/src/molecules/Select/Input.tsx +++ b/src/molecules/Select/Input.tsx @@ -119,8 +119,9 @@ const Input: React.SFC = ({ isOpen={isOpen} placeholder={placeholder} name={name} + data-qaid={`${qaId}-input`} /> - diff --git a/src/molecules/Select/Select.test.tsx b/src/molecules/Select/Select.test.tsx index a50217bd..889caa8d 100644 --- a/src/molecules/Select/Select.test.tsx +++ b/src/molecules/Select/Select.test.tsx @@ -17,7 +17,11 @@ const setup = () =>
I am a idiot
- {({ optionClick }: any) => citiesData.map((cityData, index) => (