Adds back setting the volume up / down using the keyboard
- Adds a volume field to the player service. It is set directly, no need for get/set... - Adds a watcher in player-directive to set jPlayer's volume accordingly - Adds turnVolumeUp and turnVolumeDown methods to the main scope. For the moment they are fine there, we'll maybe move them to the player service if they are called by anything else. - Adds get/save/delete for the volume in the persistence service.
This commit is contained in:
parent
8529e331a2
commit
a85865371c
8 changed files with 196 additions and 57 deletions
|
@ -1,7 +1,7 @@
|
|||
describe("Main controller", function() {
|
||||
'use strict';
|
||||
|
||||
var scope, mockGlobals, player, utils;
|
||||
var controllerParams, $controller, scope, mockGlobals, player, utils, persistence;
|
||||
beforeEach(function() {
|
||||
mockGlobals = {
|
||||
settings: {
|
||||
|
@ -17,14 +17,20 @@ describe("Main controller", function() {
|
|||
|
||||
// Mock the player service
|
||||
player = jasmine.createSpyObj("player", ["togglePause"]);
|
||||
player.queue = [];
|
||||
player.volume = 1.0;
|
||||
|
||||
inject(function ($controller, $rootScope, _$document_, _$window_, _$location_, _$cookieStore_, _utils_, globals, _model_, _notifications_, _locker_, _Page_) {
|
||||
// Mock the persistence service
|
||||
persistence = jasmine.createSpyObj("persistence", ["getVolume", "saveVolume"]);
|
||||
|
||||
inject(function (_$controller_, $rootScope, _$document_, _$window_, _$location_, _$cookieStore_, _utils_, globals, _model_, _notifications_, _Page_) {
|
||||
scope = $rootScope.$new();
|
||||
utils = _utils_;
|
||||
|
||||
spyOn(utils, "switchTheme");
|
||||
|
||||
$controller('AppController', {
|
||||
$controller = _$controller_;
|
||||
controllerParams = {
|
||||
$scope: scope,
|
||||
$rootScope: $rootScope,
|
||||
$document: _$document_,
|
||||
|
@ -36,11 +42,10 @@ describe("Main controller", function() {
|
|||
model: _model_,
|
||||
notifications: _notifications_,
|
||||
player: player,
|
||||
locker: _locker_,
|
||||
persistence: persistence,
|
||||
Page: _Page_
|
||||
});
|
||||
};
|
||||
});
|
||||
player.queue = [];
|
||||
});
|
||||
|
||||
xdescribe("updateFavorite -", function() {
|
||||
|
@ -70,30 +75,85 @@ describe("Main controller", function() {
|
|||
|
||||
});
|
||||
|
||||
it("given that the global setting 'ShowQueue' is true, when the playing queue's length changes and is not empty, it shows the queue", function() {
|
||||
mockGlobals.settings.ShowQueue = true;
|
||||
player.queue = [{
|
||||
id: 684
|
||||
}];
|
||||
spyOn(scope, "showQueue");
|
||||
|
||||
scope.$apply();
|
||||
|
||||
expect(scope.showQueue).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe("When I toggle pause,", function() {
|
||||
it("given that we're using the Jukebox mode, it sends a 'pause' command to the jukebox", function() {
|
||||
mockGlobals.settings.Jukebox = true;
|
||||
spyOn(scope, "sendToJukebox");
|
||||
|
||||
scope.togglePause();
|
||||
expect(scope.sendToJukebox).toHaveBeenCalledWith('pause');
|
||||
describe("", function () {
|
||||
beforeEach(function() {
|
||||
$controller('AppController', controllerParams);
|
||||
});
|
||||
|
||||
it("it toggles pause using the player service", function() {
|
||||
scope.togglePause();
|
||||
expect(player.togglePause).toHaveBeenCalled();
|
||||
it("given that the global setting 'ShowQueue' is true, when the playing queue's length changes and is not empty, it shows the queue", function() {
|
||||
mockGlobals.settings.ShowQueue = true;
|
||||
player.queue = [{
|
||||
id: 684
|
||||
}];
|
||||
spyOn(scope, "showQueue");
|
||||
|
||||
scope.$apply();
|
||||
|
||||
expect(scope.showQueue).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe("When I toggle pause,", function() {
|
||||
it("given that we're using the Jukebox mode, it sends a 'pause' command to the jukebox", function() {
|
||||
mockGlobals.settings.Jukebox = true;
|
||||
spyOn(scope, "sendToJukebox");
|
||||
|
||||
scope.togglePause();
|
||||
expect(scope.sendToJukebox).toHaveBeenCalledWith('pause');
|
||||
});
|
||||
|
||||
it("it toggles pause using the player service", function() {
|
||||
scope.togglePause();
|
||||
expect(player.togglePause).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("When I turn the volume up,", function() {
|
||||
it("it sets the player's volume up by 10% and saves it using the persistence service", function() {
|
||||
player.volume = 0.5;
|
||||
|
||||
scope.turnVolumeUp();
|
||||
|
||||
expect(player.volume).toBe(0.6);
|
||||
expect(persistence.saveVolume).toHaveBeenCalledWith(0.6);
|
||||
});
|
||||
|
||||
it("if the player's resulting volume won't be between 0 and 1, it sets it to 1", function() {
|
||||
player.volume = 5.91488;
|
||||
|
||||
scope.turnVolumeUp();
|
||||
|
||||
expect(player.volume).toBe(1.0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("When I turn the volume down,", function() {
|
||||
it("it sets the player's volume down by 10% and saves it using the persistence service", function() {
|
||||
player.volume = 0.5;
|
||||
|
||||
scope.turnVolumeDown();
|
||||
|
||||
expect(player.volume).toBe(0.4);
|
||||
expect(persistence.saveVolume).toHaveBeenCalledWith(0.4);
|
||||
});
|
||||
|
||||
it("if the player's resulting volume won't be between 0 and 1, it sets it to 0", function() {
|
||||
player.volume = 5.91488;
|
||||
|
||||
scope.turnVolumeDown();
|
||||
|
||||
expect(player.volume).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("When starting up,", function() {
|
||||
it("it loads the volume from the persistence service and sets the player service's volume with it", function() {
|
||||
persistence.getVolume.and.returnValue(0.551835);
|
||||
|
||||
$controller('AppController', controllerParams);
|
||||
|
||||
expect(persistence.getVolume).toHaveBeenCalled();
|
||||
expect(player.volume).toBe(0.551835);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue