Skip to content

Commit 2b96e45

Browse files
committed
Add tasks for making individual languages live
1 parent 737bc08 commit 2b96e45

6 files changed

Lines changed: 258 additions & 8 deletions

File tree

app/services/form_task_list_service.rb

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,20 @@ def group_upgrade_url
193193

194194
def make_form_live_section_tasks
195195
[
196-
{
197-
task_name: share_preview_task_name,
198-
path: share_preview_path(@form.id),
199-
status: @task_statuses[:share_preview_status],
200-
active: @form.pages.any?,
201-
},
202-
make_live_task,
203-
]
196+
share_preview_task,
197+
(make_live_task unless display_make_languages_live_tasks?),
198+
(make_only_english_live_task if display_make_languages_live_tasks?),
199+
(make_only_welsh_live_task if display_make_languages_live_tasks?),
200+
].compact
201+
end
202+
203+
def share_preview_task
204+
{
205+
task_name: share_preview_task_name,
206+
path: share_preview_path(@form.id),
207+
status: @task_statuses[:share_preview_status],
208+
active: @form.pages.any?,
209+
}
204210
end
205211

206212
def make_live_task
@@ -215,6 +221,34 @@ def make_live_task
215221
}
216222
end
217223

224+
def make_only_english_live_task
225+
status = @task_statuses[:make_live_status]
226+
can_make_form_live = status == :not_started
227+
228+
{
229+
task_name: I18n.t("forms.task_list_create.make_form_live_section.make_english_form_live"),
230+
path: can_make_form_live ? make_language_live_path(@form.id, language: "en") : "",
231+
status:,
232+
active: can_make_form_live,
233+
}
234+
end
235+
236+
def make_only_welsh_live_task
237+
status = @task_statuses[:make_only_welsh_live_status]
238+
can_make_form_live = status == :not_started
239+
240+
{
241+
task_name: I18n.t("forms.task_list_create.make_form_live_section.make_welsh_form_live"),
242+
path: can_make_form_live ? make_language_live_path(@form.id, language: "cy") : "",
243+
status:,
244+
active: can_make_form_live,
245+
}
246+
end
247+
248+
def display_make_languages_live_tasks?
249+
@form.live_welsh_form_document.blank? && @form.has_welsh_translation?
250+
end
251+
218252
def live_title_name
219253
return I18n.t("forms.task_list_create.make_form_live_section.title") if @form.is_archived?
220254

app/services/task_status_service.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def all_task_statuses
3636
batch_submissions_status:,
3737
share_preview_status:,
3838
make_live_status:,
39+
make_only_english_live_status:,
40+
make_only_welsh_live_status:,
3941
welsh_language_status:,
4042
submission_email_status:,
4143
confirm_submission_email_status:,
@@ -139,6 +141,20 @@ def make_live_status
139141
:completed if @form.has_live_version
140142
end
141143

144+
def make_only_english_live_status
145+
return :not_started if @form.can_make_language_live?(language: "en")
146+
return :completed if @form.state == "live"
147+
148+
:cannot_start
149+
end
150+
151+
def make_only_welsh_live_status
152+
return :not_started if @form.can_make_language_live?(language: "cy")
153+
return :completed if @form.live_welsh_form_document.present?
154+
155+
:cannot_start
156+
end
157+
142158
def make_live_status_for_draft
143159
# If the form has a live Welsh version, we ignore missing Welsh translations
144160
# and show the make live task and link. In this case, we will show a warning

config/locales/en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,9 @@ en:
546546
547547
A group admin can request to upgrade the group so forms can be made live. You can <a href="%{group_members_path}">view the members of the group</a> to find a group admin.
548548
no_org_admin: You cannot make this form live because it’s in a ‘trial’ group.
549+
make_english_form_live: Make your English form live
549550
make_live: Make your form live
551+
make_welsh_form_live: Make your Welsh form live
550552
share_preview: Share a preview of your draft form
551553
title: Make your form live
552554
user_cannot_administer:

spec/models/form_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,8 @@
10201020
welsh_language_status: :optional,
10211021
share_preview_status: :completed,
10221022
make_live_status: :completed,
1023+
make_only_english_live_status: :completed,
1024+
make_only_welsh_live_status: :cannot_start,
10231025
}
10241026
expect(form.all_task_statuses).to eq expected_hash
10251027
end

spec/services/form_task_list_service_spec.rb

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,22 @@
469469
it "has the correct default status" do
470470
expect(section_rows.second[:status]).to eq :not_started
471471
end
472+
473+
context "when the form has Welsh translations" do
474+
let(:form) { create(:form, :ready_for_live, :with_welsh_translation, welsh_completed: false) }
475+
476+
it "has the make English live task without a link" do
477+
expect(section_rows.second[:task_name]).to eq I18n.t("forms.task_list_create.make_form_live_section.make_english_form_live")
478+
expect(section_rows.second[:path]).to eq ""
479+
expect(section_rows.second[:status]).to eq :cannot_start
480+
end
481+
482+
it "has the make Welsh live task without a link" do
483+
expect(section_rows.third[:task_name]).to eq I18n.t("forms.task_list_create.make_form_live_section.make_welsh_form_live")
484+
expect(section_rows.third[:path]).to eq ""
485+
expect(section_rows.third[:status]).to eq :cannot_start
486+
end
487+
end
472488
end
473489

474490
context "when form is live" do
@@ -487,6 +503,37 @@
487503
it "describes the task correctly" do
488504
expect(section_rows.second[:task_name]).to eq I18n.t("forms.task_list_edit.make_form_live_section.make_live")
489505
end
506+
507+
context "when the form has a draft with welsh translations" do
508+
before do
509+
allow(form).to receive(:has_welsh_translation?).and_return(true)
510+
end
511+
512+
it "has a link to make the English form live" do
513+
expect(section_rows.second[:task_name]).to eq I18n.t("forms.task_list_create.make_form_live_section.make_english_form_live")
514+
expect(section_rows.second[:path]).to eq "/forms/#{form.id}/make-live/en"
515+
expect(section_rows.second[:status]).to eq :not_started
516+
end
517+
518+
it "has the make Welsh live task without a link" do
519+
expect(section_rows.third[:task_name]).to eq I18n.t("forms.task_list_create.make_form_live_section.make_welsh_form_live")
520+
expect(section_rows.third[:path]).to eq ""
521+
expect(section_rows.third[:status]).to eq :cannot_start
522+
end
523+
524+
context "when the Welsh version can be made live" do
525+
before do
526+
allow(form).to receive(:can_make_language_live?).with(language: "en").and_return(true)
527+
allow(form).to receive(:can_make_language_live?).with(language: "cy").and_return(true)
528+
end
529+
530+
it "has a link to make the Welsh form live" do
531+
expect(section_rows.third[:task_name]).to eq "Make your Welsh form live"
532+
expect(section_rows.third[:path]).to eq "/forms/#{form.id}/make-live/cy"
533+
expect(section_rows.third[:status]).to eq :not_started
534+
end
535+
end
536+
end
490537
end
491538

492539
context "when the form is archived" do
@@ -496,6 +543,26 @@
496543
expect(section_rows.second[:task_name]).to eq "Make your form live"
497544
expect(section_rows.second[:path]).to eq "/forms/#{form.id}/make-live"
498545
end
546+
547+
context "when the form has a draft with welsh translations" do
548+
let(:form) { create(:form, :archived_with_draft) }
549+
550+
before do
551+
allow(form).to receive(:has_welsh_translation?).and_return(true)
552+
end
553+
554+
it "has a link to make the English form live" do
555+
expect(section_rows.second[:task_name]).to eq I18n.t("forms.task_list_create.make_form_live_section.make_english_form_live")
556+
expect(section_rows.second[:path]).to eq "/forms/#{form.id}/make-live/en"
557+
expect(section_rows.second[:status]).to eq :not_started
558+
end
559+
560+
it "has the make Welsh live task without a link" do
561+
expect(section_rows.third[:task_name]).to eq I18n.t("forms.task_list_create.make_form_live_section.make_welsh_form_live")
562+
expect(section_rows.third[:path]).to eq ""
563+
expect(section_rows.third[:status]).to eq :cannot_start
564+
end
565+
end
499566
end
500567
end
501568
end

spec/services/task_status_service_spec.rb

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
let(:current_user) { build(:user, role: :standard) }
1111

12+
before do
13+
form.set_task_status_service(task_status_service)
14+
end
15+
1216
describe "statuses" do
1317
describe "name status" do
1418
let(:form) { build(:form, :new_form, :with_group, group:) }
@@ -391,6 +395,129 @@
391395
end
392396
end
393397
end
398+
399+
describe "make_only_english_live_status" do
400+
let(:can_make_english_live) { false }
401+
let(:can_make_welsh_live) { false }
402+
403+
let(:form) { build(:form, :with_group, group:) }
404+
405+
before do
406+
allow(form).to receive(:can_make_language_live?).with(language: "en").and_return(can_make_english_live)
407+
allow(form).to receive(:can_make_language_live?).with(language: "cy").and_return(can_make_welsh_live)
408+
end
409+
410+
context "with a new form" do
411+
let(:form) { build(:form, :new_form, :with_group, group:) }
412+
413+
it "returns the correct default value" do
414+
expect(task_status_service.all_task_statuses[:make_only_english_live_status]).to eq :cannot_start
415+
end
416+
end
417+
418+
context "when the English version can be made live" do
419+
let(:can_make_english_live) { true }
420+
421+
it "returns not started" do
422+
expect(task_status_service.all_task_statuses[:make_only_english_live_status]).to eq :not_started
423+
end
424+
end
425+
426+
context "when the English version cannot be made live" do
427+
let(:can_make_english_live) { false }
428+
429+
context "when the form is live" do
430+
let(:form) { build(:form, :live, :with_group, group:) }
431+
432+
it "returns completed" do
433+
expect(task_status_service.all_task_statuses[:make_only_english_live_status]).to eq :completed
434+
end
435+
end
436+
437+
context "when the form is a draft" do
438+
let(:form) { build(:form, :ready_for_live, :with_group, group:) }
439+
440+
it "returns cannot_start" do
441+
expect(task_status_service.all_task_statuses[:make_only_english_live_status]).to eq :cannot_start
442+
end
443+
end
444+
445+
context "when the form is live with draft" do
446+
let(:form) { build(:form, :live_with_draft, :with_group, group:) }
447+
448+
it "returns cannot_start" do
449+
expect(task_status_service.all_task_statuses[:make_only_english_live_status]).to eq :cannot_start
450+
end
451+
end
452+
453+
context "when the form is archived" do
454+
let(:form) { build(:form, :archived, :with_group, group:) }
455+
456+
it "returns cannot_start" do
457+
expect(task_status_service.all_task_statuses[:make_only_english_live_status]).to eq :cannot_start
458+
end
459+
end
460+
461+
context "when the form is archived with draft" do
462+
let(:form) { build(:form, :archived_with_draft, :with_group, group:) }
463+
464+
it "returns cannot_start" do
465+
expect(task_status_service.all_task_statuses[:make_only_english_live_status]).to eq :cannot_start
466+
end
467+
end
468+
end
469+
end
470+
471+
describe "make_only_welsh_live_status" do
472+
let(:can_make_english_live) { true }
473+
let(:can_make_welsh_live) { false }
474+
475+
let(:form) { build(:form, :with_group, group:) }
476+
477+
before do
478+
allow(form).to receive(:can_make_language_live?).with(language: "en").and_return(can_make_english_live)
479+
allow(form).to receive(:can_make_language_live?).with(language: "cy").and_return(can_make_welsh_live)
480+
end
481+
482+
context "with a new form" do
483+
let(:form) { build(:form, :new_form, :with_group, group:) }
484+
485+
it "returns the correct default value" do
486+
expect(task_status_service.all_task_statuses[:make_only_welsh_live_status]).to eq :cannot_start
487+
end
488+
end
489+
490+
context "when the Welsh version can be made live" do
491+
let(:can_make_welsh_live) { true }
492+
493+
it "returns not started" do
494+
expect(task_status_service.all_task_statuses[:make_only_welsh_live_status]).to eq :not_started
495+
end
496+
end
497+
498+
context "when the Welsh version cannot be made live" do
499+
let(:can_make_welsh_live) { false }
500+
let(:welsh_form_document) { build(:form_document, :live, form:, language: "cy", content: form.as_form_document) }
501+
502+
before do
503+
allow(form).to receive(:live_welsh_form_document).and_return(welsh_form_document)
504+
end
505+
506+
context "when the form already has a live Welsh version" do
507+
it "returns completed" do
508+
expect(task_status_service.all_task_statuses[:make_only_welsh_live_status]).to eq :completed
509+
end
510+
end
511+
512+
context "when the form does not have a live Welsh version" do
513+
let(:welsh_form_document) { nil }
514+
515+
it "returns cannot start" do
516+
expect(task_status_service.all_task_statuses[:make_only_welsh_live_status]).to eq :cannot_start
517+
end
518+
end
519+
end
520+
end
394521
end
395522

396523
describe "#mandatory_tasks_completed" do
@@ -537,6 +664,8 @@
537664
share_preview_status: :completed,
538665
submission_email_status: :completed,
539666
confirm_submission_email_status: :completed,
667+
make_only_english_live_status: :completed,
668+
make_only_welsh_live_status: :cannot_start,
540669
}
541670
expect(task_status_service.all_task_statuses).to eq expected_hash
542671
end

0 commit comments

Comments
 (0)