Skip to content

Commit adb1384

Browse files
committed
Change Tasklist show live logic
The tasklist should offer the link for making a form live even if the Welsh hasn't been updated. This only happens if there is an existing live Welsh form document. This is to allow us to show a warning message to the user in place of the make live task. For the tasklist to show the task correctly, the task must have a status which isn't :cannot_start. It must have a valid link and active must be true. The previous logic for producing the task used status from the TaskStatusService and form#all_ready_for_live? to determine if the task should be active. This commit changes the code to just use the TaskStatusService. This allows us to show the link even if the form cannot be made live yet. Form#all_ready_for_live? is still used in the controller code to prevent the form actually being made live if it is not ready.
1 parent 96274ff commit adb1384

File tree

3 files changed

+67
-15
lines changed

3 files changed

+67
-15
lines changed

app/services/form_task_list_service.rb

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,22 @@ def make_form_live_section_tasks
195195
status: @task_statuses[:share_preview_status],
196196
active: @form.pages.any?,
197197
},
198-
{
199-
task_name: live_task_name,
200-
path: live_path,
201-
status: @task_statuses[:make_live_status],
202-
active: @form.all_ready_for_live?,
203-
},
198+
make_live_task,
204199
]
205200
end
206201

202+
def make_live_task
203+
status = @task_statuses[:make_live_status]
204+
can_make_form_live = status == :not_started
205+
206+
{
207+
task_name: live_task_name,
208+
path: can_make_form_live ? make_live_path(@form.id) : "",
209+
status: status,
210+
active: can_make_form_live,
211+
}
212+
end
213+
207214
def live_title_name
208215
return I18n.t("forms.task_list_create.make_form_live_section.title") if @form.is_archived?
209216

@@ -220,12 +227,6 @@ def live_task_name
220227
I18n.t("forms.task_list_#{create_or_edit}.make_form_live_section.make_live")
221228
end
222229

223-
def live_path
224-
return "" unless @form.all_ready_for_live?
225-
226-
make_live_path(@form.id)
227-
end
228-
229230
def statuses_by_user
230231
statuses = @task_statuses
231232

app/services/task_status_service.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ def initialize(form:)
33
@form = form
44
end
55

6-
def mandatory_tasks_completed?
7-
incomplete_tasks.empty?
6+
def mandatory_tasks_completed?(ignore_missing_welsh: false)
7+
if ignore_missing_welsh
8+
incomplete_tasks.reject { |task| task == :missing_welsh_translations }.empty?
9+
else
10+
incomplete_tasks.empty?
11+
end
812
end
913

1014
def incomplete_tasks
@@ -130,7 +134,12 @@ def make_live_status
130134
end
131135

132136
def make_live_status_for_draft
133-
mandatory_tasks_completed? ? :not_started : :cannot_start
137+
# If the form has a live Welsh version, we ignore missing Welsh translations
138+
# and show the make live task and link. In this case, we will show a warning
139+
# message on the make live page asking the user to update the Welsh before
140+
# the form can be made live.
141+
ignore_missing_welsh = @form.live_welsh_form_document.present?
142+
mandatory_tasks_completed?(ignore_missing_welsh:) ? :not_started : :cannot_start
134143
end
135144

136145
def welsh_translations_invalid

spec/services/task_status_service_spec.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,18 @@
376376
expect(task_status_service.mandatory_tasks_completed?).to be true
377377
end
378378
end
379+
380+
context "when missing_welsh_translations is present" do
381+
let(:form) { build(:form, :ready_for_live, :with_welsh_translation, welsh_completed: false) }
382+
383+
it "when ignore_missing_welsh is true returns true" do
384+
expect(task_status_service.mandatory_tasks_completed?(ignore_missing_welsh: true)).to be true
385+
end
386+
387+
it "without ignore_missing_welsh returns false" do
388+
expect(task_status_service.mandatory_tasks_completed?).to be false
389+
end
390+
end
379391
end
380392

381393
describe "#incomplete_tasks" do
@@ -469,6 +481,36 @@
469481
}
470482
expect(task_status_service.task_statuses).to eq expected_hash
471483
end
484+
485+
context "when the form has a live Welsh version" do
486+
let(:form) { create(:form, :live_with_draft, :with_welsh_translation, welsh_completed: true) }
487+
488+
context "and an incomplete welsh translation" do
489+
before do
490+
# Add new content requiring Welsh translation
491+
form.update!(declaration_markdown: "I declare this is correct", share_preview_completed: true)
492+
end
493+
494+
it "make live_status is not_started" do
495+
expect(task_status_service.task_statuses).to include(make_live_status: :not_started)
496+
end
497+
end
498+
end
499+
500+
context "when the form does not have a live Welsh version" do
501+
let(:form) { create(:form, :with_welsh_translation, welsh_completed: true) }
502+
503+
context "and an incomplete welsh translation" do
504+
before do
505+
# Add new content requiring Welsh translation
506+
form.update!(declaration_markdown: "I declare this is correct", share_preview_completed: true)
507+
end
508+
509+
it "make live_status is cannot_start" do
510+
expect(task_status_service.task_statuses).to include(make_live_status: :cannot_start)
511+
end
512+
end
513+
end
472514
end
473515

474516
describe "#incomplete_email_tasks" do

0 commit comments

Comments
 (0)