module('vimeoplugin');

var generateTestPlayer = function(id) {
    $('#qunit-fixture').append('<iframe id="' + id + '" width="630" height="354" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>');
}

test( "test video switch", function( assert ) {
    var skipVideoStart = true;
    generateTestPlayer('player5');
    var doneVideo0 = assert.async();
    var doneVideo1 = assert.async();
    var player = $('#player5').vimeoplaylist({
        startFrom : 1,
        startTime : 90,
        videoList : [{'vimeoid' : '7100569'}, {'vimeoid' : '240975'}],
        onVideoStart: function(videoIndex) {
            if (!skipVideoStart) {
                assert.equal(videoIndex, 0, 'Start first video');
                doneVideo1();
            } else {
                skipVideoStart = false;
            }
        },
        onVideoFinish: function(videoIndex) {
            assert.equal(videoIndex, 1, 'Finish second video');
            doneVideo0();
        },
    });
    player[0].getPlayer().callEvent('ready');
    player[0].getPlayer().callEvent('finish');
    player[0].getPlayer().callEvent('ready');
});

test( "test onVideoFinish call", function( assert ) {
    generateTestPlayer('player1');
    var done = assert.async();
    var player = $('#player1').vimeoplaylist({
        startFrom : 1,
        startTime : 90,
        videoList : [{'vimeoid' : '7100569'}, {'vimeoid' : '240975'}],
        onVideoFinish: function(videoIndex) {
            assert.equal(videoIndex, 1, 'Finish second video');
            done();
        },
    });
    player[0].getPlayer().callEvent('ready');
    player[0].getPlayer().callEvent('finish');
});

test( "init test", function( assert ) {
    generateTestPlayer('player2');
    var player = $('#player2').vimeoplaylist({
        startFrom : 1,
        startTime : 12,
        videoList : [{'vimeoid' : '7100569'}, {'vimeoid' : '240975'}]});
    assert.notEqual(player, undefined, 'Plugin should return an object');
});

test( "volume test default", function( assert ) {
    generateTestPlayer('player3');
    var done = assert.async();
    var player = $('#player3').vimeoplaylist({
        startFrom : 1,
        startTime : 12,
        videoList : [{'vimeoid' : '7100569'}, {'vimeoid' : '240975'}],
        onVideoStart: function(videoIndex) {
            assert.equal(this.getVolume(), -1, 'Default volume should remain -1 after start');
            done();
        },
    });

    player[0].getPlayer().callEvent('ready');
});

test( "test onVideoStart call", function( assert ) {
    generateTestPlayer('player4');
    var done = assert.async();
    var player = $('#player4').vimeoplaylist({
        startFrom : 1,
        startTime : 12,
        videoList : [{'vimeoid' : '7100569'}, {'vimeoid' : '240975'}],
        onVideoStart: function(videoIndex) {
            assert.equal(videoIndex, 1, 'Start second video');
            done();
        },
    });
    player[0].getPlayer().callEvent('ready');
});

test( "test use structured playlist", function( assert ) {
    generateTestPlayer('player6');
    var player = $('#player6').vimeoplaylist({
        startFrom : 0,
        startTime : 12,
        videoList : [{'vimeoid' : '7100569'}],
    });

    var expectedSrc = '//player.vimeo.com/video/' + '7100569' + '?api=1&player_id=' + 'player6';
    assert.equal($('#player6').attr('src'), expectedSrc, 'Video source should change');
});

test( "test use list playlist", function( assert ) {
    generateTestPlayer('player6');
    var player = $('#player6').vimeoplaylist({
        startFrom : 0,
        startTime : 12,
        videoList : ['7100569'],
    });

    var expectedSrc = '//player.vimeo.com/video/' + '7100569' + '?api=1&player_id=' + 'player6';
    assert.equal($('#player6').attr('src'), expectedSrc, 'Video source should change');
});

@@ -96,16 +96,31 @@
 '%3Ciframe
+ class=%22player%22
  id=%22' +
@@ -242,16 +242,698 @@
 %3E');%0A%7D%0A%0A
+test( %22init test%22, function( assert ) %7B%0A    generateTestPlayer('player2');%0A    var player = $('#player2').vimeoplaylist(%7B%0A        startFrom : 1,%0A        startTime : 12,%0A        videoList : %5B%7B'vimeoid' : '7100569'%7D, %7B'vimeoid' : '240975'%7D%5D%7D);%0A    assert.notEqual(player, undefined, 'Plugin should return an object');%0A%7D);%0A%0Atest( %22init plugin for collection%22, function( assert ) %7B%0A    generateTestPlayer('player1');%0A    generateTestPlayer('player2');%0A    var players = $('.player').vimeoplaylist(%7B%0A        startFrom : 1,%0A        startTime : 90,%0A        videoList : %5B%7B'vimeoid' : '7100569'%7D, %7B'vimeoid' : '240975'%7D%5D,%0A    %7D);%0A    assert.equal(players.length, 2, 'Get 2 instances');%0A%7D);%0A%0A
 test( %22t
@@ -2374,329 +2374,8 @@
 );%0A%0A
-test( %22init test%22, function( assert ) %7B%0A    generateTestPlayer('player2');%0A    var player = $('#player2').vimeoplaylist(%7B%0A        startFrom : 1,%0A        startTime : 12,%0A        videoList : %5B%7B'vimeoid' : '7100569'%7D, %7B'vimeoid' : '240975'%7D%5D%7D);%0A    assert.notEqual(player, undefined, 'Plugin should return an object');%0A%7D);%0A%0A
 test

Test plugin applied to a collection