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

Commit

Permalink
feat(client): Add email prefil on the /signup page if an email is p…
Browse files Browse the repository at this point in the history
…assed as a URL search parameter

fixes #1285
  • Loading branch information
Shane Tomlinson committed Jun 25, 2014
1 parent 8c0e091 commit af7ad38
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
15 changes: 10 additions & 5 deletions app/scripts/views/sign_up.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ define([
'stache!templates/sign_up',
'lib/session',
'views/mixins/password-mixin',
'lib/auth-errors'
'lib/auth-errors',
'lib/url'
],
function (_, BaseView, FormView, Template, Session, PasswordMixin, AuthErrors) {
function (_, BaseView, FormView, Template, Session, PasswordMixin, AuthErrors, Url) {
var t = BaseView.t;

function selectAutoFocusEl(email, password) {
Expand Down Expand Up @@ -80,12 +81,16 @@ function (_, BaseView, FormView, Template, Session, PasswordMixin, AuthErrors) {
},

context: function () {
var autofocusEl = selectAutoFocusEl(Session.prefillEmail,
Session.prefillPassword);
// Session.prefillEmail comes first because users can edit the email,
// go to another screen, edit the email again, and come back here. We
// want the last used email.
var email = Session.prefillEmail || Url.searchParam('email', this.window.location.search);

var autofocusEl = selectAutoFocusEl(email, Session.prefillPassword);

return {
serviceName: this.serviceName,
email: Session.prefillEmail,
email: email,
password: Session.prefillPassword,
year: Session.prefillYear || 'none',
service: Session.service,
Expand Down
21 changes: 18 additions & 3 deletions app/tests/spec/views/sign_up.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ define([
'lib/auth-errors',
'lib/metrics',
'../../mocks/router',
'../../mocks/window',
'../../lib/helpers'
],
function (chai, _, $, p, View, Session, AuthErrors, Metrics, RouterMock, TestHelpers) {
function (chai, _, $, p, View, Session, AuthErrors, Metrics, RouterMock, WindowMock, TestHelpers) {
var assert = chai.assert;
var wrapAssertion = TestHelpers.wrapAssertion;

Expand All @@ -39,17 +40,21 @@ function (chai, _, $, p, View, Session, AuthErrors, Metrics, RouterMock, TestHel
}

describe('views/sign_up', function () {
var view, router, email, metrics;
var view, router, email, metrics, windowMock;

beforeEach(function () {
Session.clear();

email = 'testuser.' + Math.random() + '@testuser.com';
document.cookie = 'tooyoung=1; expires=Thu, 01-Jan-1970 00:00:01 GMT';
router = new RouterMock();
windowMock = new WindowMock();
metrics = new Metrics();

view = new View({
router: router,
metrics: metrics
metrics: metrics,
window: windowMock
});
return view.render()
.then(function () {
Expand Down Expand Up @@ -82,6 +87,16 @@ function (chai, _, $, p, View, Session, AuthErrors, Metrics, RouterMock, TestHel
});
});

it('prefills email with email from search parameter if Session.prefillEmail is not set', function () {
windowMock.location.search = '?email=' + encodeURIComponent('testuser@testuser.com');

return view.render()
.then(function () {
assert.ok($('#fxa-signup-header').length);
assert.equal(view.$('[type=email]').val(), 'testuser@testuser.com');
});
});

it('shows choose what to sync checkbox when service is sync even after session is cleared', function () {
Session.set('service', 'sync');
Session.clear();
Expand Down

0 comments on commit af7ad38

Please sign in to comment.