Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions app/views/forms/check_your_answers/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@

<%= form.hidden_field :confirmation_email_reference, id: 'confirmation-email-reference' %>

<%if @current_context.form.declaration_text.present? %>
<%if @current_context.form.try(:declaration_markdown).present? %>
<h2 class="govuk-heading-m govuk-!-margin-top-7"><%= t('form.check_your_answers.declaration') %></h2>
<%= HtmlMarkdownSanitizer.new.render_scrubbed_markdown(@current_context.form.declaration_markdown) %>
<%elsif @current_context.form.declaration_text.present? %>
<h2 class="govuk-heading-m govuk-!-margin-top-7"><%= t('form.check_your_answers.declaration') %></h2>
<%= HtmlMarkdownSanitizer.new.render_scrubbed_html(@current_context.form.declaration_text) %>
<% end %>

<%= form.govuk_submit(@current_context.form.declaration_text.present? ? t('form.check_your_answers.agree_and_submit') : t('form.check_your_answers.submit')) %>
</div>

<% declaration_present = @current_context.form.try(:declaration_markdown).present? || @current_context.form.declaration_text.present? %>
<%= form.govuk_submit(declaration_present ? t('form.check_your_answers.agree_and_submit') : t('form.check_your_answers.submit')) %> </div>

</div>
<div class="govuk-grid-row">
Expand Down
32 changes: 31 additions & 1 deletion spec/views/forms/check_your_answers/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
require "rails_helper"

describe "forms/check_your_answers/show.html.erb" do
let(:form) { build :form, :with_support, id: 1, declaration_text: }
let(:form) { build :form, :with_support, id: 1, declaration_text:, declaration_markdown: }
let(:support_details) { OpenStruct.new(email: form.support_email) }
let(:context) { OpenStruct.new(form:) }
let(:full_width) { false }
let(:declaration_text) { nil }
let(:declaration_markdown) { nil }
let(:email_confirmation_input) { build :email_confirmation_input }
let(:question) { build :text, question_text: "Do you want to remain anonymous?", text: "Yes" }
let(:steps) { [build(:step, question:, page: build(:page, :with_text_settings))] }
Expand Down Expand Up @@ -41,6 +42,35 @@
end
end

context "when the form has a markdown declaration and declaration text" do
let(:declaration_text) { "You should agree to all terms before submitting" }
let(:declaration_markdown) { "This is the markdown decalaration\n\nsecond paragraph" }

it "displays the declaration heading" do
expect(rendered).to have_css("h2", text: "Declaration")
end

it "displays declaration markdown" do
expect(rendered).to have_css("p", text: "second paragraph")
end

it "does not display declaration text" do
expect(rendered).not_to have_css("p", text: form.declaration_text)
end
end

context "when the form has a markdown declaration only" do
let(:declaration_markdown) { "This is the markdown decalaration\n\nsecond paragraph" }

it "displays the declaration heading" do
expect(rendered).to have_css("h2", text: "Declaration")
end

it "displays declaration markdown" do
expect(rendered).to have_css("p", text: "second paragraph")
end
end

it "displays the summary list two-thirds width" do
expect(rendered).not_to have_css(".govuk-grid-column-full .govuk-summary-list")
expect(rendered).to have_css(".govuk-grid-column-two-thirds-from-desktop .govuk-summary-list")
Expand Down