- improved test app

- defined new tests
This commit is contained in:
Sefa Ilkimen
2017-10-13 16:30:48 +02:00
parent 6f210a70fb
commit 7037fd2fa7
4 changed files with 85 additions and 22 deletions
+30 -10
View File
@@ -5,35 +5,53 @@ const app = {
document.getElementById('nextBtn').addEventListener('click', app.onNextBtnClick);
},
print: function(prefix, content) {
const text = '\n' + prefix + ': ' + JSON.stringify(content);
printResult: function(prefix, content) {
const text = prefix + ': ' + JSON.stringify(content);
document.getElementById('resultTextarea').value += text;
},
reject: function(content) {
app.print('result - rejected', content);
app.printResult('result - rejected', content);
},
resolve: function(content) {
app.print('result - resolved', content);
app.printResult('result - resolved', content);
},
runTest: function(index) {
const testDefinition = tests[index];
const titleText = app.testIndex + ': ' + testDefinition.description;
const resultText = 'expectation - ' + testDefinition.expected;
const expectedText = 'expected - ' + testDefinition.expected;
document.getElementById('resultTextarea').value = resultText;
document.getElementById('expectedTextarea').value = expectedText;
document.getElementById('resultTextarea').value = '';
document.getElementById('descriptionLbl').innerText = titleText;
testDefinition.func(index);
testDefinition.func(app.resolve, app.reject);
},
onBeforeTest: function(testIndex, cb) {
if (hooks && hooks.onBeforeEachTest) {
return hooks.onBeforeEachTest(function() {
const testDefinition = tests[testIndex];
if (testDefinition.before) {
testDefinition.before(cb);
} else {
cb();
}
});
} else {
cb();
}
},
onFinishedAllTests: function() {
const titleText = 'No more tests';
const resultText = 'You have run all available tests.';
const expectedText = 'You have run all available tests.';
document.getElementById('resultTextarea').value = resultText;
document.getElementById('expectedTextarea').value = expectedText;
document.getElementById('resultTextarea').value = '';
document.getElementById('descriptionLbl').innerText = titleText;
},
@@ -41,7 +59,9 @@ const app = {
app.testIndex += 1;
if (app.testIndex < tests.length) {
app.runTest(app.testIndex);
app.onBeforeTest(app.testIndex, function() {
app.runTest(app.testIndex);
});
} else {
app.onFinishedAllTests();
}