Commit 70510333 by Will Daly

Merge pull request #603 from edx/will/authoring-read-data-fix

Correctly update the label for student training if called multiple times
parents bb8bb0cd 216a6987
...@@ -45,7 +45,7 @@ describe("OpenAssessment.StudentTrainingListener", function() { ...@@ -45,7 +45,7 @@ describe("OpenAssessment.StudentTrainingListener", function() {
listener = new OpenAssessment.StudentTrainingListener(); listener = new OpenAssessment.StudentTrainingListener();
}); });
it("updates the label of an option", function() { it("updates the label and points of an option", function() {
// Initial state, set by the fixture // Initial state, set by the fixture
assertExampleLabels( assertExampleLabels(
listener.examplesOptionsLabels(), listener.examplesOptionsLabels(),
...@@ -79,6 +79,48 @@ describe("OpenAssessment.StudentTrainingListener", function() { ...@@ -79,6 +79,48 @@ describe("OpenAssessment.StudentTrainingListener", function() {
); );
}); });
it("updates an option twice", function() {
// Initial state, set by the fixture
assertExampleLabels(
listener.examplesOptionsLabels(),
{
criterion_with_two_options: {
"": "Not Selected",
option_1: "Fair - 1 points",
option_2: "Good - 2 points"
}
}
);
// Update the option label and points,
listener.optionUpdated({
criterionName: "criterion_with_two_options",
name: "option_1",
label: "This is a new label!",
points: 42
});
// Update the option again
listener.optionUpdated({
criterionName: "criterion_with_two_options",
name: "option_1",
label: "This is YET ANOTHER label!",
points: 18
});
// Verify the final state
assertExampleLabels(
listener.examplesOptionsLabels(),
{
criterion_with_two_options: {
"": "Not Selected",
option_1: "This is YET ANOTHER label! - 18 points",
option_2: "Good - 2 points"
}
}
);
});
it("updates the label of an option with invalid points", 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 // If an option has invalid points, the points will be set to NaN
listener.optionUpdated({ listener.optionUpdated({
......
...@@ -31,8 +31,8 @@ OpenAssessment.ItemUtilities = { ...@@ -31,8 +31,8 @@ OpenAssessment.ItemUtilities = {
element (Jquery Element): The element that represents the object. element (Jquery Element): The element that represents the object.
**/ **/
refreshOptionString: function(element) { refreshOptionString: function(element) {
var points = $(element).data('points'); var points = $(element).attr('data-points');
var label = $(element).data('label'); var label = $(element).attr('data-label');
var name = $(element).val(); var name = $(element).val();
// We don't want the lack of a label to make it look like - 1 points. // We don't want the lack of a label to make it look like - 1 points.
if (label === ""){ if (label === ""){
......
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