Skip to content

Commit

Permalink
Add new tests, update old ones
Browse files Browse the repository at this point in the history
  • Loading branch information
vodkabears committed Sep 29, 2014
1 parent 151631b commit 3f76a31
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 5 deletions.
4 changes: 4 additions & 0 deletions test/vide.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@

<div id="block1" data-vide-bg="http://vodkabears.github.io/vide/video/ocean" data-vide-options="loop: false, volume:0.3,playbackRate:,position: 60% bottom"></div>
<div id="block2"></div>
<div id="block3" data-vide-bg="mp4: http://vodkabears.github.io/vide/video/ocean, webm: video/ocean.webm, ogv: video/ocean, poster: video/ocean.jpg"></div>
<div id="block4" data-vide-bg='{"mp4": "http://vodkabears.github.io/vide/video/ocean", "webm": "video/ocean.webm", "ogv": "video/ocean", "poster": "video/ocean.jpg"}' data-vide-options='{"loop": false, "volume":0.3}'>
<div id="block5"></div>
</div>
</body>
</html>
79 changes: 74 additions & 5 deletions test/vide_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
throws(block, [expected], [message])
*/

var $block1, $block2;
var $block1, $block2, $block3, $block4, $block5;

QUnit.begin(function () {
$block1 = $("#block1");
$block2 = $("#block2");
$block3 = $("#block3");
$block4 = $("#block4");
$block5 = $("#block5");
});

QUnit.test("Initialization", function () {
Expand All @@ -33,16 +36,39 @@
posterType: "gif"
});

$block5.vide(
"mp4: video/ocean, webm: video/ocean.webm, ogv: video/ocean, poster: video/ocean",
"loop: false,volume:0.3, playbackRate:"
);

ok($block1.data("vide"));
ok($block2.data("vide"));
ok($block3.data("vide"));
ok($block4.data("vide"));
ok($block5.data("vide"));
});

QUnit.test("Parse path", function () {
equal($block1.data("vide").path, $block1.data("vide-bg"));
});

QUnit.test("Parsing of a path with multiple names", function () {
deepEqual($block3.data("vide").path, {
mp4: "http://vodkabears.github.io/vide/video/ocean",
webm: "video/ocean",
ogv: "video/ocean",
poster: "video/ocean"
});
});

QUnit.test("Parse options", function () {
var video = $block1.data("vide").getVideoObject();
var inst = $block1.data("vide"),
video = $block1.data("vide").getVideoObject();

equal(inst.settings.loop, false);
equal(inst.settings.volume, 0.3);
equal(inst.settings.playbackRate, 1);
equal(inst.settings.position, "60% bottom");

equal(video.loop, false);
equal(video.volume, 0.3);
Expand All @@ -51,12 +77,45 @@
equal(video.style.top, "100%");
});

QUnit.test("Passing JSON with a data attribute", function () {
var inst = $block4.data("vide");

deepEqual(inst.path, {
mp4: "http://vodkabears.github.io/vide/video/ocean",
webm: "video/ocean",
ogv: "video/ocean",
poster: "video/ocean"
});

equal(inst.settings.loop, false);
equal(inst.settings.volume, 0.3);
});

QUnit.test("Passing strings with params directly to the constructor", function () {
var inst = $block5.data("vide");

deepEqual(inst.path, {
mp4: "video/ocean",
webm: "video/ocean",
ogv: "video/ocean",
poster: "video/ocean"
});

equal(inst.settings.loop, false);
equal(inst.settings.volume, 0.3);
equal(inst.settings.playbackRate, 1);
});

QUnit.asyncTest("Poster detection", function () {
var wrapper1 = $block1.data("vide").wrapper,
wrapper2 = $block2.data("vide").wrapper;
var inst1 = $block1.data("vide"),
inst2 = $block2.data("vide"),
wrapper1 = inst1.wrapper,
wrapper2 = inst2.wrapper;

equal(inst2.settings.posterType, "gif");
ok(wrapper2.css("background-image").search("video/ocean.gif") > -1);

equal(inst1.settings.posterType, "detect");
setTimeout(function () {
ok(wrapper1.css("background-image").search("http://vodkabears.github.io/vide/video/ocean.jpg") > -1);
QUnit.start();
Expand All @@ -75,19 +134,26 @@
$block2.vide("video/ocean");
$block2.vide("video/ocean");
$block1.vide("video/ocean");
$block3.vide("video/ocean");

var count = $.vide.lookup.filter(function (value) {
return value !== undefined;
}).length;

ok($block1.data("vide"));
ok($block2.data("vide"));
equal(count, 2);
ok($block3.data("vide"));
ok($block4.data("vide"));
ok($block5.data("vide"));
equal(count, 5);
});

QUnit.test("Destroy", function () {
$block1.data("vide").destroy();
$block2.data("vide").destroy();
$block3.data("vide").destroy();
$block4.data("vide").destroy();
$block5.data("vide").destroy();

var count = $.vide.lookup.filter(function (value) {
return value !== undefined;
Expand All @@ -96,6 +162,9 @@
equal(count, 0);
equal($block1.find("video").length, 0);
equal($block2.find("video").length, 0);
equal($block3.find("video").length, 0);
equal($block4.find("video").length, 0);
equal($block5.find("video").length, 0);
});

}(jQuery));

0 comments on commit 3f76a31

Please sign in to comment.