#195: use replace state, when navigating to permissions from oauth entry point

This commit is contained in:
SleepWalker 2016-08-27 17:36:33 +03:00
parent 8cd00a5c40
commit 5ed38e0716
4 changed files with 37 additions and 6 deletions

View File

@ -23,7 +23,12 @@ export default class AuthFlow {
}
setStore(store) {
this.navigate = (route) => {
/**
* @param {string} route
* @param {object} options
* @param {object} options.replace
*/
this.navigate = (route, options = {}) => {
if (this.getRequest().path !== route) {
this.currentRequest = {
path: route
@ -32,7 +37,7 @@ export default class AuthFlow {
if (this.replace) {
this.replace(route);
}
store.dispatch(routeActions.push(route)); // TODO: may be deleted?
store.dispatch(routeActions[options.replace ? 'replace' : 'push'](route));
}
this.replace = null;

View File

@ -3,7 +3,11 @@ import CompleteState from './CompleteState';
export default class PermissionsState extends AbstractState {
enter(context) {
context.navigate('/oauth/permissions');
context.navigate('/oauth/permissions', {
// replacing oauth entry point if currently on it
// to allow user easy go-back action to client's site
replace: context.getRequest().path.includes('oauth2')
});
}
resolve(context) {

View File

@ -22,7 +22,25 @@ describe('PermissionsState', () => {
describe('#enter', () => {
it('should navigate to /oauth/permissions', () => {
expectNavigate(mock, '/oauth/permissions');
context.getRequest.returns({
path: '/'
});
expectNavigate(mock, '/oauth/permissions', {
replace: false
});
state.enter(context);
});
it('should replace instead of push if current request contains oauth2', () => {
context.getRequest.returns({
path: '/oauth2'
});
expectNavigate(mock, '/oauth/permissions', {
replace: true
});
state.enter(context);
});

View File

@ -25,8 +25,12 @@ export function expectState(mock, state) {
);
}
export function expectNavigate(mock, route) {
return mock.expects('navigate').once().withExactArgs(route);
export function expectNavigate(mock, route, options) {
if (options) {
return mock.expects('navigate').once().withExactArgs(route, sinon.match(options));
} else {
return mock.expects('navigate').once().withExactArgs(route);
}
}
export function expectRun(mock, ...args) {