Commit a886d1b3 by gradyward

Merge pull request #581 from edx/grady/ORA-767

Fixes ORA 767
parents dab8db7a e4afa2d4
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
{{ criterion.label }} {{ criterion.label }}
</div> </div>
<select class="openassessment_training_example_criterion_option setting-input" data-criterion="{{ criterion.name }}" data-option="{{ option.name }}"> <select class="openassessment_training_example_criterion_option setting-input" data-criterion="{{ criterion.name }}" data-option="{{ option.name }}">
<option value="">{% trans "Not Scored" %}</option> <option value="">{% trans "Not Selected" %}</option>
{% for option in criterion.options %} {% for option in criterion.options %}
<option value="{{ option.name }}" data-points="{{ option.points }}" data-label="{{ option.label }}" <option value="{{ option.name }}" data-points="{{ option.points }}" data-label="{{ option.label }}"
{% if criterion.option_selected == option.name %} selected {% endif %} {% if criterion.option_selected == option.name %} selected {% endif %}
......
...@@ -51,7 +51,7 @@ describe("OpenAssessment.StudentTrainingListener", function() { ...@@ -51,7 +51,7 @@ describe("OpenAssessment.StudentTrainingListener", function() {
listener.examplesOptionsLabels(), listener.examplesOptionsLabels(),
{ {
criterion_with_two_options: { criterion_with_two_options: {
"": "Not Scored", "": "Not Selected",
option_1: "Fair - 1 points", option_1: "Fair - 1 points",
option_2: "Good - 2 points" option_2: "Good - 2 points"
} }
...@@ -71,7 +71,7 @@ describe("OpenAssessment.StudentTrainingListener", function() { ...@@ -71,7 +71,7 @@ describe("OpenAssessment.StudentTrainingListener", function() {
listener.examplesOptionsLabels(), listener.examplesOptionsLabels(),
{ {
criterion_with_two_options: { criterion_with_two_options: {
"": "Not Scored", "": "Not Selected",
option_1: "This is a new label! - 42 points", option_1: "This is a new label! - 42 points",
option_2: "Good - 2 points" option_2: "Good - 2 points"
} }
...@@ -93,7 +93,7 @@ describe("OpenAssessment.StudentTrainingListener", function() { ...@@ -93,7 +93,7 @@ describe("OpenAssessment.StudentTrainingListener", function() {
listener.examplesOptionsLabels(), listener.examplesOptionsLabels(),
{ {
criterion_with_two_options: { criterion_with_two_options: {
"": "Not Scored", "": "Not Selected",
option_1: "This is a new label!", option_1: "This is a new label!",
option_2: "Good - 2 points" option_2: "Good - 2 points"
} }
...@@ -108,7 +108,7 @@ describe("OpenAssessment.StudentTrainingListener", function() { ...@@ -108,7 +108,7 @@ describe("OpenAssessment.StudentTrainingListener", function() {
listener.examplesOptionsLabels(), listener.examplesOptionsLabels(),
{ {
criterion_with_two_options: { criterion_with_two_options: {
"": "Not Scored", "": "Not Selected",
option_1: "Fair - 1 points", option_1: "Fair - 1 points",
option_2: "Good - 2 points" option_2: "Good - 2 points"
} }
...@@ -127,7 +127,7 @@ describe("OpenAssessment.StudentTrainingListener", function() { ...@@ -127,7 +127,7 @@ describe("OpenAssessment.StudentTrainingListener", function() {
listener.examplesOptionsLabels(), listener.examplesOptionsLabels(),
{ {
criterion_with_two_options: { criterion_with_two_options: {
"": "Not Scored", "": "Not Selected",
option_2: "Good - 2 points" option_2: "Good - 2 points"
} }
} }
...@@ -219,12 +219,12 @@ describe("OpenAssessment.StudentTrainingListener", function() { ...@@ -219,12 +219,12 @@ describe("OpenAssessment.StudentTrainingListener", function() {
listener.examplesOptionsLabels(), listener.examplesOptionsLabels(),
{ {
criterion_with_two_options: { criterion_with_two_options: {
"": "Not Scored", "": "Not Selected",
option_1: "Fair - 1 points", option_1: "Fair - 1 points",
option_2: "Good - 2 points", option_2: "Good - 2 points",
}, },
new_criterion: { new_criterion: {
"": "Not Scored", "": "Not Selected",
new_option: "This is a new option! - 56 points" new_option: "This is a new option! - 56 points"
} }
} }
...@@ -241,12 +241,12 @@ describe("OpenAssessment.StudentTrainingListener", function() { ...@@ -241,12 +241,12 @@ describe("OpenAssessment.StudentTrainingListener", function() {
listener.examplesOptionsLabels(), listener.examplesOptionsLabels(),
{ {
criterion_with_two_options: { criterion_with_two_options: {
"": "Not Scored", "": "Not Selected",
option_1: "Fair - 1 points", option_1: "Fair - 1 points",
option_2: "Good - 2 points", option_2: "Good - 2 points",
}, },
new_criterion: { new_criterion: {
"": "Not Scored", "": "Not Selected",
new_option: "This is a new option! - 56 points", new_option: "This is a new option! - 56 points",
yet_another_option: "This is yet another option! - 27 points" yet_another_option: "This is yet another option! - 27 points"
} }
...@@ -341,3 +341,135 @@ describe("OpenAssessment.AssessmentToggleListener", function() { ...@@ -341,3 +341,135 @@ describe("OpenAssessment.AssessmentToggleListener", function() {
expect(alert.isVisible()).toBe(false); expect(alert.isVisible()).toBe(false);
}); });
}); });
describe("OpenAssessment.StudentTrainingListenerWithTrainingExamples", function() {
var listener = null;
var view = null;
/**
Check that all student training examples have the expected
criteria or option labels.
Args:
actual (array): A list of example criteria or option labels
(object literals) retrieved from the DOM.
expected (object literal): The expected value for each example.
numExamples (int, optional): The number of student training examples
(defaults to 1).
**/
var assertExampleLabels = function(actual, expected, numExamples) {
// The most common case is one example, so use that as a default.
if (typeof(numExamples) == "undefined") {
numExamples = 1;
}
// Add one to the number of examples to include the client-side template.
expect(actual.length).toEqual(numExamples + 1);
// Verify that each example matches what we expect.
// Since there is only one rubric for the problem,
// the training examples should always match that rubric.
for (var index in actual) {
for (var criterionName in expected) {
expect(actual[index][criterionName]).toEqual(expected[criterionName]);
}
}
};
beforeEach(function() {
loadFixtures('oa_edit_student_training.html');
listener = new OpenAssessment.StudentTrainingListener();
view = new OpenAssessment.EditStudentTrainingView('#oa_student_training_editor');
});
it("adds a criterion and an option, then adds a training example", 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"
}
}
);
// Sets the option number to a number greater than one to prevent case conflicts
// (which are reliant on pieces of code not being tested here)
listener.optionUpdated({
criterionName: 'criterion_with_two_options',
name: 'option_1',
label: 'Fair',
points: '2'
});
assertExampleLabels(
listener.examplesOptionsLabels(),
{
criterion_with_two_options: {
"": "Not Selected",
option_1: "Fair - 2 points",
option_2: "Good - 2 points"
}
}
);
// Adds a criterion
listener.criterionAdd({
criterionName: "new_criterion",
label: "This is a new criterion!"
});
// Add an option to the criterion
listener.optionAdd({
criterionName: "new_criterion",
name: "new_option",
label: "This is a new option!",
points: 56
});
assertExampleLabels(
listener.examplesOptionsLabels(),
{
criterion_with_two_options: {
"": "Not Selected",
option_1: "Fair - 2 points",
option_2: "Good - 2 points",
},
new_criterion: {
"": "Not Selected",
new_option: "This is a new option! - 56 points"
}
}
);
// Adds a student training example
view.addTrainingExample();
var options = listener.examplesOptionsLabels();
// Asserts that the example labels are the same for the student training example
// and in doing so, checks that all changes were made to the studnet training template.
assertExampleLabels(
options,
{
criterion_with_two_options: {
"": "Not Selected",
option_1: "Fair - 2 points",
option_2: "Good - 2 points",
},
new_criterion: {
"": "Not Selected",
new_option: "This is a new option! - 56 points"
}
},
2
);
});
});
\ No newline at end of file
...@@ -33,6 +33,7 @@ OpenAssessment.ItemUtilities = { ...@@ -33,6 +33,7 @@ OpenAssessment.ItemUtilities = {
refreshOptionString: function(element) { refreshOptionString: function(element) {
var points = $(element).data('points'); var points = $(element).data('points');
var label = $(element).data('label'); var label = $(element).data('label');
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 === ""){
label = gettext('Unnamed Option'); label = gettext('Unnamed Option');
...@@ -40,10 +41,11 @@ OpenAssessment.ItemUtilities = { ...@@ -40,10 +41,11 @@ 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's name value is the empty string, 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. This is an acceptable
// assumption because we require name (option value) to be a unique identifier for each option.
var finalLabel = ""; var finalLabel = "";
if (points === undefined) { if (name === '') {
finalLabel = gettext('Not Selected'); finalLabel = gettext('Not Selected');
} }
...@@ -486,15 +488,6 @@ OpenAssessment.TrainingExample = function(element){ ...@@ -486,15 +488,6 @@ OpenAssessment.TrainingExample = function(element){
this.element = element; this.element = element;
this.criteria = $(".openassessment_training_example_criterion_option", this.element); this.criteria = $(".openassessment_training_example_criterion_option", this.element);
this.answer = $('.openassessment_training_example_essay', this.element).first(); this.answer = $('.openassessment_training_example_essay', this.element).first();
// Initialize the option label in the training example for each option.
this.criteria.each(
function () {
$('option', this).each(function(){
OpenAssessment.ItemUtilities.refreshOptionString($(this));
});
}
);
}; };
OpenAssessment.TrainingExample.prototype = { OpenAssessment.TrainingExample.prototype = {
...@@ -520,7 +513,14 @@ OpenAssessment.TrainingExample.prototype = { ...@@ -520,7 +513,14 @@ OpenAssessment.TrainingExample.prototype = {
}; };
}, },
addHandler: function() {}, addHandler: function() {
// Goes through and instantiates the option description in the training example for each option.
$(".openassessment_training_example_criterion_option", this.element) .each( function () {
$('option', this).each(function(){
OpenAssessment.ItemUtilities.refreshOptionString($(this));
});
});
},
addEventListeners: function() {}, addEventListeners: function() {},
removeHandler: function() {}, removeHandler: function() {},
updateHandler: function() {}, updateHandler: function() {},
......
...@@ -516,6 +516,14 @@ OpenAssessment.EditStudentTrainingView.prototype = { ...@@ -516,6 +516,14 @@ OpenAssessment.EditStudentTrainingView.prototype = {
this.clearValidationErrors(); this.clearValidationErrors();
}); });
}, },
/**
Adds a new training example by copying the training example template.
Primarily used for testing.
**/
addTrainingExample: function() {
this.exampleContainer.add();
}
}; };
/** /**
......
...@@ -24,8 +24,8 @@ OpenAssessment.StudentTrainingListener.prototype = { ...@@ -24,8 +24,8 @@ OpenAssessment.StudentTrainingListener.prototype = {
function() { function() {
var criterion = this; var criterion = this;
var option = $('option[value="' + data.name + '"]', criterion) var option = $('option[value="' + data.name + '"]', criterion)
.data("points", data.points) .attr("data-points", data.points)
.data("label", data.label); .attr("data-label", data.label);
OpenAssessment.ItemUtilities.refreshOptionString(option); OpenAssessment.ItemUtilities.refreshOptionString(option);
} }
); );
...@@ -62,8 +62,8 @@ OpenAssessment.StudentTrainingListener.prototype = { ...@@ -62,8 +62,8 @@ OpenAssessment.StudentTrainingListener.prototype = {
// but this avoids overly complex templating code. // but this avoids overly complex templating code.
var option = $("<option></option>") var option = $("<option></option>")
.attr("value", data.name) .attr("value", data.name)
.data("points", data.points) .attr("data-points", data.points)
.data("label", data.label); .attr("data-label", data.label);
// Sets the option's text description, and adds it to the criterion. // Sets the option's text description, and adds it to the criterion.
OpenAssessment.ItemUtilities.refreshOptionString(option); OpenAssessment.ItemUtilities.refreshOptionString(option);
......
...@@ -9,7 +9,7 @@ git+https://github.com/edx/xblock-sdk.git@643900aadcb18aaeb7fe67271ca9dbf36e463e ...@@ -9,7 +9,7 @@ git+https://github.com/edx/xblock-sdk.git@643900aadcb18aaeb7fe67271ca9dbf36e463e
edx-submissions==0.0.6 edx-submissions==0.0.6
# Third Party Requirements # Third Party Requirements
boto>=2.13.0,<3.0.0 boto>=2.30.0,<3.0.0
celery==3.0.19 celery==3.0.19
defusedxml==0.4.1 defusedxml==0.4.1
dogapi==1.2.1 dogapi==1.2.1
......
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