Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/models/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,11 @@ def changed_from_live_version?(language:)
live_document = latest_live_or_archived_form_document(language:)
return false if live_document.blank?

ignored_keys = %w[live_at available_languages updated_at tag created_at version]
return false if live_document.content.except(*ignored_keys) == as_form_document(language:).except(*ignored_keys)
draft_document = form_documents.find_by(tag: "draft", language:)
return false if draft_document.blank?

true
ignored_keys = %w[live_at available_languages updated_at tag created_at version]
live_document.content.except(*ignored_keys) != draft_document.content.except(*ignored_keys)
end

def only_s3_delivery_enabled?
Expand Down
13 changes: 6 additions & 7 deletions app/services/form_task_list_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ def group_upgrade_url
def make_form_live_section_tasks
[
share_preview_task,
(make_live_task unless display_make_languages_live_tasks?),
(make_only_english_live_task if display_make_languages_live_tasks?),
(make_only_welsh_live_task if display_make_languages_live_tasks?),
(make_live_task if @task_statuses.key?(:make_live_status)),
(make_only_english_live_task if @task_statuses.key?(:make_only_english_live_status)),
(make_only_welsh_live_task if @task_statuses.key?(:make_only_welsh_live_status)),
].compact
end

Expand Down Expand Up @@ -250,10 +250,6 @@ def make_only_welsh_live_task
}
end

def display_make_languages_live_tasks?
!@form.has_live_welsh_translation? && @form.has_welsh_translation?
end

def live_title_name
return I18n.t("forms.task_list_create.make_form_live_section.title") if @form.is_archived?

Expand All @@ -276,6 +272,8 @@ def statuses_by_user
unless Pundit.policy(@current_user, @form).can_make_form_live?
statuses.delete(:share_preview_status)
statuses.delete(:make_live_status)
statuses.delete(:make_only_english_live_status)
statuses.delete(:make_only_welsh_live_status)
end

statuses
Expand All @@ -295,6 +293,7 @@ def remove_optional_statuses(statuses)
statuses.delete(:copy_of_answers_status)
statuses.delete(:submission_attachments_status)
statuses.delete(:batch_submissions_status)
statuses.delete(:welsh_language_status)
end

def can_enter_submission_email_code
Expand Down
18 changes: 14 additions & 4 deletions app/services/task_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def all_incomplete_tasks(ignore_missing_welsh: false)
end

def all_task_statuses
{
statuses = {
name_status:,
pages_status:,
declaration_status:,
Expand All @@ -35,13 +35,19 @@ def all_task_statuses
submission_attachments_status:,
batch_submissions_status:,
share_preview_status:,
make_live_status:,
make_only_english_live_status:,
make_only_welsh_live_status:,
welsh_language_status:,
submission_email_status:,
confirm_submission_email_status:,
}

if display_make_languages_live_tasks?
statuses[:make_only_english_live_status] = make_only_english_live_status
statuses[:make_only_welsh_live_status] = make_only_welsh_live_status
else
statuses[:make_live_status] = make_live_status
end

statuses
end

def incomplete_email_tasks
Expand All @@ -59,6 +65,10 @@ def email_task_statuses

private

def display_make_languages_live_tasks?
!@form.has_live_welsh_translation? && @form.has_welsh_translation?
end

def name_status
:completed
end
Expand Down
2 changes: 0 additions & 2 deletions spec/models/form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -960,8 +960,6 @@
welsh_language_status: :optional,
share_preview_status: :completed,
make_live_status: :completed,
make_only_english_live_status: :completed,
make_only_welsh_live_status: :cannot_start,
}
expect(form.all_task_statuses).to eq expected_hash
end
Expand Down
44 changes: 44 additions & 0 deletions spec/services/form_task_list_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
share_preview_status: :completed,
submission_email_status: :completed,
confirm_submission_email_status: :not_started,
welsh_language_status: :in_progress,
}
end
let(:form) { create(:form) }
Expand Down Expand Up @@ -76,6 +77,49 @@
expect(result.task_counts).to eq expected_hash
end
end

context "when the language live statuses are included instead of the make live status" do
let(:statuses) do
{
declaration_status: :completed,
make_only_english_live_status: :not_started,
make_only_welsh_live_status: :completed,
name_status: :completed,
pages_status: :completed,
privacy_policy_status: :not_started,
support_contact_details_status: :not_started,
what_happens_next_status: :completed,
payment_link_status: :optional,
copy_of_answers_status: :optional,
submission_attachments_status: :optional,
batch_submissions_status: :optional,
share_preview_status: :completed,
submission_email_status: :completed,
confirm_submission_email_status: :not_started,
welsh_language_status: :in_progress,
}
end

