Discussion's refetches data after initial discussion_topics_post

fixes VICE-3041

Test plan
1. With discussionr design enabled...
2. Create a Discussion Topic with "reply before showing post" enabled
3. Post an initial response as the creator of the Topic
4. Change to student account, go to Topic
5. Notice, there are no posts showing
6. Make a reply, when clicking reply, notice the page requires and
post from teacher is now visible

Change-Id: Ia01ac5150651484d61baf7def954b20503b670d0
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/302952
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Reviewed-by: Omar Soto-Fortuño <omar.soto@instructure.com>
Product-Review: Omar Soto-Fortuño <omar.soto@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
This commit is contained in:
Jeffrey Johnson 2022-10-10 09:47:26 -07:00
parent 891c0374c2
commit 60c1ba2e2d
3 changed files with 37 additions and 0 deletions

View File

@ -456,5 +456,28 @@ describe "threaded discussions" do
expect(authors).not_to include("student") expect(authors).not_to include("student")
end end
end end
context "users must post before seeing replies" do
it "requires a post before seeing replies for students" do
topic = create_discussion("must see replies", "threaded")
topic.require_initial_post = true
topic.save!
topic.reload
topic.discussion_entries.create!(
user: @teacher,
message: "students can only see this if they reply"
)
user_session(@student)
get "/courses/#{@course.id}/discussion_topics/#{topic.id}"
expect(fj("div:contains('You must post before seeing replies.')")).to be_present
expect(f("body")).not_to contain_jqcss("div:contains('students can only see this if they reply')")
f("button[data-testid='discussion-topic-reply']").click
type_in_tiny("textarea", "student here")
fj("button:contains('Reply')").click
wait_for_ajaximations
expect(f("body")).to contain_jqcss("div:contains('students can only see this if they reply')")
expect(f("body")).to contain_jqcss("div:contains('student here')")
end
end
end end
end end

View File

@ -262,6 +262,15 @@ const DiscussionTopicManager = props => {
}) })
}} }}
isHighlighted={isTopicHighlighted} isHighlighted={isTopicHighlighted}
onDiscussionReplyPost={() => {
// When post requires a reply, check to see if we can refatch after initial post
if (
discussionTopicQuery.data.legacyNode.availableForUser &&
discussionTopicQuery.data.legacyNode.initialPostRequiredForCurrentUser
) {
discussionTopicQuery.refetch(variables)
}
}}
/> />
{discussionTopicQuery.data.legacyNode.discussionEntriesConnection.nodes.length === 0 && {discussionTopicQuery.data.legacyNode.discussionEntriesConnection.nodes.length === 0 &&
(searchTerm || filter === 'unread') ? ( (searchTerm || filter === 'unread') ? (

View File

@ -502,6 +502,7 @@ export const DiscussionTopicContainer = ({createDiscussionEntry, ...props}) => {
if (createDiscussionEntry) { if (createDiscussionEntry) {
createDiscussionEntry(message, anonymousAuthorState) createDiscussionEntry(message, anonymousAuthorState)
setExpandedReply(false) setExpandedReply(false)
props.onDiscussionReplyPost()
} }
}} }}
onCancel={() => { onCancel={() => {
@ -583,6 +584,10 @@ DiscussionTopicContainer.propTypes = {
* useState Boolean to toggle highlight * useState Boolean to toggle highlight
*/ */
isHighlighted: PropTypes.bool, isHighlighted: PropTypes.bool,
/**
* Callback to be called when discussion post is submitted
*/
onDiscussionReplyPost: PropTypes.func,
} }
export default DiscussionTopicContainer export default DiscussionTopicContainer