Skip to content

Commit

Permalink
Merge pull request #1712 from alphagov/update-file-upload-content
Browse files Browse the repository at this point in the history
Update file upload content
  • Loading branch information
stephencdaly authored Jan 17, 2025
2 parents 7daddab + d95fc0d commit c7f9f4b
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 6 deletions.
6 changes: 6 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ def hint_for_edit_page_field(field, answer_type, answer_settings)
t("helpers.hint.page.#{field}.#{key}", default: t("helpers.hint.page.#{field}.default"))
end

def question_text_label(answer_type, answer_settings)
key = translation_key_for_answer_type(answer_type, answer_settings)
translation_path = "helpers.label.pages_question_input.question_text"
t("#{translation_path}.#{key}", default: t("#{translation_path}.default"))
end

def govuk_assets_path
"/node_modules/govuk-frontend/dist/govuk/assets"
end
Expand Down
13 changes: 10 additions & 3 deletions app/views/pages/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<%= form_with model: [form_object, question_input], url: action_path do |f| %>
<%= f.govuk_error_summary %>

<%= f.govuk_text_field :question_text, label: { size: 'm' }, hint: { text: hint_for_edit_page_field("question_text", draft_question.answer_type, draft_question.answer_settings) } %>
<% if question_input.answer_type == "file" %>
<p class="govuk-body"><%=t('helpers.label.pages_question_input.file_body_html')%></p>
<% end %>

<%= f.govuk_text_field :question_text,
label: { size: 'm', text: question_text_label(draft_question.answer_type, draft_question.answer_settings) },
hint: { text: hint_for_edit_page_field("question_text", draft_question.answer_type, draft_question.answer_settings) }
%>

<hr class="govuk-section-break govuk-section-break--m govuk-section-break--visible" />

Expand All @@ -14,7 +21,7 @@
<%= govuk_summary_list(**PageSummaryData::GuidanceService.call(form: form_object, draft_question:).build_data) %>

<% else %>
<p><%= t("guidance.instructions") %></p>
<p><%= hint_for_edit_page_field("guidance", draft_question.answer_type, draft_question.answer_settings) %></p>

<p>
<% guidance_link = unless is_new_page
Expand All @@ -34,7 +41,7 @@
<hr class="govuk-section-break govuk-section-break--m govuk-section-break--visible" />
<% end %>

<% if question_input.answer_type == "selection" %>
<% if question_input.answer_type == "selection" || question_input.answer_type == "file" %>
<%= f.hidden_field :is_repeatable, value: false %>
<% else %>
<%= f.govuk_collection_radio_buttons :is_repeatable, question_input.repeatable_options, :id, :name, :description, legend: { size: 'm', tag: 'h2' }, bold_labels: false %>
Expand Down
13 changes: 11 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,6 @@ en:
guidance:
add_guidance: Add guidance
guidance: Guidance
instructions: Only add guidance if you need to give a longer explanation of how to answer the question, or to format your content with paragraphs, headings, lists or links.
markdown_editor:
edit_markdown_link: Edit guidance text
preview:
Expand Down Expand Up @@ -588,13 +587,17 @@ en:
organisation_id: Currently, GOV.UK Forms is only available for central government organisations that publish content on the GOV.UK website.
page:
answer_type: The answer will be checked to make sure it’s in the selected format.
guidance:
default: Only add guidance if you need to give a longer explanation of how to answer the question, or to format your content with paragraphs, headings, lists or links.
file: Only add guidance if you need to give a longer explanation of what the uploaded file needs to contain, or to format your content with paragraphs, headings, lists or links.
hint_text:
address: You can add a short hint to help people answer the question. For example, you could tell people how you’ll use their address.
checkbox: You can add a short hint to help people answer the question. For a question where people can select more than one answer you might want to use ‘Select all that apply’.
date: You can add a short hint to help people answer the question. For a date question you could use ‘For example, 27 3 2007’.
date_of_birth: You can add a short hint to help people answer the question. For a date of birth question you could use ‘For example, 27 3 1998’.
default: You can add a short hint to help people answer the question. For example, to explain the format the answer should be in, or where to find the information you’ve asked for.
email: You could add a short hint to tell people how you’ll use their email address. For example, ‘We’ll only use your email address to contact you about your application.’
file: You can add a short hint to help people upload the file you need. For example, you might need the file to contain specific information.
long_text: You can add a short hint to help people answer the question. For example, you could give a bit more detail about the information you need.
name: You can add a short hint to help people answer the question. For example, you might need to ask people to enter their name as it’s written on an official document such as a passport or driving licence.
national_insurance_number: You can add a short hint to help people answer the question. For example, ‘It’s on your National Insurance card, benefit letter, payslip or P60. For example, QQ 12 34 56 C.’
Expand All @@ -611,6 +614,7 @@ en:
date_of_birth: Ask the question the way you would in person. For example, ‘What’s your date of birth?’
default: Ask a question the way you would in person. For example ‘What is your address?’
email: Ask the question the way you would in person. For example, ‘What’s your email address?’
file: Be specific about the file you want to receive. For example ’Upload your annual report’.
long_text: Ask the question the way you would in person. For example, ‘Why do you want to apply for this role?’
name: Ask the question the way you would in person. For example, ‘What’s your name?’
national_insurance_number: Ask the question the way you would in person. For example, ‘What’s your National Insurance number?’
Expand Down Expand Up @@ -744,14 +748,19 @@ en:
default_answer_value: Select an answer
default_goto_page_id: Select a question or page
pages_question_input:
file_body_html: |
<p>People will be able to upload one image or document up to 7MB in size.</p>
<p>You can have up to 4 file upload questions in a form.</p>
hint_text: Hint text (optional)
is_optional_options:
'false': Mandatory
'true': Optional
is_repeatable_options:
'false': No - this question can only be answered once
'true': 'Yes'
question_text: Question text
question_text:
default: Question text
file: Ask for a file
pages_secondary_skip_input:
default_goto_page_id: Select a question or page
default_routing_page_id: Select a question
Expand Down
31 changes: 30 additions & 1 deletion spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
end
end

describe "hint_for_edit_page_field" do
describe "#hint_for_edit_page_field" do
context "with an answer type that has custom text" do
let(:answer_type) { "email" }
let(:answer_settings) { {} }
Expand All @@ -158,6 +158,35 @@
expect(helper.hint_for_edit_page_field("hint_text", answer_type, answer_settings)).to eq(I18n.t("helpers.hint.page.hint_text.default"))
end
end

context "with the file answer type" do
let(:answer_type) { "file" }
let(:answer_settings) { {} }

it "returns the hint text for the file answer type" do
expect(helper.hint_for_edit_page_field("question_text", answer_type, answer_settings)).to eq(I18n.t("helpers.hint.page.question_text.file"))
end
end
end

describe "#question_text_label" do
context "with an answer type that does not have custom text" do
let(:answer_type) { "some_random_string" }
let(:answer_settings) { {} }

it "returns the default question text label" do
expect(helper.question_text_label(answer_type, answer_settings)).to eq(I18n.t("helpers.label.pages_question_input.question_text.default"))
end
end

context "with the file answer type" do
let(:answer_type) { "file" }
let(:answer_settings) { {} }

it "returns the question text label for the file answer type" do
expect(helper.question_text_label(answer_type, answer_settings)).to eq(I18n.t("helpers.label.pages_question_input.question_text.file"))
end
end
end

describe "#govuk_assets_path" do
Expand Down
38 changes: 38 additions & 0 deletions spec/views/pages/_forms.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

it "has a field with the question text" do
expect(rendered).to have_field(type: "text", with: question_input.question_text)
expect(rendered).to have_text(I18n.t("helpers.label.pages_question_input.question_text.default"))
end

it "has a field with the hint text" do
Expand Down Expand Up @@ -79,6 +80,10 @@
expect(rendered).to have_link(text: I18n.t("guidance.add_guidance"), href: guidance_new_path(form_id: form.id))
end

it "contains a hint for guidance" do
expect(rendered).to have_text(I18n.t("helpers.hint.page.guidance.default"))
end

context "when it is not a new page" do
let(:is_new_page) { false }

Expand Down Expand Up @@ -128,4 +133,37 @@
expect(rendered).to have_text(draft_question.guidance_markdown)
end
end

it "does not display the file body text" do
expect(rendered).not_to have_text(I18n.t("helpers.label.pages_question_input.file_body_html"))
end

context "when the answer type is file" do
let(:page) { build :page, :with_hints, answer_type: "file", id: 2, form_id: form.id }
let(:draft_question) { build :draft_question, answer_type: "file" }
let(:question_input) do
build :question_input,
answer_type: page.answer_type,
question_text: page.question_text,
hint_text: page.hint_text,
answer_settings: page.answer_settings,
draft_question:
end

it "displays the file body text" do
expect(rendered).to include(I18n.t("helpers.label.pages_question_input.file_body_html"))
end

it "has a field with the file question text" do
expect(rendered).to have_text(I18n.t("helpers.label.pages_question_input.question_text.file"))
end

it "contains a hint for guidance" do
expect(rendered).to have_text(I18n.t("helpers.hint.page.guidance.file"))
end

it "does not have the radio input for repeatable" do
expect(rendered).not_to have_field("pages_question_input[is_repeatable]", type: :radio)
end
end
end

0 comments on commit c7f9f4b

Please sign in to comment.