mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-27 23:40:28 +05:30
#195: use replace state, when navigating to permissions from oauth entry point
This commit is contained in:
parent
8cd00a5c40
commit
5ed38e0716
@ -23,7 +23,12 @@ export default class AuthFlow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setStore(store) {
|
setStore(store) {
|
||||||
this.navigate = (route) => {
|
/**
|
||||||
|
* @param {string} route
|
||||||
|
* @param {object} options
|
||||||
|
* @param {object} options.replace
|
||||||
|
*/
|
||||||
|
this.navigate = (route, options = {}) => {
|
||||||
if (this.getRequest().path !== route) {
|
if (this.getRequest().path !== route) {
|
||||||
this.currentRequest = {
|
this.currentRequest = {
|
||||||
path: route
|
path: route
|
||||||
@ -32,7 +37,7 @@ export default class AuthFlow {
|
|||||||
if (this.replace) {
|
if (this.replace) {
|
||||||
this.replace(route);
|
this.replace(route);
|
||||||
}
|
}
|
||||||
store.dispatch(routeActions.push(route)); // TODO: may be deleted?
|
store.dispatch(routeActions[options.replace ? 'replace' : 'push'](route));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.replace = null;
|
this.replace = null;
|
||||||
|
@ -3,7 +3,11 @@ import CompleteState from './CompleteState';
|
|||||||
|
|
||||||
export default class PermissionsState extends AbstractState {
|
export default class PermissionsState extends AbstractState {
|
||||||
enter(context) {
|
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) {
|
resolve(context) {
|
||||||
|
@ -22,7 +22,25 @@ describe('PermissionsState', () => {
|
|||||||
|
|
||||||
describe('#enter', () => {
|
describe('#enter', () => {
|
||||||
it('should navigate to /oauth/permissions', () => {
|
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);
|
state.enter(context);
|
||||||
});
|
});
|
||||||
|
@ -25,8 +25,12 @@ export function expectState(mock, state) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function expectNavigate(mock, route) {
|
export function expectNavigate(mock, route, options) {
|
||||||
return mock.expects('navigate').once().withExactArgs(route);
|
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) {
|
export function expectRun(mock, ...args) {
|
||||||
|
Loading…
Reference in New Issue
Block a user