Browse Source

fix some feature and helpers specs offences

pull/264/head
Kat 3 years ago
parent
commit
f0e47c0d57
  1. 2
      spec/features/organisation_spec.rb
  2. 4
      spec/features/start_page_spec.rb
  3. 12
      spec/features/user_spec.rb
  4. 0
      spec/helpers/application_helper_spec.rb
  5. 5
      spec/helpers/check_answers_helper_spec.rb
  6. 2
      spec/helpers/conditional_questions_helper_spec.rb
  7. 2
      spec/helpers/form_page_error_helper_spec.rb
  8. 2
      spec/helpers/question_attribute_helper_spec.rb
  9. 34
      spec/helpers/question_view_helper.rb

2
spec/features/organisation_spec.rb

@ -6,7 +6,7 @@ RSpec.describe "User Features" do
let(:organisation) { user.organisation } let(:organisation) { user.organisation }
let(:org_id) { organisation.id } let(:org_id) { organisation.id }
let(:set_password_template_id) { DeviseNotifyMailer::SET_PASSWORD_TEMPLATE_ID } let(:set_password_template_id) { DeviseNotifyMailer::SET_PASSWORD_TEMPLATE_ID }
let(:notify_client) { double(Notifications::Client) } let(:notify_client) { instance_double(Notifications::Client) }
let(:reset_password_token) { "MCDH5y6Km-U7CFPgAMVS" } let(:reset_password_token) { "MCDH5y6Km-U7CFPgAMVS" }
before do before do

4
spec/features/start_page_spec.rb

@ -5,7 +5,7 @@ RSpec.describe "Start Page Features" do
include Helpers include Helpers
let(:user) { FactoryBot.create(:user) } let(:user) { FactoryBot.create(:user) }
context "a signed in user" do context "when the user is signed in" do
before do before do
sign_in user sign_in user
end end
@ -16,7 +16,7 @@ RSpec.describe "Start Page Features" do
end end
end end
context "a not signed in user" do context "when the user is not signed in" do
it "takes you to sign in and then to your logs" do it "takes you to sign in and then to your logs" do
visit("/") visit("/")
click_link("Start now") click_link("Start now")

12
spec/features/user_spec.rb

@ -14,7 +14,7 @@ RSpec.describe "User Features" do
allow_any_instance_of(User).to receive(:set_reset_password_token).and_return(reset_password_token) allow_any_instance_of(User).to receive(:set_reset_password_token).and_return(reset_password_token)
end end
context "A user navigating to case logs" do context "when the user navigates to case logs" do
it " is required to log in" do it " is required to log in" do
visit("/logs") visit("/logs")
expect(page).to have_current_path("/users/sign-in") expect(page).to have_current_path("/users/sign-in")
@ -54,7 +54,7 @@ RSpec.describe "User Features" do
end end
end end
context "A user who has forgotten their password" do context "when the user has forgotten their password" do
it " is redirected to the reset password page when they click the reset password link" do it " is redirected to the reset password page when they click the reset password link" do
visit("/logs") visit("/logs")
click_link("reset your password") click_link("reset your password")
@ -118,7 +118,7 @@ RSpec.describe "User Features" do
end end
end end
context "If user not logged in" do context "when the user is not logged in" do
it "'Your account' link does not display" do it "'Your account' link does not display" do
visit("/logs") visit("/logs")
expect(page).to have_no_link("Your account") expect(page).to have_no_link("Your account")
@ -140,7 +140,7 @@ RSpec.describe "User Features" do
end end
end end
context "Trying to log in with incorrect credentials" do context "when the user is trying to log in with incorrect credentials" do
it "shows a gov uk error summary and no flash message" do it "shows a gov uk error summary and no flash message" do
visit("/logs") visit("/logs")
fill_in("user[email]", with: user.email) fill_in("user[email]", with: user.email)
@ -171,7 +171,7 @@ RSpec.describe "User Features" do
end end
end end
context "Your Account " do context "when viewing your account" do
before do before do
visit("/logs") visit("/logs")
fill_in("user[email]", with: user.email) fill_in("user[email]", with: user.email)
@ -207,7 +207,7 @@ RSpec.describe "User Features" do
end end
end end
context "Adding a new user" do context "when adding a new user" do
before do before do
visit("/logs") visit("/logs")
fill_in("user[email]", with: user.email) fill_in("user[email]", with: user.email)

0
spec/helpers/application_helper.rb → spec/helpers/application_helper_spec.rb

5
spec/helpers/check_answers_helper_spec.rb

@ -1,20 +1,19 @@
require "rails_helper" require "rails_helper"
RSpec.describe CheckAnswersHelper do RSpec.describe CheckAnswersHelper do
let(:case_log) { FactoryBot.build(:case_log) }
let(:form) { case_log.form } let(:form) { case_log.form }
let(:subsection) { form.get_subsection("household_characteristics") } let(:subsection) { form.get_subsection("household_characteristics") }
let(:case_log) { FactoryBot.build(:case_log, :in_progress) } let(:case_log) { FactoryBot.build(:case_log, :in_progress) }
describe "display_answered_questions_summary" do describe "display_answered_questions_summary" do
context "given a section that hasn't been completed yet" do context "when a section hasn't been completed yet" do
it "returns that you have unanswered questions" do it "returns that you have unanswered questions" do
expect(display_answered_questions_summary(subsection, case_log)) expect(display_answered_questions_summary(subsection, case_log))
.to match(/You have answered 2 of 4 questions./) .to match(/You have answered 2 of 4 questions./)
end end
end end
context "given a section that has been completed" do context "when a section has been completed" do
it "returns that you have answered all the questions" do it "returns that you have answered all the questions" do
case_log.sex1 = "F" case_log.sex1 = "F"
case_log.other_hhmemb = 0 case_log.other_hhmemb = 0

