From fe81499abe448c5e00f85c80067dff9a5b7bc124 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Thu, 7 Oct 2021 10:25:20 +0100 Subject: [PATCH] Spec attrib merging --- ...imulus_controller_attribute_helper_spec.rb | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spec/helpers/stimulus_controller_attribute_helper_spec.rb b/spec/helpers/stimulus_controller_attribute_helper_spec.rb index d3ca1a5d4..e0dcbe551 100644 --- a/spec/helpers/stimulus_controller_attribute_helper_spec.rb +++ b/spec/helpers/stimulus_controller_attribute_helper_spec.rb @@ -17,5 +17,35 @@ RSpec.describe StimulusControllerAttributeHelper do "data-calculated": questions["basic_rent"]["fields-to-add"].to_json, }) end + + context "a question that requires multiple controllers" do + let(:question) { + { + "check_answer_label"=>"Basic Rent", + "header"=>"What is the basic rent?", + "hint_text"=>"Eligible for housing benefit or Universal Credit", + "type"=>"numeric", + "min"=>0, + "step"=>1, + "fields-to-add"=>["basic_rent", "service_charge", "personal_service_charge", "support_charge"], + "result-field"=>"total_charge", + "conditional_for" => { + "next_question": ">1" + } + } + } + let(:expected_attribs) { + { + "data-controller": "numeric-question conditional-question", + "data-action": "numeric-question#calculateFields conditional-question#displayConditional", + "data-target": "case-log-#{question['result-field'].to_s.dasherize}-field", + "data-calculated": question["fields-to-add"].to_json, + "data-info": question["conditional_for"].to_json + } + } + it "correctly merges html attributes" do + expect(stimulus_html_attributes(question)).to eq(expected_attribs) + end + end end end