display test stats

This commit is contained in:
rolux 2012-06-12 17:24:58 +02:00
parent e21354d7b4
commit b915839305

View file

@ -61,29 +61,32 @@ Ox.DocPanel = function(options, self) {
} }
}); });
if (!self.options.results) { self.$toolbar = Ox.Bar({size: 24});
self.options.results = {};
}
self.$testsButton = Ox.Button({title: 'Run Tests'})
.css({float: 'left', margin: '4px'})
.bindEvent({click: runTests});
self.$testsLabel = Ox.Label({title: 'Running Tests...'})
.css({float: 'left', margin: '4px'})
.hide();
self.$toolbar = Ox.Bar({size: 24})
.append(self.$testsButton)
.append(self.$testsLabel)
self.$list = Ox.Element(); self.$list = Ox.Element();
self.$sidebar = Ox.SplitPanel({ self.$sidebar = Ox.SplitPanel({
elements: [ elements: [
{element: Ox.Element(), size: 24}, {element: Ox.Element()},
{element: Ox.Element()} {element: Ox.Element(), size: 24}
], ],
orientation: 'vertical' orientation: 'vertical'
}); });
self.$page = Ox.Element(); self.$page = Ox.Element();
if (!self.options.results) {
self.options.results = {};
self.$testsButton = Ox.Button({title: 'Run Tests'})
.css({float: 'left', margin: '4px'})
.bindEvent({click: runTests})
.appendTo(self.$toolbar);
self.$testsLabel = Ox.Label({title: 'Running Tests...'}).hide();
} else {
self.$testsLabel = Ox.Label({title: formatResults()});
}
self.$testsLabel
.css({float: 'left', margin: '4px'})
.appendTo(self.$toolbar);
that.setElement( that.setElement(
self.$panel = Ox.SplitPanel({ self.$panel = Ox.SplitPanel({
elements: [ elements: [
@ -109,7 +112,7 @@ Ox.DocPanel = function(options, self) {
}), function(docItems) { }), function(docItems) {
self.options.items = docItems; self.options.items = docItems;
getExamples(function() { getExamples(function() {
self.$sidebar.replaceElement(0, self.$toolbar); self.$sidebar.replaceElement(1, self.$toolbar);
renderList(); renderList();
self.options.runTests && runTests(); self.options.runTests && runTests();
that.triggerEvent('load', {items: self.options.items}); that.triggerEvent('load', {items: self.options.items});
@ -117,12 +120,19 @@ Ox.DocPanel = function(options, self) {
}); });
} else { } else {
getExamples(function() { getExamples(function() {
self.$sidebar.replaceElement(0, self.$toolbar); self.$sidebar.replaceElement(1, self.$toolbar);
renderList(); renderList();
self.options.runTests && runTests(); self.options.runTests && runTests();
}); });
} }
function formatResults() {
var results = self.options.results[''],
tests = results.passed + results.failed;
return tests + ' test' + (tests == 1 ? '' : 's') + ', '
+ results.passed + ' passed, ' + results.failed + ' failed';
}
function getExamples(callback) { function getExamples(callback) {
var i = 0; var i = 0;
if (self.options.examples && self.options.examples.length) { if (self.options.examples && self.options.examples.length) {
@ -265,7 +275,7 @@ Ox.DocPanel = function(options, self) {
selectItem(data.ids.length ? data.ids[0] : '') selectItem(data.ids.length ? data.ids[0] : '')
} }
}); });
self.$sidebar.replaceElement(1, self.$list); self.$sidebar.replaceElement(0, self.$list);
selectItem(self.options.selected); selectItem(self.options.selected);
} }
@ -288,8 +298,7 @@ Ox.DocPanel = function(options, self) {
self.options.results[key][passed]++; self.options.results[key][passed]++;
}); });
}); });
self.$testsLabel.hide(); self.$testsLabel.options({title: formatResults()});
self.$testsButton.show();
renderList(); renderList();
that.triggerEvent('tests', {results: self.options.results}); that.triggerEvent('tests', {results: self.options.results});
}); });