Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AO3-6392 Comment actions when replying in full page #4381

Merged
merged 25 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions app/helpers/comments_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def add_comment_reply_link(comment)
end

# return link to cancel new reply to a comment
def cancel_comment_reply_link(comment)
def cancel_comment_reply_link(comment, remote: true)
commentable_id = comment.ultimate_parent.is_a?(Tag) ?
:tag_id :
comment.parent.class.name.foreign_key.to_sym
Expand All @@ -218,14 +218,17 @@ def cancel_comment_reply_link(comment)
comment.parent.id
link_to(
ts("Cancel"),
url_for(controller: :comments,
action: :cancel_comment_reply,
id: comment.id,
comment_id: params[:comment_id],
commentable_id => commentable_value,
view_full_work: params[:view_full_work],
page: params[:page]),
remote: true)
url_for(
controller: :comments,
action: :cancel_comment_reply,
id: comment.id,
comment_id: params[:comment_id],
commentable_id => commentable_value,
view_full_work: params[:view_full_work],
page: params[:page]
),
remote: remote
)
end

# canceling an edit
Expand Down
2 changes: 1 addition & 1 deletion app/views/comments/_comment_actions.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h5 class="landmark heading"><%= ts("Comment Actions") %></h5>

<ul class="actions" id="navigation_for_comment_<%= comment.id %>">
<ul class="actions" id="navigation_for_comment_<%= comment.id %>" <% if params[:add_comment_reply_id] && params[:add_comment_reply_id] == comment.id.to_s %>style="display:none;"<% end %>>
<% # The effect is "Frozen" replaces "Reply." We can't do that in the helper
# method for the reply link because that would prevent "Frozen" from
# appearing on the Unreviewed Comments page for works with moderated
Expand Down
2 changes: 1 addition & 1 deletion app/views/comments/_comment_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<% elsif comment.persisted? %>
<%= cancel_edit_comment_link(comment) %>
<% elsif commentable.is_a?(Comment) || commentable.is_a?(CommentDecorator) %>
<%= cancel_comment_reply_link(commentable) %>
<%= cancel_comment_reply_link(commentable, remote: !(params[:add_comment_reply_id] && params[:add_comment_reply_id] == commentable.id.to_s)) %>
<% end %>
</p>
</fieldset>
Expand Down
42 changes: 42 additions & 0 deletions features/comments_and_kudos/add_comment.feature
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,45 @@ Scenario: Try to post a comment with a < angle bracket before a linebreak, with
"""
And I press "Comment"
Then I should see "Comment created!"

Scenario: It hides comment actions when a reply form is open
When I am logged in as "author"
And I post the work "The One Where Neal is Awesome"
When I am logged in as "commenter"
And I post the comment "I loved this!" on the work "The One Where Neal is Awesome"
When I follow "Reply"
Then I should see "Comment as commenter"
Then I should not see "Thread"
ceithir marked this conversation as resolved.
Show resolved Hide resolved

@javascript
Scenario: It shows and hides cancel buttons properly
Given the work "Aftermath" by "creator"
And a comment "Ugh." by "pest" on the work "Aftermath"
When I am logged in as "creator"
And I view the work "Aftermath"
And I display comments
Then I should see "Ugh."
When I open the reply box
Then I should see "Cancel"
Then I should not see "Reply"
When I cancel the reply box
Then I should not see "Cancel"
Then I should see "Reply"
ceithir marked this conversation as resolved.
Show resolved Hide resolved

@javascript
Scenario: It shows and hides cancel buttons properly even on a new page
Given the work "Aftermath" by "creator"
And a comment "Ugh." by "pest" on the work "Aftermath"
When I am logged in as "creator"
And I view the work "Aftermath"
And I display comments
Then I should see "Ugh."
When I reply to the work comment "Ugh." on a new page
Then I should see "Aftermath"
Then I should see "Cancel"
Then I should not see "Reply"
When I cancel the reply box
And I fix the domain name
Then I should see "Aftermath"
Then I should not see "Cancel"

21 changes: 21 additions & 0 deletions features/step_definitions/comment_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,24 @@
click_link("Yes, delete!") # TODO: Fix along with comment deletion.
end
end

When "I display comments" do
click_link("Comments")
end

When "I open the reply box" do
click_link("Reply")
end

When "I cancel the reply box" do
click_link("Cancel")
end

When /^I reply to the work comment "([^"]*)" on a new page$/ do |comment_content|
comment = Comment.find_by(comment_content: comment_content)
visit work_path(
comment.commentable,
add_comment_reply_id: comment.id,
show_comments: true
)
end
ceithir marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions features/step_definitions/web_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,9 @@ def with_scope(locator)
cookie_value = Capybara.current_session.driver.request.cookies.[](cookie)
assert cookie_value.nil?
end

When "I fix the domain name" do
parsed = URI.parse(current_url)
dest = "#{parsed.path}?#{parsed.query || ''}##{parsed.fragment || ''}"
visit dest
end
ceithir marked this conversation as resolved.
Show resolved Hide resolved