Fix bug with infinite loader, when page refreshed on /login with oauth state restoration active

This commit is contained in:
SleepWalker 2016-10-25 09:32:50 +03:00
parent abf5fbbef6
commit 28ce3e4b70
3 changed files with 15 additions and 5 deletions

View File

@ -89,9 +89,9 @@ function restoreScroll() {
/* global process: false */ /* global process: false */
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
// some shortcuts for testing on localhost // some shortcuts for testing on localhost
window.testOAuth = () => location.href = '/oauth2/v1/ely?client_id=ely&redirect_uri=http%3A%2F%2Fely.by&response_type=code&scope=minecraft_server_session'; window.testOAuth = () => location.href = '/oauth2/v1/ely?client_id=ely&redirect_uri=http%3A%2F%2Fely.by%2Fauthorization%2Foauth&response_type=code&scope=account_info%2Caccount_email';
window.testOAuthStatic = () => location.href = '/oauth2/v1/ely?client_id=ely&redirect_uri=static_page_with_code&response_type=code&scope=minecraft_server_session'; window.testOAuthStatic = () => location.href = '/oauth2/v1/ely?client_id=ely&redirect_uri=static_page_with_code&response_type=code&scope=account_info%2Caccount_email';
window.testOAuthStaticCode = () => location.href = '/oauth2/v1/ely?client_id=ely&redirect_uri=static_page&response_type=code&scope=minecraft_server_session'; window.testOAuthStaticCode = () => location.href = '/oauth2/v1/ely?client_id=ely&redirect_uri=static_page&response_type=code&scope=account_info%2Caccount_email';
// expose Perf // expose Perf
window.Perf = require('react-addons-perf'); window.Perf = require('react-addons-perf');

View File

@ -202,7 +202,8 @@ export default class AuthFlow {
if (Date.now() - data.timestamp < expirationTime) { if (Date.now() - data.timestamp < expirationTime) {
this.run('oAuthValidate', data.payload) this.run('oAuthValidate', data.payload)
.then(() => this.setState(new CompleteState())); .then(() => this.setState(new CompleteState()))
.then(() => this.onReady());
return true; return true;
} }

View File

@ -58,7 +58,8 @@ describe('AuthFlow', () => {
})); }));
sinon.stub(flow, 'run').named('flow.run'); sinon.stub(flow, 'run').named('flow.run');
flow.run.returns({then: (fn) => fn()}); const promiseLike = {then: (fn) => fn() || promiseLike};
flow.run.returns(promiseLike);
sinon.stub(flow, 'setState').named('flow.setState'); sinon.stub(flow, 'setState').named('flow.setState');
}); });
@ -96,6 +97,14 @@ describe('AuthFlow', () => {
expect(flow.setState, 'was called once'); expect(flow.setState, 'was called once');
}); });
it('should call onReady after state restoration', () => {
const onReady = sinon.stub().named('onReady');
flow.handleRequest({path: '/login'}, null, onReady);
expect(onReady, 'was called');
});
it('should not restore oauth state for /register route', () => { it('should not restore oauth state for /register route', () => {
flow.handleRequest({path: '/register'}); flow.handleRequest({path: '/register'});