Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent user from submitting empty feedback
Also, clear the component's state after a successful submission so the UI is empty. Closes 18F/crime-data-explorer#267
- Loading branch information
Jeremia Kimelman
committed
Aug 2, 2017
1 parent
82948a6
commit 0101f80
Showing
2 changed files
with
79 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* eslint no-undef: 0 */ | ||
|
||
import { shallow } from 'enzyme' | ||
import React from 'react' | ||
|
||
import Feedback from '../../src/components/Feedback' | ||
|
||
describe('Feedback', () => { | ||
describe('createInitialState()', () => { | ||
it('returns an object with "result" set to {}', () => { | ||
const wrapper = shallow(<Feedback onClose={() => {}} />) | ||
const actual = wrapper.instance().createInitialState() | ||
|
||
expect(actual.result).toEqual({}) | ||
}) | ||
|
||
it('returns an object with "data" based on props', () => { | ||
const wrapper = shallow(<Feedback onClose={() => {}} />) | ||
const instance = wrapper.instance() | ||
const actualFields = Object.keys(instance.createInitialState().data) | ||
const propFields = instance.props.fields | ||
|
||
expect(actualFields.length).toEqual(propFields.length) | ||
}) | ||
}) | ||
|
||
describe('validateSubmission()', () => { | ||
it('returns false if all textareas are empty strings', () => { | ||
const wrapper = shallow(<Feedback onClose={() => {}} />) | ||
const actual = wrapper.instance().validateSubmission() | ||
|
||
expect(actual).toEqual(false) | ||
}) | ||
|
||
it('returns true if at least one textarea is not an empty string', () => { | ||
const wrapper = shallow( | ||
<Feedback fields={[{ id: 'foo', label: 'hey' }]} onClose={() => {}} />, | ||
) | ||
const instance = wrapper.instance() | ||
const { state } = instance | ||
instance.state = { ...state, data: { foo: 'yo' } } | ||
|
||
expect(instance.validateSubmission()).toEqual(true) | ||
}) | ||
}) | ||
}) |