Skip to content

Commit

Permalink
CTP-3783 adapt behat to commit c1132f6
Browse files Browse the repository at this point in the history
  • Loading branch information
watson8 committed Oct 7, 2024
1 parent 71b27fc commit a63f597
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 73 deletions.
10 changes: 8 additions & 2 deletions classes/controllers/feedback_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,14 @@ protected function new_feedback() {
}

$ability = new ability(user::find($USER), $this->coursework);
$ability->require_can('new', $teacherfeedback);

if (!$ability->can('new', $teacherfeedback)) {
if ($this->params['ajax']) {
echo json_encode(['success' => false, 'message' => $ability->get_last_message()]);
die();
} else {
throw new access_denied($this->coursework, $ability->get_last_message());
}
}
$this->check_stage_permissions($this->params['stage_identifier']);

$urlparams = [];
Expand Down
7 changes: 0 additions & 7 deletions classes/models/outstanding_marking.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@

class outstanding_marking {

private $dayinsecs;

public function __construct() {

$this->day_in_secs = 86400;
}

/**
* @param $cwkrecord
* @param $userid
Expand Down
63 changes: 33 additions & 30 deletions datatables/js/edit_datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,41 +727,44 @@ $(document).ready(function () {
}).done(function(response) {
response = $.parseJSON(response);
var modalbody = $('#modal-grading').find('.modal-body');
modalbody.html(response.formhtml);
var filemanager = modalbody.find('.filemanager');
if (response.filemanageroptions && filemanager.length) {
var elementid = filemanager.attr('id');
var clientid = elementid.substr(12);
if (clientid) {
response.filemanageroptions.client_id = clientid;
M.form_filemanager.init(Y, response.filemanageroptions);
// Careful as not all requests return a response.success value. Only if it's false, show error.
if ((response.success ?? true) === false && (response.message ?? null)) {
modalbody.html(response.message);
} else {
modalbody.html(response.formhtml);
var filemanager = modalbody.find('.filemanager');
if (response.filemanageroptions && filemanager.length) {
var elementid = filemanager.attr('id');
var clientid = elementid.substr(12);
if (clientid) {
response.filemanageroptions.client_id = clientid;
M.form_filemanager.init(Y, response.filemanageroptions);
}
}
}
if (response.editoroptions) {
require(['editor_tiny/editor'], (Tiny) => {
Tiny.setupForElementId({
elementId: 'id_feedbackcomment',
options: JSON.parse(response.editoroptions),
if (response.editoroptions) {
require(['editor_tiny/editor'], (Tiny) => {
Tiny.setupForElementId({
elementId: 'id_feedbackcomment',
options: JSON.parse(response.editoroptions),
});
});
});
}

if (response.commentoptions) {
M.util.js_pending('gradingform_guide/comment_chooser');
require(['gradingform_guide/comment_chooser'], function(amd) {
$(".remark").each( function (i,ele) {
buttonele = $(ele).find(".commentchooser");
textele = $(ele).find(".markingguideremark");

buttonid = $(buttonele).attr("id");
textid = $(textele).attr("id");
}

amd.initialise(1, buttonid, textid, response.commentoptions) ;
M.util.js_complete('gradingform_guide/comment_chooser');
if (response.commentoptions) {
M.util.js_pending('gradingform_guide/comment_chooser');
require(['gradingform_guide/comment_chooser'], function(amd) {
$(".remark").each( function (i,ele) {
buttonele = $(ele).find(".commentchooser");
textele = $(ele).find(".markingguideremark");
buttonid = $(buttonele).attr("id");
textid = $(textele).attr("id");
amd.initialise(1, buttonid, textid, response.commentoptions);
M.util.js_complete('gradingform_guide/comment_chooser');

})
})

});
});
}
}
});
var cell_td = $(this).closest('td');
Expand Down
10 changes: 8 additions & 2 deletions tests/behat/behat_mod_coursework.php
Original file line number Diff line number Diff line change
Expand Up @@ -1992,7 +1992,7 @@ public function there_is_final_feedback() {
}

/**
* @Given /^there is final feedback from the other teacher$/
* @Given /^there is final feedback from the other teacher with grade 45$/
*/
public function there_is_final_feedback_from_the_other_teacher() {
$generator = $this->get_coursework_generator();
Expand Down Expand Up @@ -2169,7 +2169,7 @@ public function i_should_see_the_final_single_grade_on_the_page($grade = 56) {
}

/**
* @Given /^I have an assessor feedback$/
* @Given /^I have an assessor feedback at grade 67$/
*/
public function i_have_an_assessor_feedback() {
/**
Expand All @@ -2191,6 +2191,10 @@ public function i_have_an_assessor_feedback() {
* @param string $expectedvalue
*/
public function i_should_see_the_grade_comment_in_the_form_on_the_page($expectedvalue = 'New comment here') {
// Since commit c1132f6, feedback comments editing has happened from AJAX form.
// Tests were not updated for this so add a wait to enable form to load before we check.
$this->wait_for_pending_js();
$this->wait_for_seconds(2);
$commentfield = $this->find('css', '#feedback_comment');
if ($commentfield->getValue() != $expectedvalue) {
throw new ExpectationException("Expected comment $expectedvalue got " . $commentfield->getValue(), $this->getSession());
Expand Down Expand Up @@ -2250,6 +2254,8 @@ public function i_should_see_the_rubric_grade_on_the_page() {
* @throws Behat\Mink\Exception\ElementNotFoundException
*/
public function i_grade_the_submission_using_the_simple_form($grade = 56, $withoutcomments=false) {
$this->wait_for_pending_js();
$this->wait_for_seconds(2);
$nodeelement = $this->getSession()->getPage()->findById('feedback_grade');
if ($nodeelement) {
$nodeelement->selectOption($grade);
Expand Down
45 changes: 29 additions & 16 deletions tests/behat/feedback_collisions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,52 @@ Feature: Collisions: two people try to create feedback at the same time
And the student has a submission
And the submission is finalised

Scenario: Single marker: If I submit feedback and it's already been given then the form should reload with a warning
@javascript
Scenario: Single marker: If I submit feedback and it's already been given then the form should show a warning
Given there is a teacher
And there is another teacher
And I am logged in as the other teacher
And the coursework is set to single marker
When I visit the coursework page
And I have an assessor feedback at grade 67
And I click the new single final feedback button for the student
And I have an assessor feedback
When I grade the submission using the simple form
Then I should be on the create feedback page
And I should see "has already submitted"
Then I should see the grade comment in the form on the page
And I should see the grade in the form on the page
And I should see "Allocatable already has feedback for this stage"

@javascript
Scenario: Multiple marker: If I submit feedback and it's already been given then it should be given a new stage_identifier
Given there is a teacher
And there is another teacher
And I am logged in as the other teacher
And the coursework is set to double marker
And I have an assessor feedback at grade 67
When I visit the coursework page
And I click on the new feedback button for assessor 1
And I have an assessor feedback
When I grade the submission using the simple form
Then I should be on the coursework page
# Expand the row.
When I click on ".details-control" "css_element"
And I wait until the page is ready
And I wait "2" seconds
And I click on "New feedback" "link"
And I wait until the page is ready
And I wait "1" seconds
And I set the field "Grade" to "56"
And I set the field "Comment" to "Some comment 1"
And I wait "2" seconds
And I click on "Save and finalise" "button"
And I should see "Your data has been saved."

@javascript
Scenario: Multiple marker: If I submit feedback and it's already been given by all teachers then it should fail
Given there is a teacher
And there is another teacher
And I am logged in as a manager
And the coursework is set to double marker
When I visit the coursework page
And I click on the new feedback button for assessor 1
And I have an assessor feedback
And there is final feedback from the other teacher
When I grade the submission using the simple form
Then I should be on the create feedback page
And I have an assessor feedback at grade 67
And there is final feedback from the other teacher with grade 45
# Expand the row.
When I click on ".details-control" "css_element"
And I wait until the page is ready
And I wait "2" seconds
And I click on "New feedback" "link"
And I wait until the page is ready
And I wait "2" seconds
And I should see "Allocatable already has feedback for this stage"
54 changes: 40 additions & 14 deletions tests/behat/feedback_final_feedback_double_marking.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@mod @mod_coursework
@mod @mod_coursework @mod_coursework_feedback_final_feedback_double_marking
Feature: Adding and editing final feedback

In order to provide students with a fair final grade that combines the component grades
Expand All @@ -15,42 +15,68 @@ Feature: Adding and editing final feedback
And the student has a submission
And the submission is finalised

@javascript
Scenario: Setting the final feedback grade
Given there are feedbacks from both teachers
And I am logged in as a manager
And I visit the coursework page
When I click the new multiple final feedback button for the student
When I grade the submission using the simple form
Then I should be on the coursework page
And I should see the final grade on the multiple marker page
# Form loaded and sent by AJAX now so wait for it to load.
And I wait until the page is ready
And I wait "1" seconds
And I set the field "Grade" to "57"
And I set the field "Comment" to "Some comment 1"
And I wait "2" seconds
And I click on "Save and finalise" "button"
And I should see "Your data has been saved."
Then I visit the coursework page
And I should see the final grade as 57 on the multiple marker page

@javascript
Scenario: Setting the final feedback comment
Given there are feedbacks from both teachers
And I am logged in as a manager
And I visit the coursework page
When I click the new multiple final feedback button for the student
When I grade the submission using the simple form
Then I should be on the coursework page
# Form loaded and sent by AJAX now so wait for it to load.
And I wait until the page is ready
And I wait "1" seconds
And I set the field "Grade" to "58"
And I set the field "Comment" to "Some comment 2"
And I wait "2" seconds
And I click on "Save and finalise" "button"
And I should see "Your data has been saved."
Then I visit the coursework page
When I click the edit final feedback button
Then I should see the grade comment in the form on the page
And I should see the grade in the form on the page
And I wait until the page is ready
And I wait "1" seconds
And the field "Grade" matches value "58"
And the field "Comment" matches value "Some comment 2"

@javascript
Scenario: I can be both an initial assessor and the manager who agrees grades
And managers do not have the manage capability
Given I am logged in as a manager
And there are feedbacks from both me and another teacher
And I visit the coursework page
When I click the new multiple final feedback button for the student
And I grade the submission using the simple form
Then I should be on the coursework page
And I wait until the page is ready
And I wait "1" seconds
And I set the field "Grade" to "59"
And I set the field "Comment" to "Some comment 3"
And I wait "2" seconds
And I click on "Save and finalise" "button"
And I should see "Your data has been saved."

@javascript
Scenario: Editing final feedback from others
And managers do not have the manage capability
Given I am logged in as a manager
And there are feedbacks from both me and another teacher
And there is final feedback from the other teacher
And there is final feedback from the other teacher with grade 45
When I visit the coursework page
When I click the edit final feedback button
And I should see the other teacher's final grade in the form on the page
And I grade the submission using the simple form
Then I should be on the coursework page
And I wait until the page is ready
And I wait "2" seconds
And I wait until the page is ready
And the field "Grade" matches value "45"
2 changes: 1 addition & 1 deletion tests/behat/feedback_multiple_assessor_feedback.feature
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Feature: Multiple assessors simple grading form
Scenario: Grade comments can be edited
Given I am logged in as a teacher
And the submission is finalised
And I have an assessor feedback
And I have an assessor feedback at grade 67
And I visit the coursework page
And I click on the edit feedback icon
Then I should see the grade comment in the form on the page
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

$plugin->component = 'mod_coursework';

$plugin->version = 2024091600; // If version == 0 then module will not be installed
$plugin->version = 2024100701; // If version == 0 then module will not be installed
$plugin->requires = 2023100400; // Requires this Moodle version

$plugin->cron = 300; // Period for cron to check this module (secs).
Expand Down

0 comments on commit a63f597

Please sign in to comment.