chore(sms): Fix the spacing in the sms_send test. (#5618) r=@shane-tomlinson
There was one too many spaces at the beginning of each line. `?w=1` says `Whitespace-only changes.`. Self merge.
This commit is contained in:
Родитель
8805aa6cd7
Коммит
15e20a7362
|
@ -2,349 +2,349 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
define((require, exports, module) => {
|
||||
'use strict';
|
||||
define((require, exports, module) => {
|
||||
'use strict';
|
||||
|
||||
const $ = require('jquery');
|
||||
const { assert } = require('chai');
|
||||
const Account = require('models/account');
|
||||
const AuthErrors = require('lib/auth-errors');
|
||||
const Broker = require('models/auth_brokers/base');
|
||||
const Backbone = require('backbone');
|
||||
const Metrics = require('lib/metrics');
|
||||
const Notifier = require('lib/channels/notifier');
|
||||
const p = require('lib/promise');
|
||||
const Relier = require('models/reliers/relier');
|
||||
const sinon = require('sinon');
|
||||
const SmsErrors = require('lib/sms-errors');
|
||||
const SmsMessageIds = require('lib/sms-message-ids');
|
||||
const View = require('views/sms_send');
|
||||
const $ = require('jquery');
|
||||
const { assert } = require('chai');
|
||||
const Account = require('models/account');
|
||||
const AuthErrors = require('lib/auth-errors');
|
||||
const Broker = require('models/auth_brokers/base');
|
||||
const Backbone = require('backbone');
|
||||
const Metrics = require('lib/metrics');
|
||||
const Notifier = require('lib/channels/notifier');
|
||||
const p = require('lib/promise');
|
||||
const Relier = require('models/reliers/relier');
|
||||
const sinon = require('sinon');
|
||||
const SmsErrors = require('lib/sms-errors');
|
||||
const SmsMessageIds = require('lib/sms-message-ids');
|
||||
const View = require('views/sms_send');
|
||||
|
||||
describe('views/sms_send', () => {
|
||||
let account;
|
||||
let broker;
|
||||
let formPrefill;
|
||||
let metrics;
|
||||
let model;
|
||||
let notifier;
|
||||
let relier;
|
||||
let view;
|
||||
describe('views/sms_send', () => {
|
||||
let account;
|
||||
let broker;
|
||||
let formPrefill;
|
||||
let metrics;
|
||||
let model;
|
||||
let notifier;
|
||||
let relier;
|
||||
let view;
|
||||
|
||||
function createView() {
|
||||
view = new View({
|
||||
broker,
|
||||
formPrefill,
|
||||
metrics,
|
||||
model,
|
||||
notifier,
|
||||
relier,
|
||||
viewName: 'sms-send'
|
||||
});
|
||||
sinon.stub(view, 'checkAuthorization').callsFake(() => p(true));
|
||||
}
|
||||
function createView() {
|
||||
view = new View({
|
||||
broker,
|
||||
formPrefill,
|
||||
metrics,
|
||||
model,
|
||||
notifier,
|
||||
relier,
|
||||
viewName: 'sms-send'
|
||||
});
|
||||
sinon.stub(view, 'checkAuthorization').callsFake(() => p(true));
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
account = new Account({ sessionToken: 'token' });
|
||||
broker = new Broker();
|
||||
formPrefill = new Backbone.Model({});
|
||||
metrics = new Metrics();
|
||||
model = new Backbone.Model({ account });
|
||||
notifier = new Notifier();
|
||||
relier = new Relier({ service: 'sync' });
|
||||
beforeEach(() => {
|
||||
account = new Account({ sessionToken: 'token' });
|
||||
broker = new Broker();
|
||||
formPrefill = new Backbone.Model({});
|
||||
metrics = new Metrics();
|
||||
model = new Backbone.Model({ account });
|
||||
notifier = new Notifier();
|
||||
relier = new Relier({ service: 'sync' });
|
||||
|
||||
createView();
|
||||
createView();
|
||||
|
||||
return view.render();
|
||||
});
|
||||
return view.render();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
metrics.destroy();
|
||||
metrics = null;
|
||||
afterEach(() => {
|
||||
metrics.destroy();
|
||||
metrics = null;
|
||||
|
||||
view.destroy(true);
|
||||
view = null;
|
||||
});
|
||||
view.destroy(true);
|
||||
view = null;
|
||||
});
|
||||
|
||||
describe('render', () => {
|
||||
it('with default country, it renders correctly for country, renders marketing', () => {
|
||||
assert.equal(view.$('input[type=tel]').__val(), '');
|
||||
assert.equal(view.$('input[type=tel]').data('country'), 'US');
|
||||
assert.lengthOf(view.$('.marketing-link'), 2);
|
||||
describe('render', () => {
|
||||
it('with default country, it renders correctly for country, renders marketing', () => {
|
||||
assert.equal(view.$('input[type=tel]').__val(), '');
|
||||
assert.equal(view.$('input[type=tel]').data('country'), 'US');
|
||||
assert.lengthOf(view.$('.marketing-link'), 2);
|
||||
|
||||
// ensure clicks on the marketing links work as expected.
|
||||
sinon.spy(metrics, 'logMarketingClick');
|
||||
sinon.spy(view, 'logFlowEvent');
|
||||
$('#container').html(view.$el);
|
||||
// ensure clicks on the marketing links work as expected.
|
||||
sinon.spy(metrics, 'logMarketingClick');
|
||||
sinon.spy(view, 'logFlowEvent');
|
||||
$('#container').html(view.$el);
|
||||
|
||||
view.$('.marketing-link-ios').click();
|
||||
assert.isTrue(metrics.logMarketingClick.calledOnce);
|
||||
assert.equal(metrics.logMarketingClick.args[0][0], 'autumn-2016-connect-another-device');
|
||||
assert.isTrue(view.logFlowEvent.calledOnce);
|
||||
assert.isTrue(view.logFlowEvent.calledWith('link.app-store.ios', 'sms-send'));
|
||||
view.$('.marketing-link-ios').click();
|
||||
assert.isTrue(metrics.logMarketingClick.calledOnce);
|
||||
assert.equal(metrics.logMarketingClick.args[0][0], 'autumn-2016-connect-another-device');
|
||||
assert.isTrue(view.logFlowEvent.calledOnce);
|
||||
assert.isTrue(view.logFlowEvent.calledWith('link.app-store.ios', 'sms-send'));
|
||||
|
||||
view.$('.marketing-link-android').click();
|
||||
assert.isTrue(metrics.logMarketingClick.calledTwice);
|
||||
assert.equal(metrics.logMarketingClick.args[1][0], 'autumn-2016-connect-another-device');
|
||||
assert.isTrue(view.logFlowEvent.calledTwice);
|
||||
assert.isTrue(view.logFlowEvent.calledWith('link.app-store.android', 'sms-send'));
|
||||
});
|
||||
view.$('.marketing-link-android').click();
|
||||
assert.isTrue(metrics.logMarketingClick.calledTwice);
|
||||
assert.equal(metrics.logMarketingClick.args[1][0], 'autumn-2016-connect-another-device');
|
||||
assert.isTrue(view.logFlowEvent.calledTwice);
|
||||
assert.isTrue(view.logFlowEvent.calledWith('link.app-store.android', 'sms-send'));
|
||||
});
|
||||
|
||||
it('with model set country, it renders correctly for country', () => {
|
||||
formPrefill.unset('phoneNumber');
|
||||
model.set('country', 'RO');
|
||||
it('with model set country, it renders correctly for country', () => {
|
||||
formPrefill.unset('phoneNumber');
|
||||
model.set('country', 'RO');
|
||||
|
||||
return view.render()
|
||||
.then(() => {
|
||||
assert.equal(view.$('input[type=tel]').__val(), '+407');
|
||||
assert.equal(view.$('input[type=tel]').data('country'), 'RO');
|
||||
});
|
||||
});
|
||||
return view.render()
|
||||
.then(() => {
|
||||
assert.equal(view.$('input[type=tel]').__val(), '+407');
|
||||
assert.equal(view.$('input[type=tel]').data('country'), 'RO');
|
||||
});
|
||||
});
|
||||
|
||||
it('with relier set country, it renders correctly for country', () => {
|
||||
formPrefill.unset('phoneNumber');
|
||||
relier.set('country', 'GB');
|
||||
it('with relier set country, it renders correctly for country', () => {
|
||||
formPrefill.unset('phoneNumber');
|
||||
relier.set('country', 'GB');
|
||||
|
||||
return view.render()
|
||||
.then(() => {
|
||||
assert.equal(view.$('input[type=tel]').__val(), '+44');
|
||||
assert.equal(view.$('input[type=tel]').data('country'), 'GB');
|
||||
});
|
||||
});
|
||||
return view.render()
|
||||
.then(() => {
|
||||
assert.equal(view.$('input[type=tel]').__val(), '+44');
|
||||
assert.equal(view.$('input[type=tel]').data('country'), 'GB');
|
||||
});
|
||||
});
|
||||
|
||||
it('with relier set country that is not supported, it renders correctly for the US/CA, renders marketing', () => {
|
||||
formPrefill.unset('phoneNumber');
|
||||
relier.set('country', 'KZ');
|
||||
it('with relier set country that is not supported, it renders correctly for the US/CA, renders marketing', () => {
|
||||
formPrefill.unset('phoneNumber');
|
||||
relier.set('country', 'KZ');
|
||||
|
||||
return view.render()
|
||||
.then(() => {
|
||||
assert.equal(view.$('input[type=tel]').__val(), '');
|
||||
assert.equal(view.$('input[type=tel]').data('country'), 'US');
|
||||
assert.lengthOf(view.$('.marketing-link'), 2);
|
||||
});
|
||||
});
|
||||
return view.render()
|
||||
.then(() => {
|
||||
assert.equal(view.$('input[type=tel]').__val(), '');
|
||||
assert.equal(view.$('input[type=tel]').data('country'), 'US');
|
||||
assert.lengthOf(view.$('.marketing-link'), 2);
|
||||
});
|
||||
});
|
||||
|
||||
it('with no relier set country, it renders correctly for the US/CA', () => {
|
||||
formPrefill.unset('phoneNumber');
|
||||
relier.unset('country');
|
||||
return view.render()
|
||||
.then(() => {
|
||||
assert.equal(view.$('input[type=tel]').__val(), '');
|
||||
assert.equal(view.$('input[type=tel]').data('country'), 'US');
|
||||
assert.lengthOf(view.$('.marketing-link'), 2);
|
||||
});
|
||||
});
|
||||
it('with no relier set country, it renders correctly for the US/CA', () => {
|
||||
formPrefill.unset('phoneNumber');
|
||||
relier.unset('country');
|
||||
return view.render()
|
||||
.then(() => {
|
||||
assert.equal(view.$('input[type=tel]').__val(), '');
|
||||
assert.equal(view.$('input[type=tel]').data('country'), 'US');
|
||||
assert.lengthOf(view.$('.marketing-link'), 2);
|
||||
});
|
||||
});
|
||||
|
||||
it('for signin, renders extra text', () => {
|
||||
sinon.stub(view, 'isSignIn').callsFake(() => true);
|
||||
return view.render()
|
||||
.then(() => {
|
||||
assert.include(view.$('.send-sms > p').text().toLowerCase(), 'still adding devices');
|
||||
});
|
||||
});
|
||||
});
|
||||
it('for signin, renders extra text', () => {
|
||||
sinon.stub(view, 'isSignIn').callsFake(() => true);
|
||||
return view.render()
|
||||
.then(() => {
|
||||
assert.include(view.$('.send-sms > p').text().toLowerCase(), 'still adding devices');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('submit', () => {
|
||||
describe('succeeds', () => {
|
||||
it('it delegates to `account.sendSms`, calls `_onSendSmsSuccess`', () => {
|
||||
sinon.stub(account, 'sendSms').callsFake(() => p());
|
||||
sinon.spy(view, '_onSendSmsSuccess');
|
||||
sinon.stub(view, 'getSmsFeatures').callsFake(() => ['signinCodes']);
|
||||
view.$('input[type=tel]').val('1234567890');
|
||||
describe('submit', () => {
|
||||
describe('succeeds', () => {
|
||||
it('it delegates to `account.sendSms`, calls `_onSendSmsSuccess`', () => {
|
||||
sinon.stub(account, 'sendSms').callsFake(() => p());
|
||||
sinon.spy(view, '_onSendSmsSuccess');
|
||||
sinon.stub(view, 'getSmsFeatures').callsFake(() => ['signinCodes']);
|
||||
view.$('input[type=tel]').val('1234567890');
|
||||
|
||||
return view.submit()
|
||||
.then(() => {
|
||||
assert.isTrue(account.sendSms.calledOnce);
|
||||
assert.isTrue(account.sendSms.calledWith('+11234567890', SmsMessageIds.FIREFOX_MOBILE_INSTALL, {
|
||||
features: ['signinCodes']
|
||||
}));
|
||||
return view.submit()
|
||||
.then(() => {
|
||||
assert.isTrue(account.sendSms.calledOnce);
|
||||
assert.isTrue(account.sendSms.calledWith('+11234567890', SmsMessageIds.FIREFOX_MOBILE_INSTALL, {
|
||||
features: ['signinCodes']
|
||||
}));
|
||||
|
||||
assert.isTrue(view.getSmsFeatures.calledOnce);
|
||||
assert.isTrue(view._onSendSmsSuccess.calledOnce);
|
||||
});
|
||||
});
|
||||
});
|
||||
assert.isTrue(view.getSmsFeatures.calledOnce);
|
||||
assert.isTrue(view._onSendSmsSuccess.calledOnce);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('errors', () => {
|
||||
it('it delegates to `account.sendSms`, calls `_onSendSmsError` with the error', () => {
|
||||
const err = AuthErrors.toError('UNEXPECTED ERROR');
|
||||
sinon.stub(account, 'sendSms').callsFake(() => p.reject(err));
|
||||
sinon.spy(view, '_onSendSmsError');
|
||||
view.$('input[type=tel]').val('1234567890');
|
||||
describe('errors', () => {
|
||||
it('it delegates to `account.sendSms`, calls `_onSendSmsError` with the error', () => {
|
||||
const err = AuthErrors.toError('UNEXPECTED ERROR');
|
||||
sinon.stub(account, 'sendSms').callsFake(() => p.reject(err));
|
||||
sinon.spy(view, '_onSendSmsError');
|
||||
view.$('input[type=tel]').val('1234567890');
|
||||
|
||||
return view.submit()
|
||||
.then(assert.fail, (_err) => {
|
||||
assert.strictEqual(_err, err);
|
||||
assert.isTrue(account.sendSms.calledOnce);
|
||||
assert.isTrue(account.sendSms.calledWith('+11234567890', SmsMessageIds.FIREFOX_MOBILE_INSTALL));
|
||||
assert.isTrue(view._onSendSmsError.calledOnce);
|
||||
assert.isTrue(view._onSendSmsError.calledWith(err));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
return view.submit()
|
||||
.then(assert.fail, (_err) => {
|
||||
assert.strictEqual(_err, err);
|
||||
assert.isTrue(account.sendSms.calledOnce);
|
||||
assert.isTrue(account.sendSms.calledWith('+11234567890', SmsMessageIds.FIREFOX_MOBILE_INSTALL));
|
||||
assert.isTrue(view._onSendSmsError.calledOnce);
|
||||
assert.isTrue(view._onSendSmsError.calledWith(err));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('_onSendSmsSuccess', () => {
|
||||
it('navigates to `sms/sent`', () => {
|
||||
sinon.spy(view, 'navigate');
|
||||
view.$('input[type=tel]').val('1234567890');
|
||||
describe('_onSendSmsSuccess', () => {
|
||||
it('navigates to `sms/sent`', () => {
|
||||
sinon.spy(view, 'navigate');
|
||||
view.$('input[type=tel]').val('1234567890');
|
||||
|
||||
view._onSendSmsSuccess();
|
||||
view._onSendSmsSuccess();
|
||||
|
||||
assert.isTrue(view.navigate.calledOnce);
|
||||
assert.isTrue(view.navigate.calledWith('sms/sent'));
|
||||
const navigateOptions = view.navigate.args[0][1];
|
||||
assert.equal(navigateOptions.country, 'US');
|
||||
assert.equal(navigateOptions.normalizedPhoneNumber, '+11234567890');
|
||||
assert.instanceOf(navigateOptions.account, Account);
|
||||
});
|
||||
});
|
||||
assert.isTrue(view.navigate.calledOnce);
|
||||
assert.isTrue(view.navigate.calledWith('sms/sent'));
|
||||
const navigateOptions = view.navigate.args[0][1];
|
||||
assert.equal(navigateOptions.country, 'US');
|
||||
assert.equal(navigateOptions.normalizedPhoneNumber, '+11234567890');
|
||||
assert.instanceOf(navigateOptions.account, Account);
|
||||
});
|
||||
});
|
||||
|
||||
describe('_onSendSmsError', () => {
|
||||
beforeEach(() => {
|
||||
sinon.spy(view, 'showValidationError');
|
||||
});
|
||||
describe('_onSendSmsError', () => {
|
||||
beforeEach(() => {
|
||||
sinon.spy(view, 'showValidationError');
|
||||
});
|
||||
|
||||
function testPhoneNumberShowValidationError(err) {
|
||||
const $phoneNumberEl = view.$('input[type=tel]');
|
||||
view._onSendSmsError(err);
|
||||
assert.isTrue(view.showValidationError.calledWith($phoneNumberEl, err));
|
||||
}
|
||||
function testPhoneNumberShowValidationError(err) {
|
||||
const $phoneNumberEl = view.$('input[type=tel]');
|
||||
view._onSendSmsError(err);
|
||||
assert.isTrue(view.showValidationError.calledWith($phoneNumberEl, err));
|
||||
}
|
||||
|
||||
describe('fails with AuthErrors.INVALID_PHONE_NUMBER', () => {
|
||||
it('prints the validation error', () => {
|
||||
testPhoneNumberShowValidationError(AuthErrors.toError('INVALID_PHONE_NUMBER'));
|
||||
});
|
||||
});
|
||||
describe('fails with AuthErrors.INVALID_PHONE_NUMBER', () => {
|
||||
it('prints the validation error', () => {
|
||||
testPhoneNumberShowValidationError(AuthErrors.toError('INVALID_PHONE_NUMBER'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('fails with SmsErrors.INVALID_PHONE_NUMBER', () => {
|
||||
it('prints the validation error', () => {
|
||||
testPhoneNumberShowValidationError(SmsErrors.toError('INVALID_PHONE_NUMBER'));
|
||||
});
|
||||
});
|
||||
describe('fails with SmsErrors.INVALID_PHONE_NUMBER', () => {
|
||||
it('prints the validation error', () => {
|
||||
testPhoneNumberShowValidationError(SmsErrors.toError('INVALID_PHONE_NUMBER'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('fails with SmsErrors.UNROUTABLE_MESSAGE', () => {
|
||||
it('prints the validation error', () => {
|
||||
testPhoneNumberShowValidationError(SmsErrors.toError('UNROUTABLE_MESSAGE'));
|
||||
});
|
||||
});
|
||||
describe('fails with SmsErrors.UNROUTABLE_MESSAGE', () => {
|
||||
it('prints the validation error', () => {
|
||||
testPhoneNumberShowValidationError(SmsErrors.toError('UNROUTABLE_MESSAGE'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('fails with SmsErrors.NUMBER_BLOCKED', () => {
|
||||
it('prints the validation error', () => {
|
||||
testPhoneNumberShowValidationError(SmsErrors.toError('NUMBER_BLOCKED'));
|
||||
});
|
||||
});
|
||||
describe('fails with SmsErrors.NUMBER_BLOCKED', () => {
|
||||
it('prints the validation error', () => {
|
||||
testPhoneNumberShowValidationError(SmsErrors.toError('NUMBER_BLOCKED'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('all other errors', () => {
|
||||
it('propagates the error', () => {
|
||||
const err = AuthErrors.toError('UNEXPECTED_ERROR');
|
||||
assert.throws(() => {
|
||||
view._onSendSmsError(err);
|
||||
}, err);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('all other errors', () => {
|
||||
it('propagates the error', () => {
|
||||
const err = AuthErrors.toError('UNEXPECTED_ERROR');
|
||||
assert.throws(() => {
|
||||
view._onSendSmsError(err);
|
||||
}, err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('_getNormalizedPhoneNumber', () => {
|
||||
describe('with a US phone number', () => {
|
||||
beforeEach(() => {
|
||||
relier.set('country', 'US');
|
||||
});
|
||||
describe('_getNormalizedPhoneNumber', () => {
|
||||
describe('with a US phone number', () => {
|
||||
beforeEach(() => {
|
||||
relier.set('country', 'US');
|
||||
});
|
||||
|
||||
it('returns phone number with +1 prefix', () => {
|
||||
// no country code prefix
|
||||
view.$('input[type=tel]').val('1234567890');
|
||||
assert.equal(view._getNormalizedPhoneNumber(), '+11234567890');
|
||||
it('returns phone number with +1 prefix', () => {
|
||||
// no country code prefix
|
||||
view.$('input[type=tel]').val('1234567890');
|
||||
assert.equal(view._getNormalizedPhoneNumber(), '+11234567890');
|
||||
|
||||
// user entered country code prefix w/o +
|
||||
view.$('input[type=tel]').val('11234567890');
|
||||
assert.equal(view._getNormalizedPhoneNumber(), '+11234567890');
|
||||
// user entered country code prefix w/o +
|
||||
view.$('input[type=tel]').val('11234567890');
|
||||
assert.equal(view._getNormalizedPhoneNumber(), '+11234567890');
|
||||
|
||||
// user entered country code prefix w/ +1
|
||||
view.$('input[type=tel]').val('+11234567890');
|
||||
assert.equal(view._getNormalizedPhoneNumber(), '+11234567890');
|
||||
});
|
||||
});
|
||||
// user entered country code prefix w/ +1
|
||||
view.$('input[type=tel]').val('+11234567890');
|
||||
assert.equal(view._getNormalizedPhoneNumber(), '+11234567890');
|
||||
});
|
||||
});
|
||||
|
||||
describe('with a GB phone number', () => {
|
||||
beforeEach(() => {
|
||||
relier.set('country', 'GB');
|
||||
});
|
||||
describe('with a GB phone number', () => {
|
||||
beforeEach(() => {
|
||||
relier.set('country', 'GB');
|
||||
});
|
||||
|
||||
it('returns phone number with +44 prefix', () => {
|
||||
// prefix is pre-filled in form
|
||||
view.$('input[type=tel]').val('+441234567890');
|
||||
assert.equal(view._getNormalizedPhoneNumber(), '+441234567890');
|
||||
it('returns phone number with +44 prefix', () => {
|
||||
// prefix is pre-filled in form
|
||||
view.$('input[type=tel]').val('+441234567890');
|
||||
assert.equal(view._getNormalizedPhoneNumber(), '+441234567890');
|
||||
|
||||
// prefix is not pre-filled in form
|
||||
view.$('input[type=tel]').val('1234567890');
|
||||
assert.equal(view._getNormalizedPhoneNumber(), '+441234567890');
|
||||
});
|
||||
});
|
||||
// prefix is not pre-filled in form
|
||||
view.$('input[type=tel]').val('1234567890');
|
||||
assert.equal(view._getNormalizedPhoneNumber(), '+441234567890');
|
||||
});
|
||||
});
|
||||
|
||||
describe('with a RO phone number', () => {
|
||||
beforeEach(() => {
|
||||
relier.set('country', 'RO');
|
||||
});
|
||||
describe('with a RO phone number', () => {
|
||||
beforeEach(() => {
|
||||
relier.set('country', 'RO');
|
||||
});
|
||||
|
||||
it('returns phone number with +40 prefix', () => {
|
||||
// prefix is pre-filled in form
|
||||
view.$('input[type=tel]').val('+401234567890');
|
||||
assert.equal(view._getNormalizedPhoneNumber(), '+401234567890');
|
||||
it('returns phone number with +40 prefix', () => {
|
||||
// prefix is pre-filled in form
|
||||
view.$('input[type=tel]').val('+401234567890');
|
||||
assert.equal(view._getNormalizedPhoneNumber(), '+401234567890');
|
||||
|
||||
// prefix is not pre-filled in form
|
||||
view.$('input[type=tel]').val('1234567890');
|
||||
assert.equal(view._getNormalizedPhoneNumber(), '+401234567890');
|
||||
});
|
||||
});
|
||||
});
|
||||
// prefix is not pre-filled in form
|
||||
view.$('input[type=tel]').val('1234567890');
|
||||
assert.equal(view._getNormalizedPhoneNumber(), '+401234567890');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('flow events', () => {
|
||||
beforeEach(() => {
|
||||
sinon.spy(view, 'logFlowEvent');
|
||||
sinon.spy(view, 'logFlowEventOnce');
|
||||
sinon.stub(view, 'navigate').callsFake(() => {});
|
||||
});
|
||||
describe('flow events', () => {
|
||||
beforeEach(() => {
|
||||
sinon.spy(view, 'logFlowEvent');
|
||||
sinon.spy(view, 'logFlowEventOnce');
|
||||
sinon.stub(view, 'navigate').callsFake(() => {});
|
||||
});
|
||||
|
||||
it('logs a click on `why is this required`', () => {
|
||||
view.$('a[href="/sms/why"]').click();
|
||||
assert.isTrue(view.logFlowEvent.calledOnce);
|
||||
assert.isTrue(view.logFlowEvent.calledWith('link.why'));
|
||||
});
|
||||
it('logs a click on `why is this required`', () => {
|
||||
view.$('a[href="/sms/why"]').click();
|
||||
assert.isTrue(view.logFlowEvent.calledOnce);
|
||||
assert.isTrue(view.logFlowEvent.calledWith('link.why'));
|
||||
});
|
||||
|
||||
it('logs a click on `maybe later`', () => {
|
||||
view.$('a#maybe-later').click();
|
||||
assert.isTrue(view.logFlowEvent.calledOnce);
|
||||
assert.isTrue(view.logFlowEvent.calledWith('link.maybe_later'));
|
||||
});
|
||||
it('logs a click on `maybe later`', () => {
|
||||
view.$('a#maybe-later').click();
|
||||
assert.isTrue(view.logFlowEvent.calledOnce);
|
||||
assert.isTrue(view.logFlowEvent.calledWith('link.maybe_later'));
|
||||
});
|
||||
|
||||
it('logs a click in the phone number field', () => {
|
||||
view.$('input[type=tel]').val('1234').click();
|
||||
assert.isTrue(view.logFlowEventOnce.calledOnce);
|
||||
assert.isTrue(view.logFlowEventOnce.calledWith('engage'));
|
||||
});
|
||||
});
|
||||
it('logs a click in the phone number field', () => {
|
||||
view.$('input[type=tel]').val('1234').click();
|
||||
assert.isTrue(view.logFlowEventOnce.calledOnce);
|
||||
assert.isTrue(view.logFlowEventOnce.calledWith('engage'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('formPrefill', () => {
|
||||
const USER_ENTERED_PHONE_NUMBER = '44(1234) 567890';
|
||||
it('destroy saves phoneNumber into formPrefill', () => {
|
||||
view.$('input[type=tel]').val(USER_ENTERED_PHONE_NUMBER);
|
||||
describe('formPrefill', () => {
|
||||
const USER_ENTERED_PHONE_NUMBER = '44(1234) 567890';
|
||||
it('destroy saves phoneNumber into formPrefill', () => {
|
||||
view.$('input[type=tel]').val(USER_ENTERED_PHONE_NUMBER);
|
||||
|
||||
view.destroy();
|
||||
view.destroy();
|
||||
|
||||
assert.equal(formPrefill.get('phoneNumber'), USER_ENTERED_PHONE_NUMBER);
|
||||
});
|
||||
assert.equal(formPrefill.get('phoneNumber'), USER_ENTERED_PHONE_NUMBER);
|
||||
});
|
||||
|
||||
it('render with formPrefill fills in information correctly', () => {
|
||||
formPrefill.set('phoneNumber', USER_ENTERED_PHONE_NUMBER);
|
||||
createView();
|
||||
it('render with formPrefill fills in information correctly', () => {
|
||||
formPrefill.set('phoneNumber', USER_ENTERED_PHONE_NUMBER);
|
||||
createView();
|
||||
|
||||
return view.render()
|
||||
.then(() => {
|
||||
const $telEl = view.$('input[type=tel]');
|
||||
assert.equal($telEl.__val(), USER_ENTERED_PHONE_NUMBER);
|
||||
});
|
||||
});
|
||||
});
|
||||
return view.render()
|
||||
.then(() => {
|
||||
const $telEl = view.$('input[type=tel]');
|
||||
assert.equal($telEl.__val(), USER_ENTERED_PHONE_NUMBER);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче