port test driver Templates to new syntax

comment out events for now

need #each over an array to work
This commit is contained in:
David Greenspan
2013-07-02 12:40:26 -07:00
parent 7bfa8b9c88
commit 9d79d39124
2 changed files with 225 additions and 216 deletions

View File

@@ -220,108 +220,103 @@ var _testStatus = function(t) {
//// Template - navBars
Template.navBars.running = function() {
countDep.depend();
return running;
};
Template.navBars({
running: function() {
countDep.depend();
return running;
},
passed: function() {
countDep.depend();
return failedCount === 0;
},
total_test_time: function() {
countDep.depend();
Template.navBars.passed = function() {
countDep.depend();
return failedCount === 0;
};
// walk whole tree to get all tests
var walk = function (groups) {
var total = 0;
Template.navBars.total_test_time = function() {
countDep.depend();
_.each(groups || [], function (group) {
_.each(group.tests || [], function (t) {
total += _testTime(t);
});
// walk whole tree to get all tests
var walk = function (groups) {
var total = 0;
_.each(groups || [], function (group) {
_.each(group.tests || [], function (t) {
total += _testTime(t);
total += walk(group.groups);
});
total += walk(group.groups);
});
return total;
};
return total;
};
return walk(resultTree);
};
return walk(resultTree);
}
});
//// Template - progressBar
Template.progressBar.running = function () {
countDep.depend();
return running;
};
Template.progressBar.percentPass = function () {
countDep.depend();
if (totalCount === 0)
return 0;
return 100*passedCount/totalCount;
};
Template.progressBar.totalCount = function () {
countDep.depend();
return totalCount;
};
Template.progressBar.passedCount = function () {
countDep.depend();
return passedCount;
};
Template.progressBar.percentFail = function () {
countDep.depend();
if (totalCount === 0)
return 0;
return 100*failedCount/totalCount;
};
Template.progressBar.anyFail = function () {
countDep.depend();
return failedCount > 0;
};
Template.progressBar.barOuterClass = function () {
return Template.progressBar.running() ? 'progress-striped' : '';
};
Template.progressBar.barInnerClass = function () {
return (Template.progressBar.anyFail() ?
'bar-warning' : 'bar-success');
};
Template.progressBar({
running: function () {
countDep.depend();
return running;
},
percentPass: function () {
countDep.depend();
if (totalCount === 0)
return 0;
return 100*passedCount/totalCount;
},
totalCount: function () {
countDep.depend();
return totalCount;
},
passedCount: function () {
countDep.depend();
return passedCount;
},
percentFail: function () {
countDep.depend();
if (totalCount === 0)
return 0;
return 100*failedCount/totalCount;
},
anyFail: function () {
countDep.depend();
return failedCount > 0;
},
barOuterClass: function () {
return this.running() ? 'progress-striped' : '';
},
barInnerClass: function () {
return (this.anyFail() ?
'bar-warning' : 'bar-success');
}
});
//// Template - groupNav
Template.groupNav.groupPaths = function () {
var groupPath = Session.get("groupPath");
var ret = [];
for (var i = 1; i <= groupPath.length; i++) {
ret.push({path: groupPath.slice(0,i), name: groupPath[i-1]});
Template.groupNav({
groupPaths: function () {
var groupPath = Session.get("groupPath");
var ret = [];
for (var i = 1; i <= groupPath.length; i++) {
ret.push({path: groupPath.slice(0,i), name: groupPath[i-1]});
}
return ret;
},
rerunScheduled: function () {
return Session.get("rerunScheduled");
},
changeToPath: function (path) {
Session.set("groupPath", path);
Session.set("rerunScheduled", true);
// pretend there's just been a hot code push
// so we run the tests completely fresh.
Meteor._reload.reload();
}
return ret;
};
});
Template.groupNav.rerunScheduled = function () {
return Session.get("rerunScheduled");
};
var changeToPath = function (path) {
Session.set("groupPath", path);
Session.set("rerunScheduled", true);
// pretend there's just been a hot code push
// so we run the tests completely fresh.
Meteor._reload.reload();
};
Template.groupNav.events({
// XXXX EVENTS
/*Template.groupNav.events({
"click .group": function () {
changeToPath(this.path);
},
@@ -329,125 +324,136 @@ Template.groupNav.events({
Session.set("rerunScheduled", true);
Meteor._reload.reload();
}
});
});*/
//// Template - failedTests
Template.failedTests.failedTests = function() {
countDep.depend();
return failedTests;
};
Template.failedTests({
failedTests: function() {
countDep.depend();
return failedTests;
}
});
//// Template - testTable
Template.testTable.data = function() {
topLevelGroupsDep.depend();
return resultTree;
};
Template.testTable({
data: function() {
topLevelGroupsDep.depend();
return resultTree;
}
});
//// Template - test_group
Template.test_group.groupDep = function () {
// this template just establishes a dependency. It doesn't actually
// render anything.
this.dep.depend();
return "";
};
Template.test_group({
groupDep: function () {
// this template just establishes a dependency. It doesn't actually
// render anything.
this.dep.depend();
return "";
}
});
// XXXX EVENTS
/*
Template.test_group.events({
"click .groupname": function () {
changeToPath(this.path);
}
});
*/
//// Template - test
Template.test.testDep = function () {
// this template just establishes a dependency. It doesn't actually
// render anything.
this.dep.depend();
return "";
};
Template.test({
testDep: function () {
// this template just establishes a dependency. It doesn't actually
// render anything.
this.dep.depend();
return "";
},
Template.test.test_status_display = function() {
var status = _testStatus(this);
if (status == "failed") {
return "FAIL";
} else if (status == "succeeded") {
return "PASS";
} else {
return "waiting...";
test_status_display: function() {
var status = _testStatus(this);
if (status == "failed") {
return "FAIL";
} else if (status == "succeeded") {
return "PASS";
} else {
return "waiting...";
}
},
test_time_display: function() {
var time = _testTime(this);
return (typeof time === "number") ? time + " ms" : "";
},
test_class: function() {
var events = this.events || [];
var classes = [_testStatus(this)];
if (this.expanded) {
classes.push("expanded");
} else {
classes.push("collapsed");
}
return classes.join(' ');
},
eventsArray: function() {
var events = _.filter(this.events, function(e) {
return e.type != "finish";
});
var partitionBy = function(seq, func) {
var result = [];
var lastValue = {};
_.each(seq, function(x) {
var newValue = func(x);
if (newValue === lastValue) {
result[result.length-1].push(x);
} else {
lastValue = newValue;
result.push([x]);
}
});
return result;
};
var dupLists = partitionBy(
_.map(events, function(e) {
// XXX XXX We need something better than stringify!
// stringify([undefined]) === "[null]"
e = _.clone(e);
delete e.sequence;
return {obj: e, str: JSON.stringify(e)};
}), function(x) { return x.str; });
return _.map(dupLists, function(L) {
var obj = L[0].obj;
return (L.length > 1) ? _.extend({times: L.length}, obj) : obj;
});
}
};
});
Template.test.test_time_display = function() {
var time = _testTime(this);
return (typeof time === "number") ? time + " ms" : "";
};
Template.test.test_class = function() {
var events = this.events || [];
var classes = [_testStatus(this)];
if (this.expanded) {
classes.push("expanded");
} else {
classes.push("collapsed");
}
return classes.join(' ');
};
Template.test.events({
// XXXX EVENTS
/*Template.test.events({
'click .testname': function() {
this.expanded = ! this.expanded;
this.dep.changed();
}
});
Template.test.eventsArray = function() {
var events = _.filter(this.events, function(e) {
return e.type != "finish";
});
var partitionBy = function(seq, func) {
var result = [];
var lastValue = {};
_.each(seq, function(x) {
var newValue = func(x);
if (newValue === lastValue) {
result[result.length-1].push(x);
} else {
lastValue = newValue;
result.push([x]);
}
});
return result;
};
var dupLists = partitionBy(
_.map(events, function(e) {
// XXX XXX We need something better than stringify!
// stringify([undefined]) === "[null]"
e = _.clone(e);
delete e.sequence;
return {obj: e, str: JSON.stringify(e)};
}), function(x) { return x.str; });
return _.map(dupLists, function(L) {
var obj = L[0].obj;
return (L.length > 1) ? _.extend({times: L.length}, obj) : obj;
});
};
});*/
//// Template - event
// XXXX EVENTS
/*
Template.event.events({
'click .debug': function () {
// the way we manage groupPath, shortName, cookies, etc, is really
@@ -456,48 +462,50 @@ Template.event.events({
test: this.cookie.shortName});
Meteor._debugTest(this.cookie, reportResults);
}
});
});*/
Template.event.get_details = function() {
Template.event({
get_details: function() {
var prepare = function(details) {
return _.compact(_.map(details, function(val, key) {
var prepare = function(details) {
return _.compact(_.map(details, function(val, key) {
// You can end up with a an undefined value, e.g. using
// isNull without providing a message attribute: isNull(1).
// No need to display those.
if (!_.isUndefined(val)) {
return {
key: key,
val: val
};
} else {
return undefined;
}
}));
};
var details = this.details;
if (! details) {
return null;
} else {
var type = details.type;
var stack = details.stack;
details = _.clone(details);
delete details.type;
delete details.stack;
return {
type: type,
stack: stack,
details: prepare(details)
// You can end up with a an undefined value, e.g. using
// isNull without providing a message attribute: isNull(1).
// No need to display those.
if (!_.isUndefined(val)) {
return {
key: key,
val: val
};
} else {
return undefined;
}
}));
};
}
};
Template.event.is_debuggable = function() {
return !!this.cookie;
};
var details = this.details;
if (! details) {
return null;
} else {
var type = details.type;
var stack = details.stack;
details = _.clone(details);
delete details.type;
delete details.stack;
return {
type: type,
stack: stack,
details: prepare(details)
};
}
},
is_debuggable: function() {
return !!this.cookie;
}
});

View File

@@ -13,7 +13,8 @@ Package.on_use(function (api) {
api.use('session');
api.use(['ui', 'livedata', 'deps'], 'client');
api.use(['ui', 'templating', 'spacebars',
'livedata', 'deps'], 'client');
api.add_files([
'driver.css',