Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
fix(oauth): ensure oauth forms are enabled if valid on afterRender
Browse files Browse the repository at this point in the history
  • Loading branch information
zaach committed Jun 27, 2014
1 parent 85853c3 commit f46e435
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
5 changes: 4 additions & 1 deletion app/scripts/views/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ function (_, $, p, Validate, AuthErrors, BaseView, Tooltip, ButtonProgressIndica
return self.invokeHandler(handler, args);
})
.then(function (value) {
self._buttonProgressIndicator.done();
// Stop the progress indicator unless the page is navigating
if (!value || !value.pageNavigation) {
self._buttonProgressIndicator.done();
}
return value;
}, function(err) {
self._buttonProgressIndicator.done();
Expand Down
1 change: 1 addition & 0 deletions app/scripts/views/mixins/oauth-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ define([
Session.clear('oauth');
// Redirect to the returned URL
self.window.location.href = result.redirect;
return { pageNavigation: true };
})
.fail(function(xhr) {
Session.clear('oauth');
Expand Down
7 changes: 6 additions & 1 deletion app/scripts/views/oauth_sign_in.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ function (_, p, SignInView, Session, OAuthMixin) {
},

beforeRender: function() {
return this.setServiceInfo();
var self = this;
return p().then(function () {
return SignInView.prototype.beforeRender.call(self);
})
.then(_.bind(this.setServiceInfo, this));
},

afterRender: function() {
this.setupOAuthLinks();
return SignInView.prototype.afterRender.call(this);
},

onSignInSuccess: function() {
Expand Down
14 changes: 10 additions & 4 deletions app/scripts/views/oauth_sign_up.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

define([
'underscore',
'p-promise',
'views/base',
'views/sign_up',
'lib/session',
'views/mixins/oauth-mixin'
],
function (_, BaseView, SignUpView, Session, OAuthMixin) {
function (_, p, BaseView, SignUpView, Session, OAuthMixin) {
var View = SignUpView.extend({
className: 'sign-up oauth-sign-up',

Expand All @@ -23,12 +24,17 @@ function (_, BaseView, SignUpView, Session, OAuthMixin) {
this.setupOAuth();
},

beforeRender: function () {
return this.setServiceInfo();
beforeRender: function() {
var self = this;
return p().then(function () {
return SignUpView.prototype.beforeRender.call(self);
})
.then(_.bind(this.setServiceInfo, this));
},

afterRender: function() {
this.$('.sign-in').attr('href', '/oauth/signin');
this.setupOAuthLinks();
return SignUpView.prototype.afterRender.call(this);
},

onSignUpSuccess: function () {
Expand Down
13 changes: 11 additions & 2 deletions app/tests/spec/views/oauth_sign_in.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ function (chai, $, View, Session, FxaClient, WindowMock, RouterMock, TestHelpers
assert.equal($('.sign-up').attr('href'), '/oauth/signup');
});
});

it('is enabled if prefills are valid', function () {
Session.set('prefillEmail', 'testuser@testuser.com');
Session.set('prefillPassword', 'prefilled password');
return view.render()
.then(function () {
assert.isFalse(view.$('button').hasClass('disabled'));
});
});
});

describe('submit', function () {
Expand All @@ -74,7 +83,7 @@ function (chai, $, View, Session, FxaClient, WindowMock, RouterMock, TestHelpers
});

describe('resetPasswordIfKnownValidEmail', function () {
it('goes to the confirm_reset_password page if user types a valid, known email', function () {
it('goes to the reset_password page if user types a valid, known email', function () {
var password = 'password';
return view.fxaClient.signUp(email, password, { preVerified: true })
.then(function () {
Expand All @@ -83,7 +92,7 @@ function (chai, $, View, Session, FxaClient, WindowMock, RouterMock, TestHelpers
})
.then(function () {
assert.ok(Session.oauth, 'oauth params are set');
assert.equal(router.page, 'confirm_reset_password');
assert.equal(router.page, 'reset_password');
});
});

Expand Down

0 comments on commit f46e435

Please sign in to comment.