@@ -2,6 +2,7 @@ var spotify = require('../lib/spotify-node-applescript.js');
2
2
var expect = require ( 'chai' ) . expect ;
3
3
4
4
var COLDPLAY_TROUBLE_ID = 'spotify:track:0R8P9KfGJCDULmlEoBagcO'
5
+ var COLDPLAY_TROUBLE_PLAYTIME_SEC = 273
5
6
6
7
describe ( 'Spotify Controller' , function ( ) {
7
8
@@ -206,6 +207,60 @@ describe('Spotify Controller', function () {
206
207
} ) ;
207
208
} ) ;
208
209
210
+ // Seek forward and backward
211
+
212
+ it ( 'should seek forward' , function ( done ) {
213
+ // first do jumpTo 0 in case position is at the max
214
+ spotify . jumpTo ( 0 , function ( ) {
215
+ spotify . seekForward ( 5 , function ( ) {
216
+ spotify . getState ( function ( error , state ) {
217
+ expect ( state . position ) . to . be . gte ( 5 ) ;
218
+ done ( ) ;
219
+ } ) ;
220
+ } ) ;
221
+ } ) ;
222
+ } ) ;
223
+
224
+ it ( 'should seek backward' , function ( done ) {
225
+ // first do jumpTo 15 in case position is at 0
226
+ spotify . jumpTo ( 15 , function ( ) {
227
+ spotify . seekBackward ( 5 , function ( ) {
228
+ spotify . getState ( function ( error , state ) {
229
+ expect ( state . position ) . to . be . gte ( 10 ) ;
230
+ done ( ) ;
231
+ } ) ;
232
+ } ) ;
233
+ } ) ;
234
+ } ) ;
235
+
236
+ it ( 'should set position to 0 on seeking foward exceeding max' , function ( done ) {
237
+ // first do jumpTo to emulate overflow when seeking forward
238
+ spotify . jumpTo ( COLDPLAY_TROUBLE_PLAYTIME_SEC - 3 , function ( ) {
239
+ spotify . getState ( function ( error , state ) {
240
+ spotify . seekForward ( 5 , function ( ) {
241
+ spotify . getState ( function ( error , state ) {
242
+ expect ( state . position ) . to . equal ( 0 ) ;
243
+ done ( ) ;
244
+ } ) ;
245
+ } ) ;
246
+ } ) ;
247
+ } ) ;
248
+ } ) ;
249
+
250
+ it ( 'should set position to 0 on seeking foward exceeding min' , function ( done ) {
251
+ // first do jumpTo to emulate overflow when seeking backward
252
+ spotify . jumpTo ( 2 , function ( ) {
253
+ spotify . getState ( function ( error , state ) {
254
+ spotify . seekBackward ( 5 , function ( ) {
255
+ spotify . getState ( function ( error , state ) {
256
+ expect ( state . position ) . to . equal ( 0 ) ;
257
+ done ( ) ;
258
+ } ) ;
259
+ } ) ;
260
+ } ) ;
261
+ } ) ;
262
+ } ) ;
263
+
209
264
// State retrieval
210
265
211
266
it ( 'should return current track' , function ( done ) {
0 commit comments