From 17352654f80cab52b3a262569f6644960917a879 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Tue, 10 May 2022 11:53:01 +0100 Subject: [PATCH] Add test for JSON derived and dependent on false options --- spec/fixtures/forms/2022_2023.json | 23 +++++++++++++++++++++++ spec/models/form_spec.rb | 8 ++++++++ 2 files changed, 31 insertions(+) diff --git a/spec/fixtures/forms/2022_2023.json b/spec/fixtures/forms/2022_2023.json index 8d856aa1c..e9fcb6990 100644 --- a/spec/fixtures/forms/2022_2023.json +++ b/spec/fixtures/forms/2022_2023.json @@ -94,6 +94,29 @@ "width": 10 } } + }, + "outstanding_amount_known": { + "header": "", + "description": "", + "questions": { + "tshortfall_known": { + "check_answer_label": "", + "header": "", + "hint_text": "", + "hidden_in_check_answers": true, + "type": "radio", + "answer_options": { + "0": { + "value": "Yes" + }, + "1": { + "value": "No" + } + } + } + }, + "derived": true, + "depends_on": [false] } } } diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index 43628ab78..2277b52f7 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -190,5 +190,13 @@ RSpec.describe Form, type: :model do expect(form.invalidated_page_questions(case_log).map(&:id).uniq).to eq(expected_invalid) end end + + context "when a page is marked as `derived`" do + let(:case_log) { FactoryBot.build(:case_log, :in_progress, startdate: Time.utc(2023, 2, 2, 10, 36, 49)) } + + it "does not count it's questions as invalidated" do + expect(form.enabled_page_questions(case_log).map(&:id).uniq).to include("tshortfall_known") + end + end end end