Skip to content

Commit

Permalink
Normalize message for unanswered custom problems.
Browse files Browse the repository at this point in the history
When a custom problem is not answered the validator is expected to
return an empty string result. The score is then marked as empty.
The special empty string is now converted to null right away, rather
than being passed as a message further into the framework.

This makes custom exercises display "more parts to answer" when a
user just clicks "Check Answer" without doing anything.
  • Loading branch information
wrwrwr committed Nov 22, 2015
1 parent 2630d00 commit f8eb84f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions test/answer-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,29 @@
start();
});

asyncTest("custom", 9, function() {
setupSolutionArea();
var $problem = jQuery("#qunit-fixture .problem").append(
"<div class='solution' data-type='custom'>" +
"<div class='instruction'>" +
"<input type='text' id='custom-input'>" +
"</div>" +
"<div class='guess'>$('#custom-input').val()</div>" +
"<div class='validator-function'>" +
"return guess == 'empty' ? '' : guess == 5;" +
"</div>" +
"</div>"
);

var answerData = Khan.answerTypes.custom.setup($("#solutionarea"),
$problem.children(".solution"));

testAnswer(answerData, "5", "right", "right answer is right");
testAnswer(answerData, "empty", "empty", "empty answer is empty");
testAnswer(answerData, "1", "wrong", "wrong answer is wrong");

start();
});

asyncTest("prime factorization", 24, function() {
setupSolutionArea();
Expand Down
2 changes: 1 addition & 1 deletion utils/answer-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -1877,7 +1877,7 @@ Khan.answerTypes = $.extend(Khan.answerTypes, {
return {
empty: pass === "",
correct: pass === true,
message: typeof pass === "string" ? pass : null,
message: typeof pass === "string" && pass !== "" ? pass : null,
guess: guess
};
}
Expand Down

0 comments on commit f8eb84f

Please sign in to comment.