From 337e8ed8de2e38cb7c8cf0823f46aeaa14212f2e Mon Sep 17 00:00:00 2001 From: Andrew Pepler Date: Mon, 23 Sep 2024 16:57:42 +0100 Subject: [PATCH] Fix tests --- app/models/feedback.rb | 8 +++++++- spec/controllers/correspondence_controller_spec.rb | 2 +- spec/features/send_correspondence_spec.rb | 2 +- spec/features/send_feedback_spec.rb | 14 +++++++------- spec/site_prism/pages/correspondence/topic_page.rb | 5 +++-- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/app/models/feedback.rb b/app/models/feedback.rb index 4668cfbf..94e5b9bb 100644 --- a/app/models/feedback.rb +++ b/app/models/feedback.rb @@ -9,8 +9,14 @@ # class Feedback < ApplicationRecord - validates :ease_of_use, :completeness, inclusion: { + validates :ease_of_use, inclusion: { in: Settings.feedback_options, + message: "Ease of use is not included in the list", + } + + validates :completeness, inclusion: { + in: Settings.feedback_options, + message: "Completeness is not included in the list", } jsonb_accessor :content, diff --git a/spec/controllers/correspondence_controller_spec.rb b/spec/controllers/correspondence_controller_spec.rb index d7493bb7..c183b3e5 100644 --- a/spec/controllers/correspondence_controller_spec.rb +++ b/spec/controllers/correspondence_controller_spec.rb @@ -81,7 +81,7 @@ it "has a flash error message" do get(:search, params:) - expect(assigns(:correspondence).errors[:topic]).to include(" can't be blank") + expect(assigns(:correspondence).errors[:topic]).to include("What are you contacting the Ministry of Justice about? can't be blank") end end end diff --git a/spec/features/send_correspondence_spec.rb b/spec/features/send_correspondence_spec.rb index e1f44913..aa4b56ab 100644 --- a/spec/features/send_correspondence_spec.rb +++ b/spec/features/send_correspondence_spec.rb @@ -100,7 +100,7 @@ expect(search_page.title).to eq "Topic search - Contact the Ministry of Justice" - topic_page.search_govuk(topic_with_results) + topic_page.search_govuk(topic_with_results, topic_page.topic_field_error) expect(search_page.title).to eq "Contact form - Contact the Ministry of Justice" diff --git a/spec/features/send_feedback_spec.rb b/spec/features/send_feedback_spec.rb index 9f55dba8..1af9a8a7 100644 --- a/spec/features/send_feedback_spec.rb +++ b/spec/features/send_feedback_spec.rb @@ -1,14 +1,14 @@ require "rails_helper" feature "Submit service feedback" do - given(:ease_of_use) { Settings.feedback_options.sample } - given(:completeness) { Settings.feedback_options.sample } - given(:comment) { Faker::Lorem.paragraphs[1] } + given(:ease_of_use) { Settings.feedback_options.sample } + given(:completeness) { Settings.feedback_options.sample } + given(:comment) { Faker::Lorem.paragraphs[1] } scenario "Using valid inputs" do visit feedback_path - choose "feedback_ease_of_use_#{ease_of_use}" - choose "feedback_completeness_#{completeness}" + choose "feedback-ease-of-use-#{ease_of_use.dasherize}-field" + choose "feedback-completeness-#{completeness.dasherize}-field" fill_in "feedback[comment]", with: comment click_button "Send" @@ -30,7 +30,7 @@ scenario "Without a rating for ease of use or completeness" do visit feedback_path click_button "Send" - expect(page).to have_content("This online service was easy to use Ease of use is not included in the list") - expect(page).to have_content("The online service enabled me to give all the relevant information Completeness is not included in the list") + expect(page).to have_content("This online service was easy to use\nError: Ease of use is not included in the list") + expect(page).to have_content("The online service enabled me to give all the relevant information\nError: Completeness is not included in the list") end end diff --git a/spec/site_prism/pages/correspondence/topic_page.rb b/spec/site_prism/pages/correspondence/topic_page.rb index 5bcda1f0..1a295dcd 100644 --- a/spec/site_prism/pages/correspondence/topic_page.rb +++ b/spec/site_prism/pages/correspondence/topic_page.rb @@ -5,10 +5,11 @@ class TopicPage < SitePrism::Page set_url "/correspondence/topic" element :topic_field, "#correspondence-topic-field" + element :topic_field_error, "#correspondence-topic-field-error" element :continue_button, 'button[type="submit"]' - def search_govuk(topic) - topic_field.set topic + def search_govuk(topic, field = topic_field) + field.set topic continue_button.click end end