Skip to content

Commit 2732da9

Browse files
committed
Add separate confirmation for making individual languages live
1 parent 83bc133 commit 2732da9

11 files changed

Lines changed: 213 additions & 9 deletions

File tree

app/controllers/forms/make_language_live_controller.rb

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,39 @@ def create
1414
return render_new(status: :unprocessable_content) unless @make_language_live_input.valid?
1515
return redirect_to form_path(@make_language_live_input.form.id) unless @make_language_live_input.confirmed?
1616

17-
@make_form_live_service = MakeFormLiveService.call(current_form:, current_user:)
17+
@make_form_live_service = MakeFormLiveService.call(current_form:, current_user:, language: params[:language])
1818
# TODO: actually make the language live
1919

20-
render "forms/make_live/confirmation", locals: {
20+
redirect_to make_language_live_show_confirmation_path
21+
end
22+
23+
def show_confirmation
24+
authorize current_form, :can_make_language_live?
25+
26+
@make_form_live_service = MakeFormLiveService.call(current_form:, current_user:, language: params[:language])
27+
28+
@go_to_make_welsh_live_input = GoToMakeWelshLiveInput.new
29+
30+
render "confirmation", locals: {
2131
current_form:,
2232
confirmation_page_title: @make_form_live_service.page_title,
2333
confirmation_page_body: @make_form_live_service.confirmation_page_body,
2434
language: params[:language],
2535
}
2636
end
2737

38+
def submit_confirmation
39+
authorize current_form, :can_make_language_live?
40+
41+
@go_to_make_welsh_live_input = GoToMakeWelshLiveInput.new(**go_to_make_welsh_live_input_params)
42+
43+
if @go_to_make_welsh_live_input.confirmed?
44+
redirect_to make_language_live_path(language: "cy")
45+
else
46+
redirect_to form_path
47+
end
48+
end
49+
2850
private
2951

3052
def make_language_live_input_params
@@ -34,5 +56,9 @@ def make_language_live_input_params
3456
def render_new(status: :ok)
3557
render "new", status:, locals: { current_form:, language: params[:language] }
3658
end
59+
60+
def go_to_make_welsh_live_input_params
61+
params.require(:forms_go_to_make_welsh_live_input).permit(:confirm)
62+
end
3763
end
3864
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Forms::GoToMakeWelshLiveInput < ConfirmActionInput
2+
end

app/services/make_form_live_service.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ def call(**args)
55
end
66
end
77

8-
def initialize(current_form:, current_user:)
8+
def initialize(current_form:, current_user:, language: nil)
99
@current_form = current_form
1010
@current_form_was_live = current_form.is_live?
1111
@current_form_was_archived = current_form.is_archived?
1212
@current_live_form = FormDocument::Content.from_form_document(current_form.live_form_document) if current_form.is_live?
1313
@current_user = current_user
14+
@language = language
1415
end
1516

1617
def make_live
@@ -29,6 +30,8 @@ def make_live
2930
def page_title
3031
return I18n.t("page_titles.your_form_is_live") if @current_form_was_archived
3132
return I18n.t("page_titles.your_changes_are_live") if @current_form_was_live
33+
return I18n.t("page_titles.your_english_form_is_live") if @language == "en"
34+
return I18n.t("page_titles.your_welsh_form_is_live") if @language == "cy"
3235

3336
I18n.t("page_titles.your_form_is_live")
3437
end
@@ -37,6 +40,7 @@ def confirmation_page_body
3740
return I18n.t("make_changes_live.confirmation.body_html_cy").html_safe if @current_form_was_live && @current_form.has_welsh_translation?
3841
return I18n.t("make_changes_live.confirmation.body_html").html_safe if @current_form_was_live
3942

43+
return I18n.t("make_live.confirmation.body_individual_language_html").html_safe if @language.present?
4044
return I18n.t("make_live.confirmation.body_html_cy").html_safe if @current_form.has_welsh_translation?
4145

4246
I18n.t("make_live.confirmation.body_html").html_safe
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<% set_page_title(confirmation_page_title) %>
2+
3+
<div class="govuk-grid-row">
4+
<div class="govuk-grid-column-two-thirds">
5+
<%= govuk_panel(title_text: confirmation_page_title) %>
6+
7+
<%= confirmation_page_body %>
8+
9+
<% if language == "en" %>
10+
<h2 class="govuk-heading-m"><%= t('make_live.confirmation.form_name_en') %></h2>
11+
12+
<p><%= current_form.name %></p>
13+
<% end %>
14+
15+
<% if language == "cy" %>
16+
<h2 class="govuk-heading-m"><%= t('make_live.confirmation.form_name_cy') %></h2>
17+
18+
<p><%= current_form.name_cy %></p>
19+
<% end %>
20+
21+
<% if language == "en" %>
22+
<%= render FormUrlComponent::View.new(
23+
runner_link: link_to_runner(Settings.forms_runner.url, current_form.id, current_form.form_slug, mode: :live),
24+
heading_text: t('make_live.confirmation.english_form_url'),
25+
button_text: t('make_live.confirmation.copy_english_url_to_clipboard')
26+
) %>
27+
<% end %>
28+
29+
<% if language == "cy" %>
30+
<%= render FormUrlComponent::View.new(
31+
runner_link: link_to_runner(Settings.forms_runner.url, current_form.id, current_form.form_slug, mode: :live, locale: "cy"),
32+
heading_text: t('make_live.confirmation.welsh_form_url'),
33+
button_text: t('make_live.confirmation.copy_welsh_url_to_clipboard')
34+
) %>
35+
<% end %>
36+
37+
<p>
38+
<%= govuk_link_to t("make_live.confirmation.continue_link"), live_form_path(current_form.id) %>
39+
</p>
40+
41+
<% if language == "en" %>
42+
<% if current_form.welsh_completed %>
43+
<%= form_with model: @go_to_make_welsh_live_input, url: make_language_live_submit_confirmation_path(form_id: current_form.id, language:) do |f| %>
44+
<%= f.govuk_collection_radio_buttons :confirm, @go_to_make_welsh_live_input.values, :itself, legend: { size: 'm', tag: 'h2' }, bold_labels: false %>
45+
<%= f.govuk_submit t("save_and_continue") %>
46+
<% end %>
47+
<% else %>
48+
<p>
49+
<%= t("make_live.confirmation.back_to_draft_link_html", url: form_path(current_form.id)) %>
50+
</p>
51+
<% end %>
52+
<% end %>
53+
</div>
54+
</div>

config/locales/en.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,7 @@ en:
11901190
<p>Completed forms will be sent to: <span class="govuk-!-text-break-word">%{submission_email}</span></p>
11911191
make_live:
11921192
confirmation:
1193+
back_to_draft_link_html: <a href="%{url}">Go back to your draft</a> to edit the Welsh version and make it live.
11931194
body_html: |
11941195
<p>
11951196
The form will not be indexed by search engines, so people will not be able to find it easily.
@@ -1199,12 +1200,18 @@ en:
11991200
<p>
12001201
The form will not be indexed by search engines, so people will not be able to find it easily. Contact your GOV⁠.⁠UK publishing team to publish links to your form on GOV⁠.⁠UK so people can find it.
12011202
</p>
1202-
continue_link: Continue to form details
1203+
body_individual_language_html: |
1204+
<p>
1205+
The form will not be indexed by search engines, so people will not be able to find it easily. Contact your GOV.UK publishing team to publish links to your form on GOV.UK so people can find it.
1206+
</p>
1207+
continue_link: Continue to the live form’s details
12031208
copy_english_url_to_clipboard: Copy English URL to clipboard
12041209
copy_welsh_url_to_clipboard: Copy Welsh URL to clipboard
12051210
english_form: English form
12061211
english_form_url: English form URL
12071212
form_name: Form name
1213+
form_name_cy: Welsh form name
1214+
form_name_en: English form name
12081215
welsh_form: Welsh form
12091216
welsh_form_url: Welsh form URL
12101217
new:
@@ -1527,7 +1534,9 @@ en:
15271534
welsh_translation: Add a Welsh version of your form
15281535
what_happens_next: Add information about what happens next
15291536
your_changes_are_live: Your changes are live
1537+
your_english_form_is_live: Your English form is live
15301538
your_form_is_live: Your form is live
1539+
your_welsh_form_is_live: Your Welsh form is live
15311540
pages:
15321541
answer_settings: Answer settings
15331542
change_order:
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
en:
3+
activemodel:
4+
errors:
5+
models:
6+
forms/go_to_make_welsh_live_input:
7+
attributes:
8+
confirm:
9+
blank: Select ‘Yes’ if you want to make your Welsh form live
10+
helpers:
11+
label:
12+
forms_go_to_make_welsh_live_input:
13+
confirm_options:
14+
'no': No, I’ll do that later
15+
'yes': 'Yes'
16+
legend:
17+
forms_go_to_make_welsh_live_input:
18+
confirm: Do you want to make your Welsh form live now?

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
post "/make-live" => "forms/make_live#create", as: :make_live_create
5757
get "/make-live/:language" => "forms/make_language_live#new", as: :make_language_live
5858
post "/make-live/:language" => "forms/make_language_live#create", as: :make_language_live_create
59+
get "/make-live/:language/success" => "forms/make_language_live#show_confirmation", as: :make_language_live_show_confirmation
60+
post "/make-live/:language/success" => "forms/make_language_live#submit_confirmation", as: :make_language_live_submit_confirmation
5961
get "/unarchive" => "forms/unarchive#new", as: :unarchive
6062
post "/unarchive" => "forms/unarchive#create", as: :unarchive_create
6163
get "/what-happens-next" => "forms/what_happens_next#new", as: :what_happens_next
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require "rails_helper"
2+
3+
RSpec.describe Forms::GoToMakeWelshLiveInput, type: :model do
4+
it "is invalid if blank" do
5+
confirm_archive_input = described_class.new(confirm: "")
6+
confirm_archive_input.validate(:confirm)
7+
8+
expect(confirm_archive_input.errors.full_messages_for(:confirm)).to include(
9+
"Confirm Select ‘Yes’ if you want to make your Welsh form live",
10+
)
11+
end
12+
end

spec/requests/forms/make_language_live_controller_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@
7171
raise
7272
end
7373

74-
it "renders the confirmation page" do
74+
it "redirects to the confirmation page" do
7575
post(make_language_live_path(form_id: form.id, language:), params: form_params)
76-
expect(response).to render_template(:confirmation)
76+
expect(response).to redirect_to(make_language_live_show_confirmation_path(form_id: form.id, language:))
7777
end
7878

7979
it "sends an email to the organisation admins" do
@@ -82,9 +82,9 @@
8282
end
8383

8484
context "and that form has not been made live before" do
85-
it "has the page title 'Your form is live'" do
85+
it "redirects to the confirmation page" do
8686
post(make_language_live_path(form_id: form.id, language:), params: form_params)
87-
expect(response.body).to include "Your form is live"
87+
expect(response).to redirect_to(make_language_live_show_confirmation_path(form_id: form.id, language:))
8888
end
8989

9090
it "creates a FormDocument" do
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
require "rails_helper"
2+
3+
describe "forms/make_language_live/confirmation.html.erb" do
4+
let(:has_welsh_translation) { false }
5+
let(:welsh_completed) { false }
6+
let(:go_to_make_welsh_live_input) { Forms::GoToMakeWelshLiveInput.new }
7+
let(:current_form) { OpenStruct.new(id: 1, name: "Form 1", name_cy: "Ffurflen 1", form_slug: "form-1", has_welsh_translation?: has_welsh_translation, welsh_completed:) }
8+
let(:language) { "en" }
9+
10+
before do
11+
assign(:go_to_make_welsh_live_input, go_to_make_welsh_live_input)
12+
render template: "forms/make_language_live/confirmation", locals: { current_form:, confirmation_page_title: "Your form is live", confirmation_page_body: I18n.t("make_changes_live.confirmation.body_html").html_safe, language: }
13+
end
14+
15+
context "when the language made live was English" do
16+
it "contains a confirmation panel with a title" do
17+
expect(rendered).to have_css(".govuk-panel--confirmation h1", text: /Your form is live/)
18+
end
19+
20+
it "contains the URL of the live form" do
21+
expect(rendered).to have_text("runner-host/form/1/form-1")
22+
end
23+
24+
it "contains a link to the live form details" do
25+
expect(rendered).to have_link("Continue to the live form’s details", href: live_form_path(1))
26+
end
27+
28+
it "displays form name as plain text" do
29+
expect(rendered).to have_css("h2", text: "English form name")
30+
expect(rendered).to have_css("p", text: "Form 1")
31+
expect(rendered).not_to have_css(".govuk-summary-list")
32+
end
33+
34+
it "displays the Form URL heading and button text" do
35+
expect(rendered).to have_css("h2", text: t("make_live.confirmation.english_form_url"))
36+
expect(rendered).to have_css("[data-copy-button-text='#{t('make_live.confirmation.copy_english_url_to_clipboard')}']")
37+
end
38+
39+
context "when the form has a completed Welsh version" do
40+
let(:has_welsh_translation) { true }
41+
let(:welsh_completed) { true }
42+
43+
it "renders radio buttons for making the draft changes live" do
44+
expect(rendered).to have_css("legend", text: I18n.t("helpers.legend.forms_go_to_make_welsh_live_input.confirm"))
45+
expect(rendered).to have_field(t("helpers.label.forms_go_to_make_welsh_live_input.confirm_options.yes"), type: "radio")
46+
expect(rendered).to have_field(t("helpers.label.forms_go_to_make_welsh_live_input.confirm_options.no"), type: "radio")
47+
end
48+
end
49+
end
50+
51+
context "when the language made live was Welsh" do
52+
let(:language) { "cy" }
53+
54+
it "contains a confirmation panel with a title" do
55+
expect(rendered).to have_css(".govuk-panel--confirmation h1", text: /Your form is live/)
56+
end
57+
58+
it "contains the URL of the live form" do
59+
expect(rendered).to have_text("runner-host/form/1/form-1.cy")
60+
end
61+
62+
it "contains a link to the live form details" do
63+
expect(rendered).to have_link("Continue to the live form’s details", href: live_form_path(1))
64+
end
65+
66+
it "displays form name as plain text" do
67+
expect(rendered).to have_css("h2", text: "Welsh form name")
68+
expect(rendered).to have_css("p", text: "Ffurflen 1")
69+
expect(rendered).not_to have_css(".govuk-summary-list")
70+
end
71+
72+
it "displays the Form URL heading and button text" do
73+
expect(rendered).to have_css("h2", text: t("make_live.confirmation.welsh_form_url"))
74+
expect(rendered).to have_css("[data-copy-button-text='#{t('make_live.confirmation.copy_welsh_url_to_clipboard')}']")
75+
end
76+
end
77+
end

0 commit comments

Comments
 (0)