context "when the user can make the form live" do
let(:can_make_form_live) { true }

it "counts the language live statuses" do
result = described_class.new(form:, current_user:)

expect(result.task_counts).to eq({ completed: 7, total: 11 })
end
end

context "when the user cannot make the form live" do
let(:can_make_form_live) { false }

it "does not count the language live statuses" do
result = described_class.new(form:, current_user:)

expect(result.task_counts).to eq({ completed: 5, total: 8 })
end
end
end
end

describe "#all_sections" do
Expand Down
54 changes: 37 additions & 17 deletions spec/services/task_status_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@
let(:form) { build(:form, :with_group, group:) }

before do
allow(form).to receive(:has_welsh_translation?).and_return(true)
allow(form).to receive(:can_make_language_live?).with(language: "en").and_return(can_make_english_live)
allow(form).to receive(:changed_from_live_version?).with(language: "en").and_return(changed_from_live_version)
allow(form).to receive(:can_make_language_live?).with(language: "cy").and_return(can_make_welsh_live)
Expand Down Expand Up @@ -514,6 +515,7 @@
let(:form) { build(:form, :with_group, group:) }

before do
allow(form).to receive(:has_welsh_translation?).and_return(true)
allow(form).to receive(:can_make_language_live?).with(language: "en").and_return(can_make_english_live)
allow(form).to receive(:can_make_language_live?).with(language: "cy").and_return(can_make_welsh_live)
end
Expand Down Expand Up @@ -543,8 +545,8 @@
end

context "when the form already has a live Welsh version" do
it "returns completed" do
expect(task_status_service.all_task_statuses[:make_only_welsh_live_status]).to eq :completed
it "does not include the language live statuses" do
expect(task_status_service.all_task_statuses).not_to include(:make_only_english_live_status, :make_only_welsh_live_status)
end
end

Expand Down Expand Up @@ -704,38 +706,56 @@
share_preview_status: :completed,
submission_email_status: :completed,
confirm_submission_email_status: :completed,
make_only_english_live_status: :completed,
make_only_welsh_live_status: :cannot_start,
}
expect(task_status_service.all_task_statuses).to eq expected_hash
end

context "when the form has a live Welsh version" do
let(:form) { create(:form, :live_with_draft, :with_welsh_translation, welsh_completed: true) }
context "when the form has no Welsh translation" do
it "includes the make live status and not the language live statuses" do
statuses = task_status_service.all_task_statuses

context "and an incomplete welsh translation" do
before do
# Add new content requiring Welsh translation
form.update!(declaration_markdown: "I declare this is correct", share_preview_completed: true)
end
expect(statuses).to include(:make_live_status)
expect(statuses).not_to include(:make_only_english_live_status, :make_only_welsh_live_status)
end

it "make live_status is not_started" do
expect(task_status_service.all_task_statuses).to include(make_live_status: :not_started)
end
it "does not calculate the language live statuses" do
allow(form).to receive(:can_make_language_live?).and_call_original

task_status_service.all_task_statuses

expect(form).not_to have_received(:can_make_language_live?)
end
end

context "when the form does not have a live Welsh version" do
context "when the form has a Welsh translation but no live Welsh version" do
let(:form) { create(:form, :with_welsh_translation, welsh_completed: true) }

it "includes the language live statuses and not the make live status" do
statuses = task_status_service.all_task_statuses

expect(statuses).to include(:make_only_english_live_status, :make_only_welsh_live_status)
expect(statuses).not_to include(:make_live_status)
end
end

context "when the form has a live Welsh version" do
let(:form) { create(:form, :live_with_draft, :with_welsh_translation, welsh_completed: true) }

it "includes the make live status and not the language live statuses" do
statuses = task_status_service.all_task_statuses

expect(statuses).to include(:make_live_status)
expect(statuses).not_to include(:make_only_english_live_status, :make_only_welsh_live_status)
end

context "and an incomplete welsh translation" do
before do
# Add new content requiring Welsh translation
form.update!(declaration_markdown: "I declare this is correct", share_preview_completed: true)
end

it "make live_status is cannot_start" do
expect(task_status_service.all_task_statuses).to include(make_live_status: :cannot_start)
it "make live_status is not_started" do
expect(task_status_service.all_task_statuses).to include(make_live_status: :not_started)
end
end
end
Expand Down
Loading