@ -11,7 +11,10 @@ RSpec.describe "form/page" do
let ( :subsection ) { form . get_subsection ( " income_and_benefits " ) }
let ( :page ) { form . get_page ( " net_income " ) }
let ( :question ) { page . questions . find { | q | q . id == " earnings " } }
let ( :initial_attribs ) { { type : " numeric " , answer_options : nil , prefix : nil , suffix : nil } }
let ( :initial_page_attributes ) { { description : nil , hide_subsection_label : nil } }
let ( :initial_question_attributes ) { { type : " numeric " , answer_options : nil , prefix : nil , suffix : nil } }
let ( :page_attributes ) { { } }
let ( :question_attributes ) { { } }
def assign_attributes ( object , attrs )
attrs . each_pair do | attr , value |
@ -23,18 +26,46 @@ RSpec.describe "form/page" do
assign ( :case_log , case_log )
assign ( :page , page )
assign ( :subsection , subsection )
assign_attributes ( question , attribs )
assign_attributes ( page , page_attributes )
assign_attributes ( question , question_attributes )
render
end
after do
# Revert any changes we've made to avoid affecting other specs as the form,
# subsection, page, question objects being acted on are in memory
assign_attributes ( question , initial_attribs )
assign_attributes ( page , initial_page_attributes )
assign_attributes ( question , initial_question_attributes )
end
context " given a page with a description " do
let ( :description ) { " Test description <a class= \" govuk-link \" href= \" /files/privacy-notice.pdf \" >with link</a>. " }
let ( :page_attributes ) { { description : description } }
let ( :expected_html ) { '<p class="govuk-body govuk-body-m">Test description <a class="govuk-link" href="/files/privacy-notice.pdf">with link</a>.</p>' }
it " renders the description " do
expect ( rendered ) . to match ( expected_html )
end
end
context " given a page with a header " do
it " renders the header and the subsection label " do
expect ( rendered ) . to match ( page . header )
expect ( rendered ) . to match ( subsection . label )
end
end
context " given a page with a header and hide_subsection_label true " do
let ( :page_attributes ) { { hide_subsection_label : true } }
it " renders the header but not the subsection label " do
expect ( rendered ) . to match ( page . header )
expect ( rendered ) . not_to match ( subsection . label )
end
end
context " given a numeric question with prefix and suffix " do
let ( :attribs ) { { type : " numeric " , prefix : " £ " , suffix : " every week " } }
let ( :question_ attribute s ) { { type : " numeric " , prefix : " £ " , suffix : " every week " } }
it " renders prefix and suffix text " do
expect ( rendered ) . to match ( / govuk-input__prefix / )
@ -48,42 +79,42 @@ RSpec.describe "form/page" do
let ( :expected_guidance ) { / What counts as income? / }
context " with radio type " do
let ( :attribs ) { { type : " radio " , answer_options : { " 1 " : " A " , " 2 " : " B " } } }
let ( :question_ attribute s ) { { type : " radio " , answer_options : { " 1 " : " A " , " 2 " : " B " } } }
it " renders the guidance partial for radio questions " do
expect ( rendered ) . to match ( expected_guidance )
end
end
context " with text type " do
let ( :attribs ) { { type : " text " , answer_options : nil } }
let ( :question_ attribute s ) { { type : " text " , answer_options : nil } }
it " renders the guidance partial for text questions " do
expect ( rendered ) . to match ( expected_guidance )
end
end
context " with numeric type " do
let ( :attribs ) { { type : " numeric " , answer_options : nil } }
let ( :question_ attribute s ) { { type : " numeric " , answer_options : nil } }
it " renders the guidance partial for numeric questions " do
expect ( rendered ) . to match ( expected_guidance )
end
end
context " with select type " do
let ( :attribs ) { { type : " select " , answer_options : { " 1 " : " A " , " 2 " : " B " } } }
let ( :question_ attribute s ) { { type : " select " , answer_options : { " 1 " : " A " , " 2 " : " B " } } }
it " renders the guidance partial for select questions " do
expect ( rendered ) . to match ( expected_guidance )
end
end
context " with checkbox type " do
let ( :attribs ) { { type : " checkbox " , answer_options : { " 1 " : " A " , " 2 " : " B " } } }
let ( :question_ attribute s ) { { type : " checkbox " , answer_options : { " 1 " : " A " , " 2 " : " B " } } }
it " renders the guidance partial for checkbox questions " do
expect ( rendered ) . to match ( expected_guidance )
end
end
context " with date type " do
let ( :attribs ) { { type : " date " , answer_options : nil } }
let ( :question_ attribute s ) { { type : " date " , answer_options : nil } }
it " renders the guidance partial for date questions " do
expect ( rendered ) . to match ( expected_guidance )
end