Skip to content

Commit 27d2721

Browse files
authored
Merge pull request #1945 from alphagov/markdown-declaration
Add markdown declaration to check your answers page, if the form has it
2 parents 245ae15 + c917d58 commit 27d2721

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

app/views/forms/check_your_answers/show.html.erb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@
3030

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

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

38-
<%= form.govuk_submit(@current_context.form.declaration_text.present? ? t('form.check_your_answers.agree_and_submit') : t('form.check_your_answers.submit')) %>
39-
</div>
40-
41+
<% declaration_present = @current_context.form.try(:declaration_markdown).present? || @current_context.form.declaration_text.present? %>
42+
<%= form.govuk_submit(declaration_present ? t('form.check_your_answers.agree_and_submit') : t('form.check_your_answers.submit')) %> </div>
4143

4244
</div>
4345
<div class="govuk-grid-row">

spec/views/forms/check_your_answers/show.html.erb_spec.rb

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
require "rails_helper"
22

33
describe "forms/check_your_answers/show.html.erb" do
4-
let(:form) { build :form, :with_support, id: 1, declaration_text: }
4+
let(:form) { build :form, :with_support, id: 1, declaration_text:, declaration_markdown: }
55
let(:support_details) { OpenStruct.new(email: form.support_email) }
66
let(:context) { OpenStruct.new(form:) }
77
let(:full_width) { false }
88
let(:declaration_text) { nil }
9+
let(:declaration_markdown) { nil }
910
let(:email_confirmation_input) { build :email_confirmation_input }
1011
let(:question) { build :text, question_text: "Do you want to remain anonymous?", text: "Yes" }
1112
let(:steps) { [build(:step, question:, page: build(:page, :with_text_settings))] }
@@ -41,6 +42,35 @@
4142
end
4243
end
4344

45+
context "when the form has a markdown declaration and declaration text" do
46+
let(:declaration_text) { "You should agree to all terms before submitting" }
47+
let(:declaration_markdown) { "This is the markdown decalaration\n\nsecond paragraph" }
48+
49+
it "displays the declaration heading" do
50+
expect(rendered).to have_css("h2", text: "Declaration")
51+
end
52+
53+
it "displays declaration markdown" do
54+
expect(rendered).to have_css("p", text: "second paragraph")
55+
end
56+
57+
it "does not display declaration text" do
58+
expect(rendered).not_to have_css("p", text: form.declaration_text)
59+
end
60+
end
61+
62+
context "when the form has a markdown declaration only" do
63+
let(:declaration_markdown) { "This is the markdown decalaration\n\nsecond paragraph" }
64+
65+
it "displays the declaration heading" do
66+
expect(rendered).to have_css("h2", text: "Declaration")
67+
end
68+
69+
it "displays declaration markdown" do
70+
expect(rendered).to have_css("p", text: "second paragraph")
71+
end
72+
end
73+
4474
it "displays the summary list two-thirds width" do
4575
expect(rendered).not_to have_css(".govuk-grid-column-full .govuk-summary-list")
4676
expect(rendered).to have_css(".govuk-grid-column-two-thirds-from-desktop .govuk-summary-list")

0 commit comments

Comments
 (0)