Skip to content

Commit

Permalink
Continuing to reduce hard dependencies on backgroundPage
Browse files Browse the repository at this point in the history
  • Loading branch information
MeoMix committed May 14, 2015
1 parent 7dd75cc commit c32663f
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 34 deletions.
11 changes: 6 additions & 5 deletions src/js/foreground/view/dialog/clearStreamDialogView.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
var DialogContentView = require('foreground/view/dialog/dialogContentView');
var DialogView = require('foreground/view/dialog/dialogView');

// TODO: Rename this to ClearStreamItems
var ClearStreamDialogView = DialogView.extend({
id: 'clearStreamDialog',
stream: null,
streamItems: null,

initialize: function(options) {
this.streamItems = options.streamItems;

initialize: function() {
this.model = new Dialog({
reminderProperty: 'remindClearStream'
});
Expand All @@ -18,13 +21,11 @@
template: _.template(chrome.i18n.getMessage('clearStreamQuestion'))
});

this.stream = Streamus.backgroundPage.stream;

DialogView.prototype.initialize.apply(this, arguments);
},

onSubmit: function() {
this.stream.get('items').clear();
this.streamItems.clear();
}
});

Expand Down
9 changes: 7 additions & 2 deletions src/js/foreground/view/dialog/dialogRegion.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,15 @@

// Ask the user to confirm linking their Google+ ID to the currently signed in Chrome account.
_showLinkUserIdDialog: function() {
this._showDialog(LinkUserIdDialogView);
this._showDialog(LinkUserIdDialogView, {
signInManager: Streamus.backgroundPage.signInManager
});
},

_showGoogleSignInDialog: function() {
this._showDialog(GoogleSignInDialogView);
this._showDialog(GoogleSignInDialogView, {
signInManager: Streamus.backgroundPage.signInManager
});
},

_showDialog: function(DialogView, options) {
Expand Down Expand Up @@ -109,6 +113,7 @@
}

this._showDialog(ErrorDialogView, {
player: Streamus.backgroundPage.player,
text: text,
error: youTubeError
});
Expand Down
1 change: 1 addition & 0 deletions src/js/foreground/view/dialog/dialogView.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
mouseDownTarget: null,

initialize: function() {
// TODO: Don't do this. Prefer to pass in as options, but really reminders will go away in favor of undo so just remove then.
this.settings = Streamus.backgroundPage.settings;
},

Expand Down
2 changes: 1 addition & 1 deletion src/js/foreground/view/dialog/errorDialogView.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
player: null,

