Created
August 21, 2017 22:19
-
-
Save bntzio/5d4d996aabd4149adf773353977e2683 to your computer and use it in GitHub Desktop.
HexCandy.com Reducers Tests
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 expect = require('expect'); | |
| var reducers = require('reducers'); | |
| var df = require('deep-freeze-strict'); | |
| describe('Reducers', () => { | |
| describe('candiesReducer', () => { | |
| it('should add new candy', () => { | |
| var action = { | |
| type: 'ADD_CANDY', | |
| candy: { | |
| id: 'zhs8a1', | |
| name: 'Orange', | |
| value: '#ff4742' | |
| } | |
| }; | |
| var res = reducers.candiesReducer(df([]), df(action)); | |
| expect(res.length).toEqual(1); | |
| expect(res[0].name).toBe(action.candy.name); | |
| }); | |
| it('should add existing candies', () => { | |
| var candies = [{ | |
| name: 'Blue', | |
| value: '#007dcc' | |
| }]; | |
| var action = { | |
| type: 'ADD_CANDIES', | |
| candies | |
| }; | |
| var res = reducers.candiesReducer(df([]), df(action)); | |
| expect(res.length).toEqual(1); | |
| expect(res[0]).toEqual(candies[0]); | |
| }); | |
| it('should remove candy', () => { | |
| var candies = [ | |
| { | |
| id: '567', | |
| name: 'Pinky', | |
| value: '#ed317b' | |
| }, | |
| { | |
| id: '912', | |
| name: 'Electric Yellow', | |
| value: '#fffc00' | |
| } | |
| ]; | |
| var action = { | |
| type: 'REMOVE_CANDY', | |
| id: '567' | |
| }; | |
| var res = reducers.candiesReducer(df(candies), df(action)); | |
| expect(res.length).toEqual(1); | |
| expect(res[0].name).toBe('Electric Yellow'); | |
| }); | |
| it('should lowercase candy value before adding the candy', () => { | |
| var action = { | |
| type: 'ADD_CANDY', | |
| candy: { | |
| id: '66tfg', | |
| name: 'Blue', | |
| value: '#0000EE' | |
| } | |
| }; | |
| var res = reducers.candiesReducer(df([]), df(action)); | |
| expect(res[0].value).toBe('#0000ee'); | |
| }); | |
| it('should mofify candy value if it does not start with #', () => { | |
| var action = { | |
| type: 'ADD_CANDY', | |
| candy: { | |
| id: '49z1h2', | |
| name: 'Royal Purple', | |
| value: '6114cc' | |
| } | |
| }; | |
| var res = reducers.candiesReducer(df([]), df(action)); | |
| expect(res[0].value).toBe('#6114cc'); | |
| }); | |
| it('should wipe candies on LOGOUT', () => { | |
| var candies = [{ | |
| id: '8a7stdf', | |
| name: 'Magenta', | |
| value: '#6c38b2' | |
| }]; | |
| var action = { | |
| type: 'LOGOUT' | |
| }; | |
| var res = reducers.candiesReducer(df(candies), df(action)); | |
| expect(res.length).toEqual(0); | |
| }); | |
| }); | |
| describe('authReducer', () => { | |
| it('should store uid on LOGIN', () => { | |
| const action = { | |
| type: 'LOGIN', | |
| uid: '12fbac' | |
| }; | |
| const res = reducers.authReducer(undefined, df(action)); | |
| expect(res).toEqual({ | |
| uid: action.uid | |
| }); | |
| }); | |
| it('should wipe auth on LOGOUT', () => { | |
| const authData = { | |
| uid: '12bhfk4' | |
| }; | |
| const action = { | |
| type: 'LOGOUT' | |
| }; | |
| const res = reducers.authReducer(df(authData), df(action)); | |
| expect(res).toEqual({}); | |
| }); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment