fix(signin): redirect to signin if bounced screen has no email

https://github.com/mozilla/fxa-content-server/pull/5339
r=shane-tomlinson
This commit is contained in:
Phil Booth 2017-08-04 10:00:01 +01:00 коммит произвёл GitHub
Родитель 745b1dcf2d
Коммит 4e03b36ed7
3 изменённых файлов: 41 добавлений и 0 удалений

Просмотреть файл

@ -26,6 +26,15 @@ define(function (require, exports, module) {
this._formPrefill = options.formPrefill;
},
beforeRender () {
if (! this.model.has('email')) {
// This may occur if the user has refreshed the page. In that case,
// we have no context for properly rendering the view, so kick them
// out to /signin where they can start again.
this.navigate('signin');
}
},
setInitialContext (context) {
context.set({
email: this.model.get('email'),

Просмотреть файл

@ -33,6 +33,31 @@ define((require, exports, module) => {
assert.strictEqual(view.template, template);
});
describe('beforeRender', () => {
beforeEach(() => {
view.navigate = sinon.spy();
view.beforeRender();
});
it('did not call navigate', () => {
assert.equal(view.navigate.callCount, 0);
});
});
describe('beforeRender, this.model.has(\'email\') === false', () => {
beforeEach(() => {
model.unset('email');
view.navigate = sinon.spy();
view.beforeRender();
});
it('called navigate correctly', () => {
assert.equal(view.navigate.callCount, 1);
assert.lengthOf(view.navigate.args[0], 1);
assert.equal(view.navigate.args[0][0], 'signin');
});
});
describe('setInitialContext', () => {
let context;

Просмотреть файл

@ -154,6 +154,13 @@ define([
.then(switchToWindow(1))
.then(pollUntil(() => window.location.href.startsWith('https://support.mozilla.org/')))
.then(closeCurrentWindow());
},
'refresh': function () {
return this.remote
.then(setUpBouncedSignIn())
.refresh()
.then(testElementExists(selectors.SIGNIN.HEADER));
}
});
});