From b91583930550b4eabf6451d08f74cf7d3b44147f Mon Sep 17 00:00:00 2001 From: rolux Date: Tue, 12 Jun 2012 17:24:58 +0200 Subject: [PATCH] display test stats --- source/Ox.UI/js/Code/DocPanel.js | 49 +++++++++++++++++++------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/source/Ox.UI/js/Code/DocPanel.js b/source/Ox.UI/js/Code/DocPanel.js index bf030714..cfa57847 100644 --- a/source/Ox.UI/js/Code/DocPanel.js +++ b/source/Ox.UI/js/Code/DocPanel.js @@ -61,29 +61,32 @@ Ox.DocPanel = function(options, self) { } }); - if (!self.options.results) { - 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.$toolbar = Ox.Bar({size: 24}); self.$list = Ox.Element(); self.$sidebar = Ox.SplitPanel({ elements: [ - {element: Ox.Element(), size: 24}, - {element: Ox.Element()} + {element: Ox.Element()}, + {element: Ox.Element(), size: 24} ], orientation: 'vertical' }); 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( self.$panel = Ox.SplitPanel({ elements: [ @@ -109,7 +112,7 @@ Ox.DocPanel = function(options, self) { }), function(docItems) { self.options.items = docItems; getExamples(function() { - self.$sidebar.replaceElement(0, self.$toolbar); + self.$sidebar.replaceElement(1, self.$toolbar); renderList(); self.options.runTests && runTests(); that.triggerEvent('load', {items: self.options.items}); @@ -117,12 +120,19 @@ Ox.DocPanel = function(options, self) { }); } else { getExamples(function() { - self.$sidebar.replaceElement(0, self.$toolbar); + self.$sidebar.replaceElement(1, self.$toolbar); renderList(); 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) { var i = 0; if (self.options.examples && self.options.examples.length) { @@ -265,7 +275,7 @@ Ox.DocPanel = function(options, self) { selectItem(data.ids.length ? data.ids[0] : '') } }); - self.$sidebar.replaceElement(1, self.$list); + self.$sidebar.replaceElement(0, self.$list); selectItem(self.options.selected); } @@ -288,8 +298,7 @@ Ox.DocPanel = function(options, self) { self.options.results[key][passed]++; }); }); - self.$testsLabel.hide(); - self.$testsButton.show(); + self.$testsLabel.options({title: formatResults()}); renderList(); that.triggerEvent('tests', {results: self.options.results}); });