From 3c8017f23ee71da4e15914fbf1e066f69822d4d6 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Sat, 30 Oct 2021 01:14:55 +0200 Subject: [PATCH] JS: Ensure to print status messages for score * If only one response is available, no array will be passed (but rather an Object). The impact of this has been tackled with the changes included --- app/assets/javascripts/editor/evaluation.js | 26 +++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/editor/evaluation.js b/app/assets/javascripts/editor/evaluation.js index 971e91ef..8f79ccf6 100644 --- a/app/assets/javascripts/editor/evaluation.js +++ b/app/assets/javascripts/editor/evaluation.js @@ -67,13 +67,31 @@ CodeOceanEditorEvaluation = { }, printScoringResults: function (response) { + response = (Array.isArray(response)) ? response : [response] + const test_results = response.filter(function(x) { + if (x === undefined || x === null) { + return false; + } + switch (x.file_role) { + case 'teacher_defined_test': + return true; + case 'teacher_defined_linter': + return true; + default: + return false; + } + }); + $('#results ul').first().html(''); - $('.test-count .number').html(response.filter(function(x) { return x && x.file_role === 'teacher_defined_test'; }).length); + $('.test-count .number').html(test_results.length); this.clearOutput(); - _.each(response, function (result, index) { - this.printOutput(result, false, index); - this.printScoringResult(result, index); + _.each(test_results, function (result, index) { + // based on https://stackoverflow.com/questions/8511281/check-if-a-value-is-an-object-in-javascript + if (result === Object(result)) { + this.printOutput(result, false, index); + this.printScoringResult(result, index); + } }.bind(this)); if (_.some(response, function (result) {