Refactor media keys and fix play/pause

- Using space to play/pause was broken due to an issue with data
  binding. Running `$scope.$apply()` after updating the `player.pauseSong`
  property using `player.togglePause()` seems to have fixed this.
- All of the key event processing has been moved into the JS. This means
  that all the key event logic is all in one spot (easier to understand
  IMO). Additionally, this removes the need to redefine functions for
  each shortcut.
- Removed the now-unused `angular-ui-utils/keypress.js` package.
- Fixed key events being active when editing dropdown/checkbox controls
  in the settings menu
- Removed the custom `[Home]` shortcut since this is done natively by
  the browser already.
- Removed the 1-6 shortcuts for the tabs. Logic being that it seems
  pretty rare that you would want to rapidly switch between them (you
  would have to use the mouse to do anything on all tabs except the
  subsonic one anyway), and they were already broken without anyone
  complaining.
- Fixed tests
This commit is contained in:
Carey Metcalfe 2017-10-27 19:03:13 -04:00
parent dbf5010745
commit 8c279093df
8 changed files with 69 additions and 115 deletions

View file

@ -3,7 +3,7 @@ describe("Main controller", function () {
'use strict';
var controllerParams, $controller, $q, scope, mockGlobals, player, utils, persistence, subsonic, notifications,
deferred;
deferred, mockKeypress;
beforeEach(function () {
mockGlobals = {
settings: {
@ -18,6 +18,16 @@ describe("Main controller", function () {
$provide.value('globals', mockGlobals);
});
// Mock a keypress to the application
mockKeypress = function(scope, key, target){
scope.processKeyEvent({
key: key,
target: target,
isDefaultPrevented: function(){},
preventDefault: function(){}
});
}
// Mock the player service
player = jasmine.createSpyObj("player", [
"togglePause",
@ -78,10 +88,6 @@ describe("Main controller", function () {
});
});
xdescribe("toggleSetting -", function () {
});
describe("", function () {
beforeEach(function () {
$controller('AppController', controllerParams);
@ -99,24 +105,16 @@ describe("Main controller", function () {
expect(scope.showQueue).toHaveBeenCalled();
});
describe("When I toggle pause,", function () {
it("given that we're using the Jukebox mode, it sends a 'stop' command to the jukebox", function () {
mockGlobals.settings.Jukebox = true;
spyOn(scope, "sendToJukebox");
scope.togglePause();
expect(scope.sendToJukebox).toHaveBeenCalledWith('stop');
});
it("it toggles pause using the player service", function () {
scope.togglePause();
describe("When I toggle pause using the keyboard shortcut,", function () {
it("it toggles pause on the player service", function () {
mockKeypress(scope, ' ');
expect(player.togglePause).toHaveBeenCalled();
});
});
it("When I turn the volume up, it sets the player's volume up and saves it using the persistence service", function () {
player.turnVolumeUp.and.returnValue(0.6);
scope.turnVolumeUp();
mockKeypress(scope, '+');
expect(player.turnVolumeUp).toHaveBeenCalled();
expect(persistence.saveVolume).toHaveBeenCalledWith(0.6);
@ -124,52 +122,49 @@ describe("Main controller", function () {
it("When I turn the volume down, it sets the player's volume down and saves it using the persistence service", function () {
player.turnVolumeDown.and.returnValue(0.4);
scope.turnVolumeDown();
mockKeypress(scope, '-');
expect(player.turnVolumeDown).toHaveBeenCalled();
expect(persistence.saveVolume).toHaveBeenCalledWith(0.4);
});
it("When I go to the next track, it calls next track on the player", function () {
scope.nextTrack();
mockKeypress(scope, 'ArrowRight');
expect(player.nextTrack).toHaveBeenCalled();
});
it("When I go to the previous track, it calls previous track on the player", function () {
scope.previousTrack();
mockKeypress(scope, 'ArrowLeft');
expect(player.previousTrack).toHaveBeenCalled();
});
describe("Given that I am targeting an input,", function () {
var event;
beforeEach(function () {
event = { target: { tagName: "INPUT" } };
});
var target = { 'tagName': "iNPUt" } ;
it("when I use a shortcut to toggle pause, it doesn't do anything", function () {
scope.togglePause(event);
mockKeypress(scope, ' ', target);
expect(player.togglePause).not.toHaveBeenCalled();
});
it("when I use a shortcut to turn the volume up, it doesn't do anything", function () {
scope.turnVolumeUp(event);
mockKeypress(scope, '+', target);
expect(player.turnVolumeUp).not.toHaveBeenCalled();
expect(persistence.saveVolume).not.toHaveBeenCalled();
});
it("when I use a shortcut to turn the volume down, it doesn't do anything", function () {
scope.turnVolumeDown(event);
mockKeypress(scope, '-', target);
expect(player.turnVolumeDown).not.toHaveBeenCalled();
expect(persistence.saveVolume).not.toHaveBeenCalled();
});
it("when I use a shortcut to go to the next track, it doesn't do anything", function () {
scope.nextTrack(event);
mockKeypress(scope, 'RightArrow', target);
expect(player.nextTrack).not.toHaveBeenCalled();
});
it("when I use a shortcut to go to the previous track, it doesn't do anything", function () {
scope.previousTrack(event);
mockKeypress(scope, 'LeftArrow', target);
expect(player.previousTrack).not.toHaveBeenCalled();
});
});