Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vertism committed Sep 23, 2024
1 parent 637ac29 commit 337e8ed
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
8 changes: 7 additions & 1 deletion app/models/feedback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/correspondence_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/features/send_correspondence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
14 changes: 7 additions & 7 deletions spec/features/send_feedback_spec.rb
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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
5 changes: 3 additions & 2 deletions spec/site_prism/pages/correspondence/topic_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 337e8ed

Please sign in to comment.