| 
 | 1 | +import {  | 
 | 2 | +  LOCATION_CHANGE,  | 
 | 3 | +  locationChange,  | 
 | 4 | +  updateLocation,  | 
 | 5 | +  default as locationReducer  | 
 | 6 | +} from 'store/location'  | 
 | 7 | + | 
 | 8 | +describe('(Internal Module) Location', () => {  | 
 | 9 | +  it('Should export a constant LOCATION_CHANGE.', () => {  | 
 | 10 | +    expect(LOCATION_CHANGE).to.equal('LOCATION_CHANGE')  | 
 | 11 | +  })  | 
 | 12 | + | 
 | 13 | +  describe('(Reducer)', () => {  | 
 | 14 | +    it('Should be a function.', () => {  | 
 | 15 | +      expect(locationReducer).to.be.a('function')  | 
 | 16 | +    })  | 
 | 17 | + | 
 | 18 | +    it('Should initialize with a state of null.', () => {  | 
 | 19 | +      expect(locationReducer(undefined, {})).to.equal(null)  | 
 | 20 | +    })  | 
 | 21 | + | 
 | 22 | +    it('Should return the previous state if an action was not matched.', () => {  | 
 | 23 | +      let state = locationReducer(undefined, {})  | 
 | 24 | +      expect(state).to.equal(null)  | 
 | 25 | +      state = locationReducer(state, { type: '@@@@@@@' })  | 
 | 26 | +      expect(state).to.equal(null)  | 
 | 27 | + | 
 | 28 | +      const locationState = { pathname: '/yup' }  | 
 | 29 | +      state = locationReducer(state, locationChange(locationState))  | 
 | 30 | +      expect(state).to.equal(locationState)  | 
 | 31 | +      state = locationReducer(state, { type: '@@@@@@@' })  | 
 | 32 | +      expect(state).to.equal(locationState)  | 
 | 33 | +    })  | 
 | 34 | +  })  | 
 | 35 | + | 
 | 36 | +  describe('(Action Creator) locationChange', () => {  | 
 | 37 | +    it('Should be exported as a function.', () => {  | 
 | 38 | +      expect(locationChange).to.be.a('function')  | 
 | 39 | +    })  | 
 | 40 | + | 
 | 41 | +    it('Should return an action with type "LOCATION_CHANGE".', () => {  | 
 | 42 | +      expect(locationChange()).to.have.property('type', LOCATION_CHANGE)  | 
 | 43 | +    })  | 
 | 44 | + | 
 | 45 | +    it('Should assign the first argument to the "payload" property.', () => {  | 
 | 46 | +      const locationState = { pathname: '/yup' }  | 
 | 47 | +      expect(locationChange(locationState)).to.have.property('payload', locationState)  | 
 | 48 | +    })  | 
 | 49 | + | 
 | 50 | +    it('Should default the "payload" property to "/" if not provided.', () => {  | 
 | 51 | +      expect(locationChange()).to.have.property('payload', '/')  | 
 | 52 | +    })  | 
 | 53 | +  })  | 
 | 54 | + | 
 | 55 | +  describe('(Specialized Action Creator) updateLocation', () => {  | 
 | 56 | +    let _globalState  | 
 | 57 | +    let _dispatchSpy  | 
 | 58 | +    let _getStateSpy  | 
 | 59 | + | 
 | 60 | +    beforeEach(() => {  | 
 | 61 | +      _globalState = {  | 
 | 62 | +        location : locationReducer(undefined, {})  | 
 | 63 | +      }  | 
 | 64 | +      _dispatchSpy = sinon.spy((action) => {  | 
 | 65 | +        _globalState = {  | 
 | 66 | +          ..._globalState,  | 
 | 67 | +          location : locationReducer(_globalState.location, action)  | 
 | 68 | +        }  | 
 | 69 | +      })  | 
 | 70 | +      _getStateSpy = sinon.spy(() => {  | 
 | 71 | +        return _globalState  | 
 | 72 | +      })  | 
 | 73 | + | 
 | 74 | +    })  | 
 | 75 | + | 
 | 76 | +    it('Should be exported as a function.', () => {  | 
 | 77 | +      expect(updateLocation).to.be.a('function')  | 
 | 78 | +    })  | 
 | 79 | + | 
 | 80 | +    it('Should return a function (is a thunk).', () => {  | 
 | 81 | +      expect(updateLocation({ dispatch: _dispatchSpy })).to.be.a('function')  | 
 | 82 | +    })  | 
 | 83 | + | 
 | 84 | +    it('Should call dispatch exactly once.', () => {  | 
 | 85 | +      const update = updateLocation({ dispatch: _dispatchSpy })('/')  | 
 | 86 | +      expect(_dispatchSpy.should.have.been.calledOnce)  | 
 | 87 | +    })  | 
 | 88 | +  })  | 
 | 89 | + | 
 | 90 | +})  | 
0 commit comments