/** * Forge Tasks Test * * @author David I. Lehn * * Copyright (c) 2009-2010 Digital Bazaar, Inc. All rights reserved. */ jQuery(function($) { var cat = 'forge.tests.tasks'; var tests = []; var passed = 0; var failed = 0; var init = function() { passed = failed = 0; $('.ready,.testing,.pass,.fail') .removeClass('ready testing pass fail'); $('#status') .text('Ready.') .addClass('ready'); $('#total').text(tests.length); $('#pass').text(passed); $('#fail').text(failed); $('.expect').empty(); $('.result').empty(); $('.time').empty(); $('#start').removeAttr('disabled'); }; var start = function() { $('#start').attr('disabled', 'disabled'); // meta! use tasks to run the task tests forge.task.start({ type: 'test', run: function(task) { task.next('starting', function(task) { forge.log.debug(cat, 'start'); $('#status') .text('Testing...') .addClass('testing') .removeClass('idle'); }); $.each(tests, function(i, test) { task.next('test', function(task) { var title = $('li:first', test.container); if($('#scroll:checked').length === 1) { $('html,body').animate({scrollTop: title.offset().top}); } title.addClass('testing'); test.run(task, test); }); task.next('test', function(task) { $('li:first', test.container).removeClass('testing'); }); }); task.next('success', function(task) { forge.log.debug(cat, 'done'); if(failed === 0) { $('#status') .text('PASS') .addClass('pass') .removeClass('testing'); } else { // FIXME: should just be hitting failure() below $('#status') .text('FAIL') .addClass('fail') .removeClass('testing'); } }); }, failure: function() { $('#status') .text('FAIL') .addClass('fail') .removeClass('testing'); } }); }; $('#start').click(function() { start(); }); $('#reset').click(function() { init(); }); var addTest = function(name, run) { var container = $('