initialize: function(options) {
this.player = Streamus.backgroundPage.player;
this.player = options.player;

this.model = new Dialog({
showCancelButton: false
Expand Down
6 changes: 3 additions & 3 deletions src/js/foreground/view/dialog/googleSignInDialogView.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
id: 'googleSignInDialog',
signInManager: null,

initialize: function() {
initialize: function(options) {
this.signInManager = options.signInManager;

this.model = new Dialog({
reminderProperty: 'remindGoogleSignIn',
alwaysSaveReminder: true
Expand All @@ -19,8 +21,6 @@
template: _.template(chrome.i18n.getMessage('googleSignInMessage'))
});

this.signInManager = Streamus.backgroundPage.signInManager;

DialogView.prototype.initialize.apply(this, arguments);
},

Expand Down
6 changes: 3 additions & 3 deletions src/js/foreground/view/dialog/linkUserIdDialogView.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
id: 'linkUserIdDialog',
signInManager: null,

initialize: function() {
initialize: function(options) {
this.signInManager = options.signInManager;

this.model = new Dialog({
reminderProperty: 'remindLinkUserId',
submitButtonText: chrome.i18n.getMessage('link'),
Expand All @@ -20,8 +22,6 @@
template: _.template(chrome.i18n.getMessage('linkAccountsMessage'))
});

this.signInManager = Streamus.backgroundPage.signInManager;

DialogView.prototype.initialize.apply(this, arguments);
},

Expand Down
4 changes: 3 additions & 1 deletion src/js/foreground/view/stream/clearStreamButtonView.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
if (streamItems.length === 1) {
streamItems.clear();
} else {
Streamus.channels.dialog.commands.trigger('show:dialog', ClearStreamDialogView);
Streamus.channels.dialog.commands.trigger('show:dialog', ClearStreamDialogView, {
streamItems: streamItems
});
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
'use strict';

var BrowserSettingsView = require('foreground/view/dialog/browserSettingsView');
var Settings = require('background/model/settings');

describe('BrowserSettingsView', function() {
beforeEach(function() {
this.documentFragment = document.createDocumentFragment();
this.view = new BrowserSettingsView({
model: Streamus.backgroundPage.browserSettings
model: new Settings()
});
});

Expand Down
13 changes: 9 additions & 4 deletions src/js/test/foreground/view/dialog/clearStreamDialogView.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
'use strict';

var ClearStreamDialogView = require('foreground/view/dialog/clearStreamDialogView');
var StreamItems = require('background/collection/streamItems');

describe('ClearStreamDialogView', function() {
beforeEach(function() {
this.streamItems = new StreamItems();

this.documentFragment = document.createDocumentFragment();
this.view = new ClearStreamDialogView();
this.view = new ClearStreamDialogView({
streamItems: this.streamItems
});
});

afterEach(function() {
Expand All @@ -20,12 +25,12 @@

describe('onSubmit', function() {
it('should clear StreamItems', function() {
sinon.stub(Streamus.backgroundPage.stream.get('items'), 'clear');
sinon.stub(this.streamItems, 'clear');

this.view.onSubmit();
expect(Streamus.backgroundPage.stream.get('items').clear.calledOnce).to.equal(true);
expect(this.streamItems.clear.calledOnce).to.equal(true);

Streamus.backgroundPage.stream.get('items').clear.restore();
this.streamItems.clear.restore();
});
});
});
Expand Down
9 changes: 7 additions & 2 deletions src/js/test/foreground/view/dialog/createPlaylistView.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
'use strict';

var CreatePlaylistView = require('foreground/view/dialog/createPlaylistView');
var Playlists = require('background/collection/playlists');
var DataSourceManager = require('background/model/dataSourceManager');
var testUtility = require('test/testUtility');

describe('CreatePlaylistView', function() {
beforeEach(function() {
this.documentFragment = document.createDocumentFragment();
this.view = new CreatePlaylistView({
playlists: Streamus.backgroundPage.playlists,
dataSourceManager: Streamus.backgroundPage.dataSourceManager
playlists: new Playlists([], {
userId: testUtility.getGuid()
}),
dataSourceManager: new DataSourceManager()
});
});

Expand Down
10 changes: 9 additions & 1 deletion src/js/test/foreground/view/dialog/errorDialogView.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@
'use strict';

var ErrorDialogView = require('foreground/view/dialog/errorDialogView');
var Player = require('background/model/player');
var Settings = require('background/model/settings');
var YouTubePlayer = require('background/model/youTubePlayer');

describe('ErrorDialogView', function() {
beforeEach(function() {
this.documentFragment = document.createDocumentFragment();
this.view = new ErrorDialogView();
this.view = new ErrorDialogView({
player: new Player({
settings: new Settings(),
youTubePlayer: new YouTubePlayer()
})
});
});

afterEach(function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
'use strict';

var GoogleSignInDialogView = require('foreground/view/dialog/googleSignInDialogView');
var SignInManager = require('background/model/signInManager');

describe('GoogleSignInDialogView', function() {
beforeEach(function() {
this.signInManager = new SignInManager();
this.documentFragment = document.createDocumentFragment();
this.view = new GoogleSignInDialogView();
this.view = new GoogleSignInDialogView({
signInManager: this.signInManager
});
});

afterEach(function() {
Expand All @@ -20,13 +24,13 @@

describe('onSubmit', function() {
it('should tell SignInManager not to notify again', function() {
sinon.stub(Streamus.backgroundPage.signInManager, 'set');
sinon.stub(this.signInManager, 'set');

this.view.onSubmit();
expect(Streamus.backgroundPage.signInManager.set.calledOnce).to.equal(true);
expect(Streamus.backgroundPage.signInManager.set.calledWith('needGoogleSignIn', false)).to.equal(true);
expect(this.signInManager.set.calledOnce).to.equal(true);
expect(this.signInManager.set.calledWith('needGoogleSignIn', false)).to.equal(true);

Streamus.backgroundPage.signInManager.set.restore();
this.signInManager.set.restore();
});
});
});
Expand Down
13 changes: 9 additions & 4 deletions src/js/test/foreground/view/dialog/linkUserIdDialogView.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
'use strict';

var LinkUserIdDialogView = require('foreground/view/dialog/linkUserIdDialogView');
var SignInManager = require('background/model/signInManager');

describe('LinkUserIdDialogView', function() {
beforeEach(function() {
this.signInManager = new SignInManager();

this.documentFragment = document.createDocumentFragment();
this.view = new LinkUserIdDialogView();
this.view = new LinkUserIdDialogView({
signInManager: this.signInManager
});
});

afterEach(function() {
Expand All @@ -20,12 +25,12 @@

describe('onSubmit', function() {
it('should tell SignInManager to save the current user\'s GooglePlusId', function() {
sinon.stub(Streamus.backgroundPage.signInManager, 'saveGooglePlusId');
sinon.stub(this.signInManager, 'saveGooglePlusId');

this.view.onSubmit();
expect(Streamus.backgroundPage.signInManager.saveGooglePlusId.calledOnce).to.equal(true);
expect(this.signInManager.saveGooglePlusId.calledOnce).to.equal(true);

Streamus.backgroundPage.signInManager.saveGooglePlusId.restore();
this.signInManager.saveGooglePlusId.restore();
});
});
});
Expand Down
6 changes: 4 additions & 2 deletions src/js/test/foreground/view/dialog/settingsView.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
'use strict';

var SettingsView = require('foreground/view/dialog/settingsView');
var SignInManager = require('background/model/signInManager');
var Settings = require('background/model/settings');

describe('SettingsView', function() {
beforeEach(function() {
this.documentFragment = document.createDocumentFragment();
this.view = new SettingsView({
model: Streamus.backgroundPage.settings,
signInManager: Streamus.backgroundPage.signInManager
model: new Settings(),
signInManager: new SignInManager()
});
});

Expand Down
5 changes: 5 additions & 0 deletions src/js/test/testUtility.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

var TestUtility = {
songIdLength: 7,
guidIdLength: 16,

getGuid: function() {
return this._getUniqueId(this.guidIdLength);
},

_getUniqueId: function(idLength) {
var text = '';
Expand Down

0 comments on commit c32663f

Please sign in to comment.