2
spec/helpers/conditional_questions_helper_spec.rb

@ -17,7 +17,7 @@ RSpec.describe ConditionalQuestionsHelper do
let(:answer_value) { "A current or former regular in the UK Armed Forces (excluding National Service)" } let(:answer_value) { "A current or former regular in the UK Armed Forces (excluding National Service)" }
it "returns the conditional question for a given answer option" do it "returns the conditional question for a given answer option" do
expect(find_conditional_question(page, question, answer_value)) expect(find_conditional_question(page, question, answer_value).id).to eq("leftreg")
end end
end end

2
spec/helpers/form_page_error_helper.spec.rb → spec/helpers/form_page_error_helper_spec.rb

@ -2,7 +2,7 @@ require "rails_helper"
RSpec.describe FormPageErrorHelper do RSpec.describe FormPageErrorHelper do
describe "#remove_other_page_errors" do describe "#remove_other_page_errors" do
context "removes non base other questions" do context "when non base other questions are removed" do
let!(:case_log) { FactoryBot.create(:case_log, :in_progress) } let!(:case_log) { FactoryBot.create(:case_log, :in_progress) }
let!(:form) { case_log.form } let!(:form) { case_log.form }

2
spec/helpers/question_attribute_helper_spec.rb

@ -21,7 +21,7 @@ RSpec.describe QuestionAttributeHelper do
}) })
end end
context "a question that requires multiple controllers" do context "when a question that requires multiple controllers" do
let(:question) do let(:question) do
Form::Question.new("brent", { Form::Question.new("brent", {
"check_answer_label" => "Basic Rent", "check_answer_label" => "Basic Rent",

34
spec/helpers/question_view_helper.rb

@ -5,71 +5,73 @@ RSpec.describe QuestionViewHelper do
let(:conditional) { false } let(:conditional) { false }
describe "caption" do describe "caption" do
let(:subject) { caption(caption_text, page_header, conditional) } subject(:header) { caption(caption_text, page_header, conditional) }
let(:caption_text) { "Some text" } let(:caption_text) { "Some text" }
let(:caption_options_hash) { { text: caption_text.html_safe, size: "l" } } let(:caption_options_hash) { { text: caption_text.html_safe, size: "l" } }
context "a page without a header" do context "when viewing a page without a header" do
let(:page_header) { nil } let(:page_header) { nil }
it "returns an options hash" do it "returns an options hash" do
expect(subject).to eq(caption_options_hash) expect(header).to eq(caption_options_hash)
end end
end end
context "a page with a header" do context "when viewing a page with a header" do
it "returns nil" do it "returns nil" do
expect(subject).to be_nil expect(header).to be_nil
end end
end end
context "a conditional question" do context "when viewing a conditional question" do
let(:conditional) { true } let(:conditional) { true }
it "returns nil" do it "returns nil" do
expect(subject).to be_nil expect(header).to be_nil
end end
end end
context "a question without a caption" do context "when viewig a question without a caption" do
let(:caption_text) { nil } let(:caption_text) { nil }
it "returns nil" do it "returns nil" do
expect(subject).to be_nil expect(header).to be_nil
end end
end end
end end
describe "legend" do describe "legend" do
subject(:question_view_helper) { legend(question, page_header, conditional) }
let(:question) { OpenStruct.new(header: "Some question header") } let(:question) { OpenStruct.new(header: "Some question header") }
let(:subject) { legend(question, page_header, conditional) }
let(:size) { "m" } let(:size) { "m" }
let(:tag) { "h2" } let(:tag) { "h2" }
let(:legend_options_hash) do let(:legend_options_hash) do
{ text: "Some question header".html_safe, size: size, tag: tag } { text: "Some question header".html_safe, size: size, tag: tag }
end end
context "a page with a header" do context "when viewing a page with a header" do
it "returns an options hash with a medium question header" do it "returns an options hash with a medium question header" do
expect(subject).to eq(legend_options_hash) expect(question_view_helper).to eq(legend_options_hash)
end end
end end
context "a page without a header" do context "when viewing a page without a header" do
let(:page_header) { nil } let(:page_header) { nil }
let(:size) { "l" } let(:size) { "l" }
let(:tag) { "h1" } let(:tag) { "h1" }
it "returns an options hash with a large question header" do it "returns an options hash with a large question header" do
expect(subject).to eq(legend_options_hash) expect(question_view_helper).to eq(legend_options_hash)
end end
end end
context "a conditional question" do context "when viewinng a conditional question" do
let(:conditional) { true } let(:conditional) { true }
it "returns an options hash with a medium question header" do it "returns an options hash with a medium question header" do
expect(subject).to eq(legend_options_hash) expect(question_view_helper).to eq(legend_options_hash)
end end
end end
end end

Loading…
Cancel
Save