You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.9 KiB
52 lines
1.9 KiB
require "rails_helper" |
|
|
|
RSpec.describe QuestionAttributeHelper do |
|
form_handler = FormHandler.instance |
|
let(:form) { form_handler.get_form("test_form") } |
|
let(:questions) { form.questions_for_page("rent") } |
|
|
|
describe "html attributes" do |
|
it "returns empty hash if fields-to-add or result-field are empty " do |
|
expect(stimulus_html_attributes(questions["tcharge"])).to eq({}) |
|
end |
|
|
|
it "returns html attributes if fields-to-add or result-field are not empty " do |
|
expect(stimulus_html_attributes(questions["brent"])).to eq({ |
|
"data-controller": "numeric-question", |
|
"data-action": "numeric-question#calculateFields", |
|
"data-target": "case-log-#{questions['brent']['result-field'].to_s.dasherize}-field", |
|
"data-calculated": questions["brent"]["fields-to-add"].to_json, |
|
}) |
|
end |
|
|
|
context "a question that requires multiple controllers" do |
|
let(:question) do |
|
{ |
|
"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" => %w[brent scharge pscharge supcharg], |
|
"result-field" => "tcharge", |
|
"conditional_for" => { |
|
"next_question": ">1", |
|
}, |
|
} |
|
end |
|
let(:expected_attribs) do |
|
{ |
|
"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, |
|
} |
|
end |
|
it "correctly merges html attributes" do |
|
expect(stimulus_html_attributes(question)).to eq(expected_attribs) |
|
end |
|
end |
|
end |
|
end
|
|
|