Navigation Menu

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

Commit

Permalink
refactor(tests): eliminate duplicated setup code in app-start tests
Browse files Browse the repository at this point in the history
  • Loading branch information
philbooth committed Feb 6, 2019
1 parent 290c9af commit b80cc24
Showing 1 changed file with 11 additions and 88 deletions.
99 changes: 11 additions & 88 deletions app/tests/spec/lib/app-start.js
Expand Up @@ -58,6 +58,17 @@ define(function (require, exports, module) {


windowMock = new WindowMock(); windowMock = new WindowMock();
windowMock.parent = new WindowMock(); windowMock.parent = new WindowMock();

appStart = new AppStart({
broker: brokerMock,
history: backboneHistoryMock,
notifier,
router: routerMock,
storage: Storage,
translator,
user: userMock,
window: windowMock
});
}); });


afterEach(() => { afterEach(() => {
Expand All @@ -72,16 +83,6 @@ define(function (require, exports, module) {
beforeEach(() => { beforeEach(() => {
sandbox = sinon.sandbox.create(); sandbox = sinon.sandbox.create();


appStart = new AppStart({
broker: brokerMock,
history: backboneHistoryMock,
router: routerMock,
storage: Storage,
translator,
user: userMock,
window: windowMock
});

sandbox.spy(appStart, 'enableSentryMetrics'); sandbox.spy(appStart, 'enableSentryMetrics');
sandbox.stub(ErrorUtils, 'fatalError').callsFake(() => {}); sandbox.stub(ErrorUtils, 'fatalError').callsFake(() => {});


Expand All @@ -103,18 +104,6 @@ define(function (require, exports, module) {
}); });


describe('startApp', () => { describe('startApp', () => {
beforeEach(() => {
appStart = new AppStart({
broker: brokerMock,
history: backboneHistoryMock,
router: routerMock,
storage: Storage,
translator,
user: userMock,
window: windowMock
});
});

it('starts the app, does not redirect', () => { it('starts the app, does not redirect', () => {
return appStart.startApp() return appStart.startApp()
.then(() => { .then(() => {
Expand Down Expand Up @@ -214,9 +203,6 @@ define(function (require, exports, module) {


describe('initializeL10n', () => { describe('initializeL10n', () => {
it('fetches translations', () => { it('fetches translations', () => {
appStart = new AppStart({
translator
});
return appStart.initializeL10n() return appStart.initializeL10n()
.then(() => { .then(() => {
assert.ok(appStart._translator.fetch.calledOnce); assert.ok(appStart._translator.fetch.calledOnce);
Expand Down Expand Up @@ -477,15 +463,6 @@ define(function (require, exports, module) {
}); });


describe('initializeErrorMetrics', () => { describe('initializeErrorMetrics', () => {
beforeEach(() => {
appStart = new AppStart({
broker: brokerMock,
history: backboneHistoryMock,
router: routerMock,
window: windowMock
});
});

it('skips error metrics on empty config', () => { it('skips error metrics on empty config', () => {
appStart.initializeExperimentGroupingRules(); appStart.initializeExperimentGroupingRules();
var ableChoose = sinon.stub(appStart._experimentGroupingRules, 'choose').callsFake(() => { var ableChoose = sinon.stub(appStart._experimentGroupingRules, 'choose').callsFake(() => {
Expand Down Expand Up @@ -528,30 +505,12 @@ define(function (require, exports, module) {
}); });


describe('_getUniqueUserId', () => { describe('_getUniqueUserId', () => {
beforeEach(() => {
appStart = new AppStart({
broker: brokerMock,
history: backboneHistoryMock,
router: routerMock,
window: windowMock
});
});

it('creates a user id', () => { it('creates a user id', () => {
assert.isDefined(appStart._getUniqueUserId()); assert.isDefined(appStart._getUniqueUserId());
}); });
}); });


describe('initializeRouter', () => { describe('initializeRouter', () => {
beforeEach(() => {
appStart = new AppStart({
broker: brokerMock,
history: backboneHistoryMock,
notifier: notifier,
window: windowMock
});
});

it('creates a router', () => { it('creates a router', () => {
appStart.initializeRouter(); appStart.initializeRouter();
assert.isDefined(appStart._router); assert.isDefined(appStart._router);
Expand Down Expand Up @@ -583,16 +542,6 @@ define(function (require, exports, module) {
}); });


describe('initializeHeightObserver', () => { describe('initializeHeightObserver', () => {
beforeEach(() => {
appStart = new AppStart({
broker: brokerMock,
history: backboneHistoryMock,
router: routerMock,
user: userMock,
window: windowMock
});
});

it('sets up the HeightObserver, triggers a `resize` notification on the iframe channel when the height changes', function (done) { it('sets up the HeightObserver, triggers a `resize` notification on the iframe channel when the height changes', function (done) {
sinon.stub(appStart, '_isInAnIframe').callsFake(() => { sinon.stub(appStart, '_isInAnIframe').callsFake(() => {
return true; return true;
Expand All @@ -612,13 +561,6 @@ define(function (require, exports, module) {
}); });


describe('initializeRefreshObserver', () => { describe('initializeRefreshObserver', () => {
beforeEach(() => {
appStart = new AppStart({
notifier: notifier,
window: windowMock
});
});

it('creates a RefreshObserver instance', () => { it('creates a RefreshObserver instance', () => {
appStart.initializeRefreshObserver(); appStart.initializeRefreshObserver();
assert.instanceOf(appStart._refreshObserver, RefreshObserver); assert.instanceOf(appStart._refreshObserver, RefreshObserver);
Expand Down Expand Up @@ -734,11 +676,6 @@ define(function (require, exports, module) {
describe('_getContext', () => { describe('_getContext', () => {
describe('in a verification flow', () => { describe('in a verification flow', () => {
beforeEach(() => { beforeEach(() => {
appStart = new AppStart({
notifier: notifier,
window: windowMock
});

sinon.stub(appStart, '_isVerification').callsFake(() => { sinon.stub(appStart, '_isVerification').callsFake(() => {
return true; return true;
}); });
Expand Down Expand Up @@ -850,13 +787,6 @@ define(function (require, exports, module) {
}); });


describe('_getSameBrowserVerificationModel', () => { describe('_getSameBrowserVerificationModel', () => {
beforeEach(() => {
appStart = new AppStart({
notifier: notifier,
window: windowMock
});
});

it('gets a `SameBrowserVerificationModel` instance', () => { it('gets a `SameBrowserVerificationModel` instance', () => {
assert.instanceOf( assert.instanceOf(
appStart._getSameBrowserVerificationModel('context'), appStart._getSameBrowserVerificationModel('context'),
Expand All @@ -866,13 +796,6 @@ define(function (require, exports, module) {
}); });


describe('isReportSignIn', () => { describe('isReportSignIn', () => {
beforeEach(() => {
appStart = new AppStart({
user: userMock,
window: windowMock
});
});

it('returns true for pathname = `/report_signin`', () => { it('returns true for pathname = `/report_signin`', () => {
windowMock.location.pathname = '/report_signin'; windowMock.location.pathname = '/report_signin';
assert.isTrue(appStart._isReportSignIn()); assert.isTrue(appStart._isReportSignIn());
Expand Down

0 comments on commit b80cc24

Please sign in to comment.