Replaced utils setTitle and scrollTitle by a dedicated service
- Adds a Page service that will control the page's title from anywhere. - Adds a setTitleSong method. It takes a song as parameter, that way player-directive isn't responsible for correctly formatting the title. It also scrolls the title if the global setting is true - Removes the title-related methods from utils-service
This commit is contained in:
parent
0646b02e94
commit
c478f0116f
7 changed files with 138 additions and 47 deletions
54
app/common/page-service_test.js
Normal file
54
app/common/page-service_test.js
Normal file
|
@ -0,0 +1,54 @@
|
|||
describe("Page service", function() {
|
||||
'use strict';
|
||||
|
||||
var mockGlobals, Page, utils, $interval;
|
||||
beforeEach(function() {
|
||||
|
||||
mockGlobals = {
|
||||
settings: {
|
||||
ScrollTitle: false
|
||||
}
|
||||
};
|
||||
|
||||
module('jamstash.page', function ($provide) {
|
||||
$provide.value('globals', mockGlobals);
|
||||
});
|
||||
|
||||
inject(function (_Page_, _utils_, _$interval_) {
|
||||
Page = _Page_;
|
||||
utils = _utils_;
|
||||
$interval = _$interval_;
|
||||
});
|
||||
spyOn(utils.toHTML, "un").and.callFake(function (arg) { return arg; });
|
||||
});
|
||||
|
||||
describe("Given a song,", function() {
|
||||
var song;
|
||||
beforeEach(function() {
|
||||
song = {
|
||||
artist: 'Merlyn Nurse',
|
||||
name: 'Exsiccator tumble'
|
||||
};
|
||||
});
|
||||
|
||||
it("it displays its artist and its name as the page's title", function() {
|
||||
Page.setTitleSong(song);
|
||||
expect(Page.title()).toBe('Merlyn Nurse - Exsiccator tumble');
|
||||
});
|
||||
|
||||
it("if the global setting 'ScrollTitle' is true, it scrolls the page title", function() {
|
||||
spyOn(Page, "scrollTitle");
|
||||
mockGlobals.settings.ScrollTitle = true;
|
||||
|
||||
Page.setTitleSong(song);
|
||||
|
||||
expect(Page.scrollTitle).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it("Given a title, it can scroll it", function() {
|
||||
Page.setTitle('unbeloved omnificent supergravitate').scrollTitle();
|
||||
$interval.flush(1201);
|
||||
expect(Page.title()).toBe('nbeloved omnificent supergravitate u');
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue