add basic test suite

This commit is contained in:
j 2012-05-28 21:53:56 +00:00
parent 488e982483
commit 6a97982fd4
2 changed files with 61 additions and 0 deletions

View file

@ -154,6 +154,7 @@ pandora.ui.mainMenu = function() {
{ id: 'reloadapplication', title: 'Reload Application'}, { id: 'reloadapplication', title: 'Reload Application'},
{ id: 'resetui', title: 'Reset UI Settings'}, { id: 'resetui', title: 'Reset UI Settings'},
{ id: 'debug', title: (pandora.localStorage('debug')?'Disable':'Enable')+' Debug Mode'}, { id: 'debug', title: (pandora.localStorage('debug')?'Disable':'Enable')+' Debug Mode'},
{ id: 'tests', title: 'Run Tests'},
{ id: 'triggererror', title: 'Trigger JavaScript Error'} { id: 'triggererror', title: 'Trigger JavaScript Error'}
] } ] }
] ]
@ -337,6 +338,8 @@ pandora.ui.mainMenu = function() {
pandora.localStorage('debug', true); pandora.localStorage('debug', true);
} }
that.setItemTitle('debug', (pandora.localStorage('debug') ? 'Disable' : 'Enable') + ' Debug Mode'); that.setItemTitle('debug', (pandora.localStorage('debug') ? 'Disable' : 'Enable') + ' Debug Mode');
} else if (data.id == 'tests') {
pandora.tests();
} else if (data.id == 'triggererror') { } else if (data.id == 'triggererror') {
var e = error; var e = error;
} }

View file

@ -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, ' '));
}
}