Last active
August 21, 2017 22:19
-
-
Save bntzio/112df2de637397279704d522d0bcde2f to your computer and use it in GitHub Desktop.
HexCandy.com AddCandy test
This file contains hidden or 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
| var React = require('react'); | |
| var ReactDOM = require('react-dom'); | |
| var $ = require('jquery'); | |
| var TestUtils = require('react-addons-test-utils'); | |
| var expect = require('expect'); | |
| import * as actions from 'actions'; | |
| var { AddCandy } = require('AddCandy'); | |
| describe('AddCandy', () => { | |
| it('should exist', () => { | |
| expect(AddCandy).toExist(); | |
| }); | |
| it('should not dispatch ADD_CANDY with invalid candy name or value', () => { | |
| var candyName = ''; | |
| var candyValue = ''; | |
| var action = { | |
| type: 'ADD_CANDY', | |
| name: candyName, | |
| value: candyValue | |
| }; | |
| var spy = expect.createSpy(); | |
| var addCandy = TestUtils.renderIntoDocument(<AddCandy dispatch={spy} />); | |
| var $el = $(ReactDOM.findDOMNode(addCandy)); | |
| addCandy.refs.candyName.value = candyName; | |
| addCandy.refs.candyValue.value = candyValue; | |
| TestUtils.Simulate.submit($el.find('form')[0]); | |
| expect(spy).toNotHaveBeenCalled(); | |
| }); | |
| it('should not dispatch ADD_CANDY with invalid candy name', () => { | |
| var candyName = ''; | |
| var candyValue = '#ed317b'; | |
| var action = { | |
| type: 'ADD_CANDY', | |
| name: candyName, | |
| value: candyValue | |
| }; | |
| var spy = expect.createSpy(); | |
| var addCandy = TestUtils.renderIntoDocument(<AddCandy dispatch={spy} />); | |
| var $el = $(ReactDOM.findDOMNode(addCandy)); | |
| addCandy.refs.candyName.value = candyName; | |
| addCandy.refs.candyValue.value = candyValue; | |
| TestUtils.Simulate.submit($el.find('form')[0]); | |
| expect(spy).toNotHaveBeenCalled(); | |
| }); | |
| it('should not dispatch ADD_CANDY with invalid candy value', () => { | |
| var candyName = 'My Candy'; | |
| var candyValue = ''; | |
| var action = { | |
| type: 'ADD_CANDY', | |
| name: candyName, | |
| value: candyValue | |
| }; | |
| var spy = expect.createSpy(); | |
| var addCandy = TestUtils.renderIntoDocument(<AddCandy dispatch={spy} />); | |
| var $el = $(ReactDOM.findDOMNode(addCandy)); | |
| addCandy.refs.candyName.value = candyName; | |
| addCandy.refs.candyValue.value = candyValue; | |
| TestUtils.Simulate.submit($el.find('form')[0]); | |
| expect(spy).toNotHaveBeenCalled(); | |
| }); | |
| it('should dispatch ADD_CANDY with valid name and value', () => { | |
| var candyName = 'My Candy'; | |
| var candyValue = '#ed317b'; | |
| var action = actions.startAddCandy(candyName, candyValue); | |
| var spy = expect.createSpy(); | |
| var addCandy = TestUtils.renderIntoDocument(<AddCandy dispatch={spy} />); | |
| var $el = $(ReactDOM.findDOMNode(addCandy)); | |
| addCandy.refs.candyName.value = candyName; | |
| addCandy.refs.candyValue.value = candyValue; | |
| TestUtils.Simulate.submit($el.find('form')[0]); | |
| expect(spy).toHaveBeenCalledWith(action); | |
| }); | |
| it('should not dispatch ADD_CANDY if candy value if not a hex value', () => { | |
| var candyName = 'My Candy'; | |
| var candyValue = '#ed317z'; | |
| var action = { | |
| type: 'ADD_CANDY', | |
| name: candyName, | |
| value: candyValue | |
| }; | |
| var spy = expect.createSpy(); | |
| var addCandy = TestUtils.renderIntoDocument(<AddCandy dispatch={spy} />); | |
| var $el = $(ReactDOM.findDOMNode(addCandy)); | |
| addCandy.refs.candyName.value = candyName; | |
| addCandy.refs.candyValue.value = candyValue; | |
| TestUtils.Simulate.submit($el.find('form')[0]); | |
| expect(spy).toNotHaveBeenCalled(); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment