Browse Source
* Hackety hack hack * Leave JS hooks until text conditionals are updated as well * Fix JS errors and remove UJS * Reload the GOV UK frontend JS * Fix armed forces case * Remove obsolete tests and config * Temo fix for household members question * Unit test * Add helper unit test * Correctly failing spec * We still need stimulus to clear answers * Fix styling issues * Refactor style logic into helper * Form fix * Conditional check box questions are shown on a new page * Update readme * Fix date bug * Clear conditional date fields if invalidated by top level answer Co-authored-by: Stéphane Meny <smeny@users.noreply.github.com>pull/245/head
baarkerlounger
3 years ago
committed by
GitHub
27 changed files with 235 additions and 129 deletions
@ -0,0 +1,25 @@ |
|||||||
|
module QuestionViewHelper |
||||||
|
def caption(caption_text, page_header, conditional) |
||||||
|
return nil unless caption_text && page_header.blank? && !conditional |
||||||
|
|
||||||
|
{ text: caption_text.html_safe, size: "l" } |
||||||
|
end |
||||||
|
|
||||||
|
def legend(question, page_header, conditional) |
||||||
|
{ |
||||||
|
text: question.header.html_safe, |
||||||
|
size: label_size(page_header, conditional), |
||||||
|
tag: label_tag(page_header, conditional), |
||||||
|
} |
||||||
|
end |
||||||
|
|
||||||
|
private |
||||||
|
|
||||||
|
def label_size(page_header, conditional) |
||||||
|
page_header.blank? && !conditional ? "l" : "m" |
||||||
|
end |
||||||
|
|
||||||
|
def label_tag(page_header, conditional) |
||||||
|
page_header.blank? && !conditional ? "h1" : "h2" |
||||||
|
end |
||||||
|
end |
@ -1,15 +1,28 @@ |
|||||||
<%= render partial: "form/guidance/#{question.guidance_partial}" if question.guidance_partial %> |
<%= render partial: "form/guidance/#{question.guidance_partial}" if question.guidance_partial %> |
||||||
|
|
||||||
<%= f.govuk_radio_buttons_fieldset question.id.to_sym, |
<%= f.govuk_radio_buttons_fieldset question.id.to_sym, |
||||||
caption: caption && !page_header.present? ? { text: caption.html_safe, size: "l" } : nil, |
caption: caption(caption_text, page_header, conditional), |
||||||
legend: { text: question.header.html_safe, size: !page_header.present? ? "l" : "m", tag: !page_header.present? ? "h1" : "h2" }, |
legend: legend(question, page_header, conditional), |
||||||
hint: { text: question.hint_text&.html_safe } do %> |
hint: { text: question.hint_text&.html_safe } do %> |
||||||
|
|
||||||
<% question.answer_options.map do |key, val| %> |
<% question.answer_options.map do |key, val| %> |
||||||
<% if key.starts_with?("divider") %> |
<% if key.starts_with?("divider") %> |
||||||
<%= f.govuk_radio_divider %> |
<%= f.govuk_radio_divider %> |
||||||
<% else %> |
<% else %> |
||||||
<%= f.govuk_radio_button question.id, val, label: { text: val }, **stimulus_html_attributes(question) %> |
<% conditional_question = find_conditional_question(@page, question, val) %> |
||||||
|
<% if conditional_question.nil? %> |
||||||
|
<%= f.govuk_radio_button question.id, val, label: { text: val }, **stimulus_html_attributes(question) %> |
||||||
|
<% else %> |
||||||
|
<%= f.govuk_radio_button question.id, val, label: { text: val }, **stimulus_html_attributes(question) do %> |
||||||
|
<%= render partial: "#{conditional_question.type}_question", locals: { |
||||||
|
question: conditional_question, |
||||||
|
caption_text: caption_text, |
||||||
|
page_header: page_header, |
||||||
|
f: f, |
||||||
|
conditional: true |
||||||
|
} %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
<% end %> |
<% end %> |
||||||
<% end %> |
<% end %> |
||||||
<% end %> |
<% end %> |
||||||
|
@ -0,0 +1,8 @@ |
|||||||
|
import { initAll } from "govuk-frontend"; |
||||||
|
import { Controller } from "@hotwired/stimulus"; |
||||||
|
|
||||||
|
export default class extends Controller { |
||||||
|
connect() { |
||||||
|
initAll() |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,75 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe QuestionViewHelper do |
||||||
|
let(:page_header) { "Some Page Header" } |
||||||
|
let(:conditional) { false } |
||||||
|
|
||||||
|
describe "caption" do |
||||||
|
let(:subject) { caption(caption_text, page_header, conditional) } |
||||||
|
let(:caption_text) { "Some text" } |
||||||
|
let(:caption_options_hash) { { text: caption_text.html_safe, size: "l" } } |
||||||
|
|
||||||
|
context "a page without a header" do |
||||||
|
let(:page_header) { nil } |
||||||
|
|
||||||
|
it "returns an options hash" do |
||||||
|
expect(subject).to eq(caption_options_hash) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "a page with a header" do |
||||||
|
it "returns nil" do |
||||||
|
expect(subject).to be_nil |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "a conditional question" do |
||||||
|
let(:conditional) { true } |
||||||
|
it "returns nil" do |
||||||
|
expect(subject).to be_nil |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "a question without a caption" do |
||||||
|
let(:caption_text) { nil } |
||||||
|
|
||||||
|
it "returns nil" do |
||||||
|
expect(subject).to be_nil |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "legend" do |
||||||
|
let(:question) { OpenStruct.new(header: "Some question header") } |
||||||
|
let(:subject) { legend(question, page_header, conditional) } |
||||||
|
let(:size) { "m" } |
||||||
|
let(:tag) { "h2" } |
||||||
|
let(:legend_options_hash) do |
||||||
|
{ text: "Some question header".html_safe, size: size, tag: tag } |
||||||
|
end |
||||||
|
|
||||||
|
context "a page with a header" do |
||||||
|
it "returns an options hash with a medium question header" do |
||||||
|
expect(subject).to eq(legend_options_hash) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "a page without a header" do |
||||||
|
let(:page_header) { nil } |
||||||
|
let(:size) { "l" } |
||||||
|
let(:tag) { "h1" } |
||||||
|
|
||||||
|
it "returns an options hash with a large question header" do |
||||||
|
expect(subject).to eq(legend_options_hash) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "a conditional question" do |
||||||
|
let(:conditional) { true } |
||||||
|
|
||||||
|
it "returns an options hash with a medium question header" do |
||||||
|
expect(subject).to eq(legend_options_hash) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue