-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
301 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[](https://circleci.com/gh/neilff/ng-redux-ui-router) | ||
|
||
#ng-redux-ui-router | ||
|
||
[](https://circleci.com/gh/neilff/ng-redux-ui-router) | ||
|
||
This package contains a middleware for performing UI Router methods such as `$state.go` as well as a reducer for storing Angular UI state inside your store. | ||
|
||
Inspired by [Redux React Router](https://github.com/acdlite/redux-react-router) by [Andrew Clark](https://github.com/acdlite) |
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,40 @@ | ||
// Karma configuration | ||
// Generated on Sat Aug 22 2015 14:55:12 GMT-0400 (EDT) | ||
|
||
module.exports = function(config) { | ||
config.set({ | ||
basePath: './', | ||
frameworks: ['mocha'], | ||
files: [ | ||
'src/**/*.js' | ||
], | ||
exclude: [ | ||
], | ||
plugins: [ | ||
'karma-babel-preprocessor', | ||
'karma-mocha', | ||
'karma-phantomjs-launcher' | ||
], | ||
preprocessors: { | ||
'src/**/*.js': ['babel'] | ||
}, | ||
babelPreprocessor: { | ||
options: { | ||
sourceMap: 'inline' | ||
}, | ||
filename: function (file) { | ||
return file.originalPath.replace(/\.js$/, '.es5.js'); | ||
}, | ||
sourceFileName: function (file) { | ||
return file.originalPath; | ||
} | ||
}, | ||
reporters: ['progress'], | ||
port: 9876, | ||
colors: true, | ||
logLevel: config.LOG_INFO, | ||
autoWatch: true, | ||
browsers: ['PhantomJS'], | ||
singleRun: false | ||
}); | ||
}; |
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,2 @@ | ||
import chai from 'chai'; | ||
global.expect = chai.expect; |
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,24 @@ | ||
import 'chai'; | ||
import routerActions from '../router-actions'; | ||
|
||
let $ngReduxMock = { | ||
getStore: () => { | ||
return { | ||
dispatch: () => {} | ||
}; | ||
} | ||
}; | ||
|
||
describe('routerActions', () => { | ||
it('should bind the action creators', () => { | ||
let actions = routerActions($ngReduxMock); | ||
|
||
expect(actions.onStateChangeStart).to.be.a('function'); | ||
expect(actions.onStateChangeSuccess).to.be.a('function'); | ||
expect(actions.onStateChangeError).to.be.a('function'); | ||
expect(actions.onStateNotFound).to.be.a('function'); | ||
expect(actions.stateGo).to.be.a('function'); | ||
expect(actions.stateReload).to.be.a('function'); | ||
expect(actions.stateTransitionTo).to.be.a('function'); | ||
}); | ||
}); |
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,35 @@ | ||
import 'chai'; | ||
import routerStateReducer from '../router-state-reducer'; | ||
|
||
describe('routerStateReducer', () => { | ||
it('should return the initial state', () => { | ||
let action = { | ||
type: 'null', | ||
payload: {} | ||
}; | ||
|
||
let state = routerStateReducer(undefined, action); | ||
expect(state.toJS().currentState).to.equal(null); | ||
expect(state.toJS().currentParams).to.equal(null); | ||
expect(state.toJS().prevState).to.equal(null); | ||
expect(state.toJS().prevParams).to.equal(null); | ||
}); | ||
|
||
it('should set the provided state if the $stateChangeSuccess type is used', () => { | ||
let action = { | ||
type: '@@reduxUiRouter/$stateChangeSuccess', | ||
payload: { | ||
currentState: 'currentState', | ||
currentParams: 'currentParams', | ||
prevState: 'prevState', | ||
prevParams: 'prevParams' | ||
} | ||
}; | ||
|
||
let state = routerStateReducer(undefined, action); | ||
expect(state.toJS().currentState).to.equal('currentState'); | ||
expect(state.toJS().currentParams).to.equal('currentParams'); | ||
expect(state.toJS().prevState).to.equal('prevState'); | ||
expect(state.toJS().prevParams).to.equal('prevParams'); | ||
}); | ||
}); |
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,15 @@ | ||
import 'chai'; | ||
import stateChangeError from '../state-change-error'; | ||
|
||
describe('stateChangeError', () => { | ||
it('should create an action with the provided params', () => { | ||
let action = stateChangeError('evt', 'toState', 'toParams', 'fromState', 'fromParams', 'err'); | ||
|
||
expect(action.payload.toState).to.equal('toState'); | ||
expect(action.payload.toParams).to.equal('toParams'); | ||
expect(action.payload.fromState).to.equal('fromState'); | ||
expect(action.payload.fromParams).to.equal('fromParams'); | ||
expect(action.payload.err).to.equal('err'); | ||
expect(action.type).to.equal('@@reduxUiRouter/$stateChangeError'); | ||
}); | ||
}); |
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,14 @@ | ||
import 'chai'; | ||
import stateChangeStart from '../state-change-start'; | ||
|
||
describe('stateChangeStart', () => { | ||
it('should create an action with the provided params', () => { | ||
let action = stateChangeStart('evt', 'toState', 'toParams', 'fromState', 'fromParams'); | ||
|
||
expect(action.payload.toState).to.equal('toState'); | ||
expect(action.payload.toParams).to.equal('toParams'); | ||
expect(action.payload.fromState).to.equal('fromState'); | ||
expect(action.payload.fromParams).to.equal('fromParams'); | ||
expect(action.type).to.equal('@@reduxUiRouter/$stateChangeStart'); | ||
}); | ||
}); |
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,14 @@ | ||
import 'chai'; | ||
import stateChangeSuccess from '../state-change-success'; | ||
|
||
describe('stateChangeSuccess', () => { | ||
it('should create an action with the provided params', () => { | ||
let action = stateChangeSuccess('evt', 'currentState', 'currentParams', 'prevState', 'prevParams'); | ||
|
||
expect(action.payload.currentState).to.equal('currentState'); | ||
expect(action.payload.currentParams).to.equal('currentParams'); | ||
expect(action.payload.prevState).to.equal('prevState'); | ||
expect(action.payload.prevParams).to.equal('prevParams'); | ||
expect(action.type).to.equal('@@reduxUiRouter/$stateChangeSuccess'); | ||
}); | ||
}); |
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,20 @@ | ||
import 'chai'; | ||
import stateGo from '../state-go'; | ||
|
||
describe('stateGo', () => { | ||
it('should create an action containing the state to go to', () => { | ||
let action = stateGo('example', { test: 'hello' }, { option: 'world' }); | ||
expect(action.payload.to).to.equal('example'); | ||
expect(action.payload.params.test).to.equal('hello'); | ||
expect(action.payload.options.option).to.equal('world'); | ||
expect(action.type).to.equal('@@reduxUiRouter/stateGo'); | ||
}); | ||
|
||
it('should create an action when to params are undefined', () => { | ||
let action = stateGo('example', undefined, undefined); | ||
expect(action.payload.to).to.equal('example'); | ||
expect(action.payload.params).to.equal(undefined); | ||
expect(action.payload.options).to.equal(undefined); | ||
expect(action.type).to.equal('@@reduxUiRouter/stateGo'); | ||
}); | ||
}); |
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,85 @@ | ||
import 'chai'; | ||
import Q from 'q'; | ||
import sinon from 'sinon'; | ||
import 'sinon-as-promised'; | ||
import routerMiddleware from '../router-middleware'; | ||
|
||
import { | ||
STATE_GO, | ||
STATE_RELOAD, | ||
STATE_TRANSITION_TO | ||
} from '../action-types'; | ||
|
||
let $state; | ||
let nextSpy; | ||
|
||
describe('routerMiddleware', () => { | ||
beforeEach(() => { | ||
$state = { | ||
go: () => {}, | ||
reload: () => {}, | ||
transitionTo: () => {} | ||
}; | ||
|
||
$state.go = sinon.stub().resolves('foo'); | ||
$state.reload = sinon.stub().resolves('foo'); | ||
$state.transitionTo = sinon.stub().resolves('foo'); | ||
|
||
nextSpy = sinon.stub(); | ||
}); | ||
|
||
it('should call the next action if the router middleware doesn\'t care about it', () => { | ||
let middleware = routerMiddleware($state)({})(nextSpy); | ||
|
||
middleware({ | ||
payload: {} | ||
}); | ||
|
||
expect(nextSpy.called).to.equal(true); | ||
expect($state.go.called).to.equal(false); | ||
expect($state.reload.called).to.equal(false); | ||
expect($state.transitionTo.called).to.equal(false); | ||
}); | ||
|
||
it('should call $state.go if the STATE_GO action is sent', () => { | ||
let middleware = routerMiddleware($state)({})(nextSpy); | ||
|
||
middleware({ | ||
type: STATE_GO, | ||
payload: {} | ||
}); | ||
|
||
expect(nextSpy.called).to.equal(true); | ||
expect($state.go.called).to.equal(true); | ||
expect($state.reload.called).to.equal(false); | ||
expect($state.transitionTo.called).to.equal(false); | ||
}); | ||
|
||
it('should call $state.reload if the STATE_GO action is sent', () => { | ||
let middleware = routerMiddleware($state)({})(nextSpy); | ||
|
||
middleware({ | ||
type: STATE_RELOAD, | ||
payload: {} | ||
}); | ||
|
||
expect(nextSpy.called).to.equal(true); | ||
expect($state.reload.called).to.equal(true); | ||
expect($state.go.called).to.equal(false); | ||
expect($state.transitionTo.called).to.equal(false); | ||
}); | ||
|
||
it('should call $state.transitionTo if the STATE_GO action is sent', () => { | ||
let middleware = routerMiddleware($state)({})(nextSpy); | ||
|
||
middleware({ | ||
type: STATE_TRANSITION_TO, | ||
payload: {} | ||
}); | ||
|
||
expect(nextSpy.called).to.equal(true); | ||
expect($state.transitionTo.called).to.equal(true); | ||
expect($state.go.called).to.equal(false); | ||
expect($state.reload.called).to.equal(false); | ||
}); | ||
}); |
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,14 @@ | ||
import 'chai'; | ||
import stateNotFound from '../state-not-found'; | ||
|
||
describe('stateNotFound', () => { | ||
it('should create an action with the provided params', () => { | ||
let action = stateNotFound('evt', 'unfoundState', 'fromState', 'fromParams'); | ||
|
||
expect(action.payload.evt).to.equal('evt'); | ||
expect(action.payload.unfoundState).to.equal('unfoundState'); | ||
expect(action.payload.fromState).to.equal('fromState'); | ||
expect(action.payload.fromParams).to.equal('fromParams'); | ||
expect(action.type).to.equal('@@reduxUiRouter/$stateNotFound'); | ||
}); | ||
}); |
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,10 @@ | ||
import 'chai'; | ||
import stateReload from '../state-reload'; | ||
|
||
describe('stateReload', () => { | ||
it('should create an action containing the state to reload', () => { | ||
let action = stateReload('example'); | ||
expect(action.payload).to.equal('example'); | ||
expect(action.type).to.equal('@@reduxUiRouter/stateReload'); | ||
}); | ||
}); |
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,20 @@ | ||
import 'chai'; | ||
import stateTransitionTo from '../state-transition-to'; | ||
|
||
describe('stateTransitionTo', () => { | ||
it('should create an action containing the state to transition to', () => { | ||
let action = stateTransitionTo('example', { test: 'hello' }, { option: 'world' }); | ||
expect(action.payload.to).to.equal('example'); | ||
expect(action.payload.toParams.test).to.equal('hello'); | ||
expect(action.payload.options.option).to.equal('world'); | ||
expect(action.type).to.equal('@@reduxUiRouter/transitionTo'); | ||
}); | ||
|
||
it('should create an action when to params are undefined', () => { | ||
let action = stateTransitionTo('example', undefined, undefined); | ||
expect(action.payload.to).to.equal('example'); | ||
expect(action.payload.toParams).to.equal(undefined); | ||
expect(action.payload.options).to.equal(undefined); | ||
expect(action.type).to.equal('@@reduxUiRouter/transitionTo'); | ||
}); | ||
}); |