Skip to content

Commit

Permalink
StudentQuiz: The comment/reply input field still displays the entered…
Browse files Browse the repository at this point in the history
… text after the user submits a comment/reply with Tiny Editor #83658
  • Loading branch information
Khoa Nguyen authored and AnupamaSarjoshi committed Nov 6, 2024
1 parent 83c1a4f commit 7ae0f90
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 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.

25 changes: 23 additions & 2 deletions amd/src/comment_area.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
/**
* @module mod_studentquiz/comment_element
*/
define(['jquery', 'core/str', 'core/ajax', 'core/modal_factory', 'core/templates', 'core/fragment', 'core/modal_events'],
function($, str, ajax, ModalFactory, Templates, fragment, ModalEvents) {
define(['jquery', 'core/str', 'core/ajax', 'core/modal_factory', 'core/templates', 'core/fragment', 'core/modal_events',
'tiny_autosave/repository'],
function($, str, ajax, ModalFactory, Templates, fragment, ModalEvents, TinyRepository) {
var t = {
EMPTY_CONTENT: ['<br><p><br></p>', '<p><br></p>', '<br>', ''],
ROOT_COMMENT_VALUE: 0,
Expand Down Expand Up @@ -397,6 +398,9 @@ define(['jquery', 'core/str', 'core/ajax', 'core/modal_factory', 'core/templates
},
};
self.createComment(params).then(function(response) {
// Remove the draft data from the editor after successfully creating a comment.
self.removeTinyAutoSaveSession(
self.formSelector?.find(t.SELECTOR.TEXTAREA)?.attr('id') ?? '');
M.util.js_pending(t.ACTION_CLEAR_FORM);
// Clear form in setTimeout to prevent require message still shown when reset on Firefox.
setTimeout(function() {
Expand Down Expand Up @@ -1140,6 +1144,8 @@ define(['jquery', 'core/str', 'core/ajax', 'core/modal_factory', 'core/templates
};
M.util.js_pending(t.ACTION_CREATE_REPLY);
self.createComment(params).then(function(response) {
// Remove draft data from the editor after successfully creating a reply comment.
self.removeTinyAutoSaveSession(formSelector?.find(t.SELECTOR.TEXTAREA)?.attr('id'));
// Hide error if exists.
$(t.SELECTOR.COMMENT_ERROR).addClass('hide');
var el = self.elementSelector.find(t.SELECTOR.COMMENT_ID + item.id);
Expand Down Expand Up @@ -1844,6 +1850,21 @@ define(['jquery', 'core/str', 'core/ajax', 'core/modal_factory', 'core/templates
this.triggerAttoHasContent(formSelector);
}
M.util.js_complete(key);
},

/**
* Remove draft data from the Tiny editor, which is auto-saved according to editorID.
*
* @param {String} editorID The editor ID for which draft data needs to be removed.
*/
removeTinyAutoSaveSession: function(editorID) {
// Execute this only if it's a Tiny editor.
if (this.isusingtinymce) {
const editor = window?.tinyMCE?.get(editorID);
if (editor) {
TinyRepository.removeAutosaveSession(editor);
}
}
}
};
},
Expand Down
11 changes: 11 additions & 0 deletions tests/behat/comment_area_create.feature
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ Feature: Create comment as an user
And I wait until the page is ready
And I set the field "Add public comment" to "Comment 1"
And I press "Add comment"
And I reload the page
And I wait until the page is ready
# The content no longer exists after successfully creating a comment.
And the following fields match these values:
| Add public 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"
# Check can reply
Expand All @@ -162,6 +166,13 @@ Feature: Create comment as an user
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"
And I should see "Reply" in the ".studentquiz-comment-item:nth-child(1) .studentquiz-comment-totalreply" "css_element"
And I reload the page
And I wait until the page is ready
And I click on "Reply" "button" in the ".studentquiz-comment-item:nth-child(1) .studentquiz-comment-commands-buttons" "css_element"
And I wait until the page is ready
# The content no longer exists after successfully creating a reply comment.
And the following fields match these values:
| Add reply | |

@javascript
Scenario: Test reply comment with long content
Expand Down

0 comments on commit 7ae0f90

Please sign in to comment.