Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
11 changes: 7 additions & 4 deletions app/views/comments/_comment_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@
<dl>
<dt class="landmark"><%= t(".landmark.note") %>:</dt>
<dd class="instructions comment_form"><%= t(".guest_instructions") %></dd>
<dt><%= f.label "name_for_#{commentable.id}", t(".guest_name") %></dt>
<dd>
<dt class="required"><%= f.label "name_for_#{commentable.id}", t(".guest_name") %></dt>
<dd class="required">
<%= f.text_field :name, id: "comment_name_for_#{commentable.id}" %>
<%= live_validation_for_field("comment_name_for_#{commentable.id}", failureMessage: t(".guest_name_failure")) %>
</dd>
<dt><%= f.label "email_for_#{commentable.id}", t(".guest_email") %></dt>
<dd>
<dt class="required"><%= f.label "email_for_#{commentable.id}", t(".guest_email") %></dt>
<dd class="required">
<%= f.text_field :email, id: "comment_email_for_#{commentable.id}" %>
<%= live_validation_for_field("comment_email_for_#{commentable.id}", failureMessage: t(".guest_email_failure")) %>
</dd>
Expand All @@ -97,6 +97,9 @@
failureMessage: t(".comment_too_short"),
maximum_length: ArchiveConfig.COMMENT_MAX,
tooLongMessage: t(".comment_too_long", count: ArchiveConfig.COMMENT_MAX) %>
<% unless logged_in? %>
<p class="footnote"><%= t(".guest_edit_warning") %></p>
<% end %>
<p class="submit actions">
<%= f.submit button_name, id: "comment_submit_for_#{commentable.id}", data: { disable_with: t(".processing_message") } %>
<% if controller.controller_name == 'inbox' %>
Expand Down
7 changes: 4 additions & 3 deletions config/locales/views/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -638,10 +638,11 @@ en:
comment_field_title: Enter Comment
comment_too_long: must be less than %{count} characters long.
comment_too_short: Brevity is the soul of wit, but we need your comment to have text in it.
guest_email: Guest email
guest_edit_warning: You will not be able to edit or delete your comment after it is posted.
guest_email: Guest email (required)
guest_email_failure: Please enter your email address.
guest_instructions: All fields are required. Your email address will not be published.
guest_name: Guest name
guest_instructions: All fields are required. Your name and comment text will both be publicly displayed. Your email address will not be made public, but it will be used to send you notifications of any replies to your comment.
guest_name: Guest name (required)
guest_name_failure: Please enter your name.
inbox_reference_html: to %{commentable_creator} on %{commentable_link}
landmark:
Expand Down
23 changes: 23 additions & 0 deletions features/comments_and_kudos/guest_comments.feature
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,26 @@ Scenario: Guest comments with embedded images are rendered as plain text
And I should see "alt="
And I should see "baz"
But I should not see the image "src" text "https://example.com/image.jpg"

Scenario: Guest sees warning footnote and required fields on comment form
Given the work "Test Work" by "author" with guest comments enabled
When I go to the work "Test Work"
Then I should see "You will not be able to edit or delete your comment after it is posted."
And I should see "Guest name (required)"
And I should see "Guest email (required)"
And I should see "All fields are required. Your name and comment text will both be publicly displayed. Your email address will not be made public, but it will be used to send you notifications of any replies to your comment."
Comment on lines +51 to +53

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're in this file for the other review comment, please indent the "And" steps one extra level (also in the other scenario)


Scenario: Logged-in user does not see guest-specific elements
Given the work "Test Work" by "author" with guest comments enabled
And I am logged in as "commenter"
When I go to the work "Test Work"
Then I should not see "You will not be able to edit or delete your comment after it is posted."
And I should not see "Guest name (required)"
And I should not see "Guest email (required)"
And I should not see "All fields are required. Your name and comment text will both be publicly displayed. Your email address will not be made public, but it will be used to send you notifications of any replies to your comment."

Scenario: Guest comment validation messages appear correctly

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is a bit out of place. The errors are created in the model, so this should be a model test. However, the changes here doesn't affect this behaviour, so I think you can just remove the test.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Bilka2! This is my first time working with cucumber test and the comments are super helpful. I currently don’t have access to my computer, and will make revision in ~1 week when I do!

Given the work "Test Work" by "author" with guest comments enabled
When I go to the work "Test Work"
And I try to submit a comment without filling required fields
Then I should see validation messages for guest name and email
15 changes: 15 additions & 0 deletions features/step_definitions/comment_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,18 @@
When "I reply on a new page" do
visit find(:link, "Reply")["href"]
end

When "I try to submit a comment without filling required fields" do
click_button("Comment")
end

# error for the server-side validation. The error shown to user on the client side will be "Please enter your name.", "Please enter your email address."
Then "I should see validation messages for guest name and email" do
expect(page).to have_content("Name can't be blank")
expect(page).to have_content("Email should look like an email address.")
end

Then "I should see a required field for {string}" do |field_name|
expect(page).to have_selector("dt.required", text: field_name)
expect(page).to have_selector("dd.required")
end
Comment on lines +418 to +421

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This step not used in a test which is okay because we don't need a test for a HTML class. However, please remove the unused step

Loading