From 8195c81a3a6a7d64df8d3ff7f8af1f6388b4a3d8 Mon Sep 17 00:00:00 2001 From: Kat Date: Tue, 19 Oct 2021 09:17:12 +0100 Subject: [PATCH] Add tests for conditional question displaying --- spec/features/case_log_spec.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index d2f0bf951..419c1e09b 100644 --- a/spec/features/case_log_spec.rb +++ b/spec/features/case_log_spec.rb @@ -191,6 +191,7 @@ RSpec.describe "Test Features" do describe "check answers page" do let(:subsection) { "household_characteristics" } + let(:conditional_subsection) { "conditional_question" } context "when the user needs to check their answers for a subsection" do it "can be visited by URL" do @@ -255,6 +256,35 @@ RSpec.describe "Test Features" do expect(page).to have_content("You answered all the questions") assert_selector "a", text: "Answer the missing questions", count: 0 end + + it "does not display conditional questions that were not visited" do + visit("case_logs/#{id}/#{conditional_subsection}/check_answers") + question_labels = ["Has the condition been met?"] + question_labels.each do |label| + expect(page).to have_content(label) + end + + excluded_question_labels = ["Has the next condition been met?", "Has the condition not been met?"] + excluded_question_labels.each do |label| + expect(page).not_to have_content(label) + end + end + + it "displays conditional question that were visited" do + visit("/case_logs/#{id}/conditional_question") + choose("case-log-pregnancy-no-field") + click_button("Save and continue") + visit("/case_logs/#{id}/#{conditional_subsection}/check_answers") + question_labels = ["Has the condition been met?", "Has the condition not been met?"] + question_labels.each do |label| + expect(page).to have_content(label) + end + + excluded_question_labels = ["Has the next condition been met?"] + excluded_question_labels.each do |label| + expect(page).not_to have_content(label) + end + end end end