Skip to content

Commit

Permalink
StudentQuiz: StudentQuiz should use the current editor base on system…
Browse files Browse the repository at this point in the history
… setting #823098
  • Loading branch information
danghieu1407 committed Sep 25, 2024
1 parent 3a1b659 commit d97ad03
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 76 deletions.
2 changes: 1 addition & 1 deletion amd/build/comment_area.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amd/build/comment_area.min.js.map

Large diffs are not rendered by default.

204 changes: 172 additions & 32 deletions amd/src/comment_area.js

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions classes/commentarea/form/comment_simple_editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ class comment_simple_editor extends MoodleQuickForm_editor {
* @param array $options - Options of element.
*/
public function __construct($elementname = null, $elementlabel = null, $attributes = [], $options = []) {
global $CFG;

// HACK: There is no way to correctly force a specific editor. Unfortunately the comment area is highly
// specific to the atto editor, both here in php and javascript code. We temporarely fake the atto to be the
// only available editor. ref: https://github.com/frankkoch/moodle-mod_studentquiz/issues/283.
$CFG->texteditors = 'atto';

$attributes = array_merge($attributes, self::ATTRIBUTES);
$options = array_merge($options, self::OPTIONS);
$this->_options['atto:toolbar'] = get_config('studentquiz', 'comment_editor_toolbar');
Expand Down
59 changes: 32 additions & 27 deletions tests/behat/comment_area_create.feature
Original file line number Diff line number Diff line change
Expand Up @@ -47,43 +47,43 @@ Feature: Create comment as an user
# Wait for comment area init.
And I wait until the page is ready
# Enter "Comment 1".
And I enter the text "Comment 1" into the "Add public comment" editor
And I set the field "Add public comment" to "Comment 1"
And I press "Add comment"
And I wait until the page is ready
And I wait until ".studentquiz-comment-item:nth-child(1)" "css_element" exists
Then I should see "Comment 1" in the ".studentquiz-comment-item:nth-child(1) .studentquiz-comment-text" "css_element"
# Wait for different created time.
And I wait "1" seconds
# Enter "Comment 2"
And I enter the text "Comment 2" into the "Add public comment" editor
And I set the field "Add public comment" to "Comment 2"
And I press "Add comment"
And I wait until the page is ready
And I wait until ".studentquiz-comment-item:nth-child(2)" "css_element" exists
And I should see "Comment 2" in the ".studentquiz-comment-item:nth-child(2) .studentquiz-comment-text" "css_element"
And I wait "1" seconds
# Enter "Comment 3"
And I enter the text "Comment 3" into the "Add public comment" editor
And I set the field "Add public comment" to "Comment 3"
And I press "Add comment"
And I wait until the page is ready
And I wait until ".studentquiz-comment-item:nth-child(3)" "css_element" exists
And I should see "Comment 3" in the ".studentquiz-comment-item:nth-child(3) .studentquiz-comment-text" "css_element"
And I wait "1" seconds
# Enter "Comment 4"
And I enter the text "Comment 4" into the "Add public comment" editor
And I set the field "Add public comment" to "Comment 4"
And I press "Add comment"
And I wait until the page is ready
And I wait until ".studentquiz-comment-item:nth-child(4)" "css_element" exists
And I should see "Comment 4" in the ".studentquiz-comment-item:nth-child(4) .studentquiz-comment-text" "css_element"
And I wait "1" seconds
# Enter "Comment 5"
And I enter the text "Comment 5" into the "Add public comment" editor
And I set the field "Add public comment" to "Comment 5"
And I press "Add comment"
And I wait until the page is ready
And I wait until ".studentquiz-comment-item:nth-child(5)" "css_element" exists
And I should see "Comment 5" in the ".studentquiz-comment-item:nth-child(5) .studentquiz-comment-text" "css_element"
And I wait "1" seconds
# Enter "Comment 6"
And I enter the text "Comment 6" into the "Add public comment" editor
And I set the field "Add public comment" to "Comment 6"
And I press "Add comment"
And I wait until the page is ready
And I wait until ".studentquiz-comment-item:nth-child(6)" "css_element" exists
Expand Down Expand Up @@ -144,7 +144,7 @@ Feature: Create comment as an user
And I press "Check"
# Wait for comment area init.
And I wait until the page is ready
And I enter the text "Comment 1" into the "Add public comment" editor
And I set the field "Add public comment" to "Comment 1"
And I press "Add comment"
And I wait until the page is ready
And I wait until ".studentquiz-comment-item:nth-child(1)" "css_element" exists
Expand All @@ -153,7 +153,7 @@ Feature: Create comment as an user
And I click on "Reply" "button" in the ".studentquiz-comment-item:nth-child(1) .studentquiz-comment-commands-buttons" "css_element"
# Wait for reply init.
And I wait until the page is ready
And I enter the text "Reply comment 1" into the "Add reply" editor
And I set the field "Add reply" to "Reply comment 1"
And I press "Add reply"
And I wait until the page is ready
And I should see "1" in the ".studentquiz-comment-item:nth-child(1) .studentquiz-comment-totalreply" "css_element"
Expand All @@ -165,7 +165,7 @@ Feature: Create comment as an user
And I click on "Start Quiz" "button"
And I set the field "True" to "1"
And I press "Check"
And I enter the text "Comment 1 with long content: simply dummy text of the printing and typesetting industry." into the "Add public comment" editor
And I set the field "Add public comment" to "Comment 1 with long content: simply dummy text of the printing and typesetting industry."
And I press "Add comment"
And I press "Collapse all comments"
Then I should see "Comment 1 with long content: simply dummy text of the printing ..."
Expand All @@ -179,7 +179,7 @@ Feature: Create comment as an user
And I press "Check"
# Wait for comment area init.
And I wait until the page is ready
And I enter the text "Comment 1" into the "Add public comment" editor
And I set the field "Add public comment" to "Comment 1"
And I press "Add comment"
And I wait until the page is ready
And I wait until ".studentquiz-comment-item:nth-child(1)" "css_element" exists
Expand All @@ -206,7 +206,7 @@ Feature: Create comment as an user
And I wait until the page is ready
And I press "Finish"
And I should see "Please comment"
And I enter the text "Comment 1" into the "Add public comment" editor
And I set the field "Add public comment" to "Comment 1"
And I press "Add comment"
And I wait until the page is ready
And I press "Finish"
Expand All @@ -221,7 +221,7 @@ Feature: Create comment as an user
And I press "Check"
# Wait for comment area init.
And I wait until the page is ready
And I enter the text "Comment 1" into the "Add public comment" editor
And I set the field "Add public comment" to "Comment 1"
And I press "Add comment"
And I wait until the page is ready
And I wait until ".studentquiz-comment-item:nth-child(1)" "css_element" exists
Expand Down Expand Up @@ -252,7 +252,7 @@ Feature: Create comment as an user
And I set the field "True" to "1"
And I press "Check"
And I wait until the page is ready
And I enter the text "Comment 1" into the "Add public comment" editor
And I set the field "Add public comment" to "Comment 1"
And I press "Add comment"
And I wait until the page is ready
And I wait until ".studentquiz-comment-item:nth-child(1)" "css_element" exists
Expand Down Expand Up @@ -298,7 +298,7 @@ Feature: Create comment as an user
And I press "id_submitbutton"
And I choose "Preview" action for "Question of Student 1" in the question bank
And I switch to "questionpreview" window
And I enter the text "Approved the question" into the "Add private comment (these are between the student and tutor only)" editor
And I set the field "Add private comment (these are between the student and tutor only)" to "Approved the question"
And I press "Add comment"
And I am on the "StudentQuiz 3" "mod_studentquiz > View" page logged in as "teacher"
And I choose "Preview" action for "Question of Student 1" in the question bank
Expand All @@ -319,7 +319,7 @@ Feature: Create comment as an user
And I set the field "True" to "1"
And I press "Check"
And I wait until the page is ready
And I enter the text "Comment 2" into the "Add public comment" editor
And I set the field "Add public comment" to "Comment 2"
And I press "Add comment"
And I wait until the page is ready
And I log out
Expand All @@ -329,7 +329,7 @@ Feature: Create comment as an user
And I set the field "True" to "1"
And I press "Check"
And I wait until the page is ready
And I enter the text "Comment 3" into the "Add public comment" editor
And I set the field "Add public comment" to "Comment 3"
And I press "Add comment"
And I wait until the page is ready
And I log out
Expand All @@ -339,7 +339,7 @@ Feature: Create comment as an user
And I set the field "True" to "1"
And I press "Check"
And I wait until the page is ready
And I enter the text "Comment 4" into the "Add public comment" editor
And I set the field "Add public comment" to "Comment 4"
And I press "Add comment"
And I wait until the page is ready
And I log out
Expand All @@ -349,7 +349,7 @@ Feature: Create comment as an user
And I set the field "True" to "1"
And I press "Check"
And I wait until the page is ready
And I enter the text "Comment 5" into the "Add public comment" editor
And I set the field "Add public comment" to "Comment 5"
And I press "Add comment"
And I wait until the page is ready
And I log out
Expand All @@ -361,10 +361,10 @@ Feature: Create comment as an user
And I set the field "True" to "1"
And I press "Check"
And I wait until the page is ready
And I enter the text "Comment 6" into the "Add public comment" editor
And I set the field "Add public comment" to "Comment 6"
And I press "Add comment"
And I wait "1" seconds
And I enter the text "Comment 7" into the "Add public comment" editor
And I set the field "Add public comment" to "Comment 7"
And I press "Add comment"
And I wait until the page is ready
And I log out
Expand Down Expand Up @@ -442,7 +442,7 @@ Feature: Create comment as an user
And I set the field "True" to "1"
And I press "Check"
And I wait until the page is ready
And I enter the text "Comment test user 1" into the "Add public comment" editor
And I set the field "Add public comment" to "Comment test user 1"
And I press "Add comment"
And I wait until the page is ready
And I should see "Date" in the ".studentquiz-comment-filters" "css_element"
Expand All @@ -451,7 +451,12 @@ Feature: Create comment as an user

@javascript
Scenario: Test placeholder display after click Add comment.
When I am on the "StudentQuiz 1" "mod_studentquiz > View" page logged in as "admin"
Given I log in as "admin"
And I follow "Preferences" in the user menu
And I follow "Editor preferences"
And I set the field "Text editor" to "Atto HTML editor"
And I press "Save changes"
When I am on the "StudentQuiz 1" "mod_studentquiz > View" page
And I click on "Start Quiz" "button"
And I set the field "True" to "1"
And I press "Check"
Expand All @@ -478,7 +483,7 @@ Feature: Create comment as an user
And I press "Check"
# Wait for comment area init.
And I wait until the page is ready
And I enter the text "Comment 1" into the "Add public comment" editor
And I set the field "Add public comment" to "Comment 1"
And I press "Add comment"
And I wait until the page is ready
And I wait until ".studentquiz-comment-item:nth-child(1)" "css_element" exists
Expand All @@ -489,7 +494,7 @@ Feature: Create comment as an user
# Try to edit.
And I click on "Edit" "button" in the ".studentquiz-comment-item:nth-child(1) .studentquiz-comment-commands-box" "css_element"
And I wait until the page is ready
And I enter the text "Comment 1 edited" into the "Edit comment" editor
And I set the field "Edit comment" to "Comment 1 edited"
And I press "Save changes"
And I wait until the page is ready
And I should see "Comment 1 edited" in the ".studentquiz-comment-item:nth-child(1) .studentquiz-comment-text" "css_element"
Expand All @@ -503,7 +508,7 @@ Feature: Create comment as an user
And I click on "Reply" "button" in the ".studentquiz-comment-item:nth-child(1) .studentquiz-comment-commands-buttons" "css_element"
# Wait for reply init.
And I wait until the page is ready
And I enter the text "Reply comment 1" into the "Add reply" editor
And I set the field "Add reply" to "Reply comment 1"
And I press "Add reply"
And I wait until the page is ready
And I should see "Reply comment 1" in the ".studentquiz-comment-item:nth-child(1) .studentquiz-comment-replies .studentquiz-comment-item:nth-child(1) .studentquiz-comment-text" "css_element"
Expand All @@ -513,7 +518,7 @@ Feature: Create comment as an user
# Try to edit reply.
And I click on "Edit" "button" in the ".studentquiz-comment-item:nth-child(1) .studentquiz-comment-replies .studentquiz-comment-item:nth-child(1) .studentquiz-comment-commands-box" "css_element"
And I wait until the page is ready
And I enter the text "Reply comment 1 edited" into the "Edit comment" editor
And I set the field "Edit comment" to "Reply comment 1 edited"
And I press "Save changes"
And I wait until the page is ready
And I should see "Reply comment 1 edited" in the ".studentquiz-comment-item:nth-child(1) .studentquiz-comment-replies .studentquiz-comment-item:nth-child(1) .studentquiz-comment-text" "css_element"
Expand Down Expand Up @@ -559,7 +564,7 @@ Feature: Create comment as an user
# Wait for comment area init.
And I wait until the page is ready
# Try to comment.
And I enter the text "Comment 1" into the "Add public comment" editor
And I set the field "Add public comment" to "Comment 1"
And I press "Add comment"
And I wait until the page is ready
And I wait until ".studentquiz-comment-item:nth-child(1)" "css_element" exists
Expand Down
10 changes: 5 additions & 5 deletions tests/behat/comment_area_private_comment.feature
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Feature: As a user I can add private comment and view private comment in my own
And I press "id_submitbutton"
And I choose "Preview" action for "Question 1" in the question bank
And I switch to "questionpreview" window
And I enter the text "Submitted for approval" into the "Add private comment (these are between the student and tutor only)" editor
And I set the field "Add private comment (these are between the student and tutor only)" to "Submitted for approval"
And I press "Add comment"
Then I should see "Submitted for approval" in the ".studentquiz-comment-item:nth-child(1) .studentquiz-comment-text" "css_element"
And I click on "Public comments" "link"
Expand All @@ -47,7 +47,7 @@ Feature: As a user I can add private comment and view private comment in my own
And I choose "Preview" action for "Question 1" in the question bank
And I switch to "questionpreview" window
And I should see "Submitted for approval"
And I enter the text "A private comment from teacher" into the "Add private comment (these are between the student and tutor only)" editor
And I set the field "Add private comment (these are between the student and tutor only)" to "A private comment from teacher"
And I press "Add comment"
And I switch to the main window
And I log out
Expand All @@ -60,7 +60,7 @@ Feature: As a user I can add private comment and view private comment in my own
And I should see "Rating and public commenting are not available for your own question in Preview mode."
And I click on "Private comments" "link"
And I should see "A private comment from teacher"
And I enter the text "Updated for approval again" into the "Add private comment (these are between the student and tutor only)" editor
And I set the field "Add private comment (these are between the student and tutor only)" to "Updated for approval again"
And I press "Add comment"
And I switch to the main window
And I reload the page
Expand All @@ -72,7 +72,7 @@ Feature: As a user I can add private comment and view private comment in my own
And I choose "Preview" action for "Question 1" in the question bank
And I switch to "questionpreview" window
And I should see "Updated for approval again"
And I enter the text "Approved the question" into the "Add private comment (these are between the student and tutor only)" editor
And I set the field "Add private comment (these are between the student and tutor only)" to "Approved the question"
And I press "Add comment"
And I set the field "statetype" to "Approved"
And I click on "Change state" "button"
Expand All @@ -94,7 +94,7 @@ Feature: As a user I can add private comment and view private comment in my own
And I click on "Start Quiz" "button"
And I set the field "True" to "1"
And I press "Check"
And I enter the text "Public comment of student 2" into the "Add public comment" editor
And I set the field "Add public comment" to "Public comment of student 2"
And I press "Add comment"
And I log out
And I am on the "StudentQuiz 1" "mod_studentquiz > View" page logged in as "student1"
Expand Down
2 changes: 1 addition & 1 deletion tests/behat/group_separate_groups.feature
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Feature: Students can create questions and practice in separate groups.
And I click on "Start Quiz" "button"
And I set the field "True" to "1"
And I press "Check"
And I enter the text "Comment 1" into the "Add public comment" editor
And I set the field "Add public comment" to "Comment 1"
And I press "Add comment"
And I wait until ".studentquiz-comment-item:nth-child(1)" "css_element" exists
Then I should see "Comment 1" in the ".studentquiz-comment-item:nth-child(1) .studentquiz-comment-text" "css_element"
4 changes: 2 additions & 2 deletions tests/behat/preview_question.feature
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Feature: Preview a question as a student
And I press "Check"
And I wait until the page is ready
And the state of "What is pi to two d.p.?" question is shown as "Correct"
And I enter the text "Very good question" into the "Add public comment" editor
And I set the field "Add public comment" to "Very good question"
And I press "Add comment"
And I wait until the page is ready
And I should see "Very good question"
Expand Down Expand Up @@ -83,7 +83,7 @@ Feature: Preview a question as a student
When I choose "Preview" action for "Example question 2" in the question bank
And I switch to "questionpreview" window
And "Add public comment" "field" should exist
And I enter the text "Comment test" into the "Add public comment" editor
And I set the field "Add public comment" to "Comment test"
And I press "Add comment"
And I wait until the page is ready
And I should see "Comment test"
Expand Down

0 comments on commit d97ad03

Please sign in to comment.