From 6a97982fd4cbeabd5c2ad6a7df7212020c5cc84a Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 28 May 2012 21:53:56 +0000 Subject: [PATCH] add basic test suite --- static/js/pandora/menu.js | 3 ++ static/js/pandora/tests.js | 58 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 static/js/pandora/tests.js diff --git a/static/js/pandora/menu.js b/static/js/pandora/menu.js index 12ca17c2..97e4fb60 100644 --- a/static/js/pandora/menu.js +++ b/static/js/pandora/menu.js @@ -154,6 +154,7 @@ pandora.ui.mainMenu = function() { { id: 'reloadapplication', title: 'Reload Application'}, { id: 'resetui', title: 'Reset UI Settings'}, { id: 'debug', title: (pandora.localStorage('debug')?'Disable':'Enable')+' Debug Mode'}, + { id: 'tests', title: 'Run Tests'}, { id: 'triggererror', title: 'Trigger JavaScript Error'} ] } ] @@ -337,6 +338,8 @@ pandora.ui.mainMenu = function() { pandora.localStorage('debug', true); } that.setItemTitle('debug', (pandora.localStorage('debug') ? 'Disable' : 'Enable') + ' Debug Mode'); + } else if (data.id == 'tests') { + pandora.tests(); } else if (data.id == 'triggererror') { var e = error; } diff --git a/static/js/pandora/tests.js b/static/js/pandora/tests.js new file mode 100644 index 00000000..995ac499 --- /dev/null +++ b/static/js/pandora/tests.js @@ -0,0 +1,58 @@ +// vim: et:ts=4:sw=4:sts=4:ft=javascript +'use strict'; + +pandora.tests = function() { + var tests = []; + pandora.api.find({ + query: {conditions: [], operator: '&'}, + sort: [{key: 'random', operator:'+'}], + keys: ['id', 'rendered', 'duration'], + range: [0, 10] + }, function(result) { + var item = result.data.items.filter(function(item) { return item.rendered && item.duration > 300; })[0], + position = 60; + pandora.UI.set('videoPoints.' + item.id, { + annotation: '', + 'in': position, + out: position, + position: position + }); + pandora.UI.set({item: item.id, itemView: 'player'}); + test('set item', pandora.user.ui.item, item.id); + startPlayback(); + function startPlayback() { + if(pandora.$ui.player) { + pandora.$ui.player.options({paused: false}); + setTimeout(function() { + pandora.$ui.player.options({paused: true}); + test('video position increased after playback', pandora.user.ui.videoPoints[item.id].position > position, true); + results(); + }, 5000); + } else { + setTimeout(startPlayback, 500); + } + } + }); + + function test(title, actual, expected) { + tests.push({ + actual: actual, + expected: expected, + passed: Ox.isEqual(actual, expected), + title: title + }) + } + + function results() { + var passed = tests.filter(function(test) { + return test.passed; + }).length, + failed = tests.length - passed; + Ox.print(JSON.stringify({ + tests: tests.length, + passed: passed, + failed: failed, + results: tests + }, null, ' ')); + } +}