diff --git a/spec/views/form/page_view_spec.rb b/spec/views/form/page_view_spec.rb index ac7c8c9b6..5ea95f8e4 100644 --- a/spec/views/form/page_view_spec.rb +++ b/spec/views/form/page_view_spec.rb @@ -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_attribs) { { description: nil, hide_subsection_label: nil } } + let(:initial_question_attribs) { { type: "numeric", answer_options: nil, prefix: nil, suffix: nil } } + let(:page_attribs) { {} } + let(:question_attribs) { {} } 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_attribs) + assign_attributes(question, question_attribs) 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_attribs) + assign_attributes(question, initial_question_attribs) + end + + context "given a page with a description" do + let(:description) { "Test description with link." } + let(:page_attribs) { { description: description } } + let(:expected_html) { '

Test description with link.

' } + + 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_attribs) { { 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_attribs) { { 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_attribs) { { 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_attribs) { { 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_attribs) { { 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_attribs) { { 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_attribs) { { 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_attribs) { { type: "date", answer_options: nil } } it "renders the guidance partial for date questions" do expect(rendered).to match(expected_guidance) end