diff --git a/app/views/comments/_comment_form.html.erb b/app/views/comments/_comment_form.html.erb index 47067ecd5de..f29b7b07821 100644 --- a/app/views/comments/_comment_form.html.erb +++ b/app/views/comments/_comment_form.html.erb @@ -72,13 +72,13 @@
<%= t(".guest_edit_warning") %>
+ <% end %><%= f.submit button_name, id: "comment_submit_for_#{commentable.id}", data: { disable_with: t(".processing_message") } %> <% if controller.controller_name == 'inbox' %> diff --git a/config/locales/views/en.yml b/config/locales/views/en.yml index 6b502b713dd..73963d4578b 100644 --- a/config/locales/views/en.yml +++ b/config/locales/views/en.yml @@ -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: diff --git a/features/comments_and_kudos/guest_comments.feature b/features/comments_and_kudos/guest_comments.feature index 0a4cd50fd40..92d7ecb5bf4 100644 --- a/features/comments_and_kudos/guest_comments.feature +++ b/features/comments_and_kudos/guest_comments.feature @@ -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." + +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 + 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 diff --git a/features/step_definitions/comment_steps.rb b/features/step_definitions/comment_steps.rb index 7ce8828f638..2b98ac9c3f2 100644 --- a/features/step_definitions/comment_steps.rb +++ b/features/step_definitions/comment_steps.rb @@ -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