Commit 1e0c3f49 by Will Daly

Fixup: do not show NaN in student training labels

parent 00d6a0e5
...@@ -79,6 +79,29 @@ describe("OpenAssessment.StudentTrainingListener", function() { ...@@ -79,6 +79,29 @@ describe("OpenAssessment.StudentTrainingListener", function() {
); );
}); });
it("updates the label of an option with invalid points", function() {
// If an option has invalid points, the points will be set to NaN
listener.optionUpdated({
criterionName: "criterion_with_two_options",
name: "option_1",
label: "This is a new label!",
points: NaN
});
// Invalid points should be labeled as such
assertExampleLabels(
listener.examplesOptionsLabels(),
{
criterion_with_two_options: {
"": "Not Scored",
option_1: "This is a new label!",
option_2: "Good - 2 points"
}
}
);
});
it("removes an option and displays an alert", function() { it("removes an option and displays an alert", function() {
// Initial state, set by the fixture // Initial state, set by the fixture
assertExampleLabels( assertExampleLabels(
......
...@@ -39,19 +39,26 @@ OpenAssessment.ItemUtilities = { ...@@ -39,19 +39,26 @@ OpenAssessment.ItemUtilities = {
} }
var singularString = label + " - " + points + " point"; var singularString = label + " - " + points + " point";
var multipleString = label + " - " + points + " points"; var multipleString = label + " - " + points + " points";
// If the option doesn't have a data points value, that indicates to us that it is not a user-specified option, // If the option doesn't have a data points value, that indicates to us that it is not a user-specified option,
// but represents the "Not Selected" option which all criterion drop-downs have. // but represents the "Not Selected" option which all criterion drop-downs have.
if (typeof points === 'undefined') { var finalLabel = "";
$(element).text( if (points === undefined) {
gettext('Not Selected') finalLabel = gettext('Not Selected');
); }
// If the points are invalid, we'll be given NaN
// Don't show this to the user.
else if (isNaN(points)) {
finalLabel = label;
} }
// Otherwise, set the text of the option element to be the properly conjugated, translated string. // Otherwise, set the text of the option element to be the properly conjugated, translated string.
else { else {
$(element).text( finalLabel = ngettext(singularString, multipleString, points);
ngettext(singularString, multipleString, points)
);
} }
$(element).text(finalLabel);
} }
}; };
......
...@@ -22,6 +22,7 @@ OpenAssessment.StudentTrainingListener.prototype = { ...@@ -22,6 +22,7 @@ OpenAssessment.StudentTrainingListener.prototype = {
optionUpdated: function(data) { optionUpdated: function(data) {
var view = this; var view = this;
var sel = '.openassessment_training_example_criterion[data-criterion="' + data.criterionName + '"]'; var sel = '.openassessment_training_example_criterion[data-criterion="' + data.criterionName + '"]';
$(sel, this.element).each( $(sel, this.element).each(
function() { function() {
var criterion = this; var criterion = this;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment