Show tests on html view

This commit is contained in:
Nathan Leniz
2015-02-14 18:31:32 -05:00
parent 693b8fbb33
commit 9ac19023d9
4 changed files with 29 additions and 23 deletions

View File

@@ -59,11 +59,14 @@ editor.on("change", function () {
});
var nodeEnv = prodOrDev === 'production' ? 'http://www.freecodecamp.com' : 'http://localhost:3001';
function updatePreview() {
goodTests = 0;
var previewFrame = document.getElementById('preview');
var preview = previewFrame.contentDocument || previewFrame.contentWindow.document;
preview.open();
$('#testSuite').empty();
preview.write(libraryIncludes + editor.getValue() + otherTestsForNow);
preview.close();
}
setTimeout(updatePreview, 300);
@@ -71,17 +74,27 @@ setTimeout(updatePreview, 300);
* "post" methods
*/
var postSuccess = function() {
showCompletion();
var postSuccess = function(data) {
var testDoc = document.createElement("div");
$(testDoc)
.html("<div class='row'><div class='col-xs-2 text-center'><i class='ion-checkmark-circled big-success-icon'></i></div><div class='col-xs-10 test-output test-vertical-center wrappable'>" + JSON.parse(data) + "</div></div><div class='ten-pixel-break'/>")
.appendTo($('#testSuite'));
testSuccess();
};
var postError = function(data) {
console.log(Object.keys(data));
var testDoc = document.createElement("div");
$(testDoc)
.html("<div class='row'><div class='col-xs-1 text-center'><i class='ion-close-circled big-error-icon'></i></div><div class='col-xs-11 test-output wrappable'>" + data + "</div></div><div class='ten-pixel-break'/>")
.html("<div class='row'><div class='col-xs-2 text-center'><i class='ion-close-circled big-error-icon'></i></div><div class='col-xs-10 test-output wrappable'>" + JSON.parse(data) + "</div></div><div class='ten-pixel-break'/>")
.prependTo($('#testSuite'))
};
var goodTests = 0;
var testSuccess = function() {
goodTests++;
if (goodTests === tests.length) {
showCompletion();
}
};
var challengeSeed = challengeSeed || null;
var tests = tests || [];
var allSeeds = '';
@@ -116,7 +129,7 @@ function doLinting () {
});
};
//$('#testSuite').empty();
function showCompletion() {
var time = Math.floor(Date.now() / 1000) - started;
ga('send', 'event', 'Challenge', 'solved', challengeName + ', Time: ' + time);