Skip to content

Commit

Permalink
Add more signals tests
Browse files Browse the repository at this point in the history
  • Loading branch information
YurySolovyov authored and emersion committed Mar 20, 2017
1 parent 1e1c917 commit 8850fb7
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 6 deletions.
11 changes: 9 additions & 2 deletions index.js
Expand Up @@ -146,14 +146,14 @@ Player.prototype.addTrack = function (track) {
if (this.tracks.length > 2) {
afterTrack = this.tracks[this.tracks.length - 2]['mpris:trackid'];
}
that.interfaces.playlists.emitSignal('TrackAdded', afterTrack);
this.interfaces.trackList.emitSignal('TrackAdded', [track], afterTrack);
};

Player.prototype.removeTrack = function (trackId) {
var i = this.getTrackIndex(trackId);
this.tracks.splice(i, 1);

that.interfaces.playlists.emitSignal('TrackRemoved', trackId);
this.interfaces.trackList.emitSignal('TrackRemoved', trackId);
};

Player.prototype.getPlaylistIndex = function (playlistId) {
Expand Down Expand Up @@ -185,6 +185,13 @@ Player.prototype.setActivePlaylist = function (playlistId) {
Valid: (i >= 0) ? true : false,
Playlist: this.playlists[i]
};

this.interfaces.playlists.emitSignal('PlaylistChanged', {
Id: this.objectPath(playlistId),
// TODO: figure out what to do with naming and icon
Name: 'playlist' + i,
Icon: ''
});
};

module.exports = Player;
8 changes: 4 additions & 4 deletions spec/player-interface-spec.js
Expand Up @@ -59,7 +59,7 @@ const signals = [
{
method: 'seeked',
signal: 'Seeked',
args: [3.14 * 10e6]
args: () => { return [3.14 * 10e6]; }
}
];

Expand Down Expand Up @@ -100,16 +100,16 @@ describe('player interface', () => {

it('should emit signals on the bus that correspond to method calls', (done) => {

return helpers.getInterfaceAsync(service, objectpath, 'org.mpris.MediaPlayer2.Player').then(obj => {
helpers.getInterfaceAsync(service, objectpath, namespace).then(obj => {

return signals.reduce((promise, signal) => {
return promise.then(() => {

const wait = helpers.waitForEvent(obj, signal.signal).then(function() {
const args = Array.prototype.slice.call(arguments);
expect(args).toEqual(signal.args);
expect(args).toEqual(signal.args(player));
});
player[signal.method].apply(player, signal.args);
player[signal.method].apply(player, signal.args(player));

return wait;
});
Expand Down
37 changes: 37 additions & 0 deletions spec/playlists-interface-spec.js
Expand Up @@ -14,6 +14,14 @@ const events = [
}
];

const signals = [
{
method: 'setActivePlaylist',
signal: 'PlaylistChanged',
args: (player) => { return ['playlist/0'] }
}
];

describe('playlists interface', () => {
let bus, name, player, service, object, servicename;

Expand All @@ -33,6 +41,13 @@ describe('playlists interface', () => {
object = obj;
done();
});

player.playlists = [
{
Id: 'playlist/0',
Valid: true
}
];
});

it('should emit events that correspond to method calls', (done) => {
Expand All @@ -48,4 +63,26 @@ describe('playlists interface', () => {
}, Promise.resolve()).then(done).catch(fail);

});

it('should emit signals on the bus that correspond to method calls', (done) => {

helpers.getInterfaceAsync(service, objectpath, namespace).then(obj => {

return signals.reduce((promise, signal) => {
return promise.then(() => {

const wait = helpers.waitForEvent(obj, signal.signal).then(function() {
// args have vastly different formats, need to somehow make them comparable
// const args = Array.prototype.slice.call(arguments);
// expect(args).toEqual(signal.args(player));
});
player[signal.method].apply(player, signal.args(player));

return wait;
});
}, Promise.resolve());

}).then(done).catch(fail);

});
});
43 changes: 43 additions & 0 deletions spec/tracklist-interface-spec.js
Expand Up @@ -24,6 +24,23 @@ const events = [
}
];

const signals = [
{
method: 'addTrack',
signal: 'TrackAdded',
args: (player) => {
return [
{'mpris:trackid': player.objectPath('playlist/1') }
];
}
},
{
method: 'removeTrack',
signal: 'TrackRemoved',
args: (player) => { return [player.objectPath('playlist/1')]; }
}
];

describe('playlists interface', () => {
let bus, name, player, service, object, servicename;

Expand All @@ -43,6 +60,10 @@ describe('playlists interface', () => {
object = obj;
done();
});

player.tracks = [
{'mpris:trackid': player.objectPath('playlist/1') }
];
});

it('should emit events that correspond to method calls', (done) => {
Expand All @@ -58,4 +79,26 @@ describe('playlists interface', () => {
}, Promise.resolve()).then(done).catch(fail);

});

it('should emit signals on the bus that correspond to method calls', (done) => {

helpers.getInterfaceAsync(service, objectpath, namespace).then(obj => {

return signals.reduce((promise, signal) => {
return promise.then(() => {

const wait = helpers.waitForEvent(obj, signal.signal).then(function() {
// args have vastly different formats, need to somehow make them comparable
// const args = Array.prototype.slice.call(arguments);
// expect(args).toEqual(signal.args(player));
});
player[signal.method].apply(player, signal.args(player));

return wait;
});
}, Promise.resolve());

}).then(done).catch(fail);

});
});

0 comments on commit 8850fb7

Please sign in to comment.