Browse Source

Refactor specs

pull/22/head
baarkerlounger 3 years ago
parent
commit
36ba98a9ae
  1. 68
      spec/features/case_log_spec.rb

68
spec/features/case_log_spec.rb

@ -3,7 +3,16 @@ RSpec.describe "Test Features" do
let!(:case_log) { FactoryBot.create(:case_log, :in_progress) } let!(:case_log) { FactoryBot.create(:case_log, :in_progress) }
let(:id) { case_log.id } let(:id) { case_log.id }
let(:status) { case_log.status } let(:status) { case_log.status }
pages = %w[tenant_code tenant_age tenant_gender tenant_ethnic_group tenant_nationality tenant_economic_status household_number_of_other_members]
question_answers = {
tenant_code: {type: "text", answer: "BZ737"},
tenant_age: {type: "numeric", answer: 25},
tenant_gender: {type: "radio", answer: "1"},
tenant_ethnic_group: {type: "radio", answer: "2"},
tenant_nationality: {type: "radio", answer: "0"},
tenant_economic_status: {type: "radio", answer: "4"},
household_number_of_other_members: {type: "numeric", answer: 2},
}
describe "Create new log" do describe "Create new log" do
it "redirects to the task list for the new log" do it "redirects to the task list for the new log" do
@ -40,47 +49,23 @@ RSpec.describe "Test Features" do
end end
it "updates model attributes correctly for each question" do it "updates model attributes correctly for each question" do
visit("/case_logs/#{id}/tenant_code") question_answers.each do |question, hsh|
fill_in(:tenant_code, with: "BZ737") type = hsh[:type]
expect { click_button("Save and continue") }.to change { answer = hsh[:answer]
case_log.reload.tenant_code original_value = case_log.send(question)
}.from("TH356").to("BZ737") visit("/case_logs/#{id}/#{question}")
case type
visit("/case_logs/#{id}/tenant_age") when "text"
fill_in(:tenant_age, with: 25) fill_in("#{question}", with: answer)
expect { click_button("Save and continue") }.to change { when "radio"
case_log.reload.tenant_age choose("#{question.to_s.gsub('_', '-')}-#{answer}-field")
}.from(NilClass).to(25) else
fill_in("#{question}", with: answer)
visit("/case_logs/#{id}/tenant_gender") end
choose("tenant-gender-1-field")
expect { click_button("Save and continue") }.to change {
case_log.reload.tenant_gender
}.from(NilClass).to("1")
visit("/case_logs/#{id}/tenant_ethnic_group")
choose("tenant-ethnic-group-2-field")
expect { click_button("Save and continue") }.to change {
case_log.reload.tenant_ethnic_group
}.from(NilClass).to("2")
visit("/case_logs/#{id}/tenant_nationality")
choose("tenant-nationality-0-field")
expect { click_button("Save and continue") }.to change {
case_log.reload.tenant_nationality
}.from(NilClass).to("0")
visit("/case_logs/#{id}/tenant_economic_status")
choose("tenant-economic-status-4-field")
expect { click_button("Save and continue") }.to change {
case_log.reload.tenant_economic_status
}.from(NilClass).to("4")
visit("/case_logs/#{id}/household_number_of_other_members")
fill_in(:household_number_of_other_members, with: 2)
expect { click_button("Save and continue") }.to change { expect { click_button("Save and continue") }.to change {
case_log.reload.household_number_of_other_members case_log.reload.send("#{question}")
}.from(NilClass).to(2) }.from(original_value).to(answer)
end
end end
end end
@ -102,6 +87,7 @@ RSpec.describe "Test Features" do
describe "Form flow is correct" do describe "Form flow is correct" do
context "given an ordered list of pages" do context "given an ordered list of pages" do
it "leads to the next one in the correct order" do it "leads to the next one in the correct order" do
pages = question_answers.keys
pages[0..-2].each_with_index do |val, index| pages[0..-2].each_with_index do |val, index|
visit("/case_logs/#{id}/#{val}") visit("/case_logs/#{id}/#{val}")
click_button("Save and continue") click_button("Save and continue")

Loading…
Cancel
Save