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: 7 additions & 0 deletions app/controllers/forms/translations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Forms
class TranslationsController < WebController
after_action :verify_authorized

def new; end
end
end
6 changes: 5 additions & 1 deletion app/models/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Form < ApplicationRecord

after_create :set_external_id
after_update :update_draft_form_document
ATTRIBUTES_NOT_IN_FORM_DOCUMENT = %i[state external_id pages question_section_completed declaration_section_completed share_preview_completed].freeze
ATTRIBUTES_NOT_IN_FORM_DOCUMENT = %i[state external_id pages question_section_completed declaration_section_completed share_preview_completed welsh_completed].freeze

def save_draft!
save!
Expand Down Expand Up @@ -184,6 +184,8 @@ def update_draft_form_document
end

def task_status_service
# TODO: refactor this in favour of dependency injection
# it can also lead to use of `allow_any_instance_of` in testing
@task_status_service ||= TaskStatusService.new(form: self)
end

Expand All @@ -196,6 +198,8 @@ def group_form
end

def email_task_status_service
# TODO: refactor this in favour of dependency injection
# it can also lead to use of `allow_any_instance_of` in testing
@email_task_status_service ||= EmailTaskStatusService.new(form: self)
end

Expand Down
51 changes: 38 additions & 13 deletions app/services/form_task_list_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,24 @@ def initialize(form:, current_user:)
end

def all_sections
[
create_form_section,
sections = [
create_form_section(section_number: 1),
payment_link_subsection,
email_address_section,
email_address_section(section_number: 2),
receive_csv_subsection,
privacy_and_contact_details_section,
make_form_live_section,
privacy_and_contact_details_section(section_number: 3),
]

last_sections = [make_form_live_section(section_number: 4)]

if FeatureService.new(group: @form.group).enabled?(:welsh)
last_sections = [
translations_section(section_number: 4),
make_form_live_section(section_number: 5),
]
end
Comment thread
chao-xian marked this conversation as resolved.

sections + last_sections
end

private
Expand All @@ -36,11 +46,11 @@ def create_or_edit
"create"
end

def create_form_section
def create_form_section(section_number:)
{
title: I18n.t("forms.task_list_#{create_or_edit}.create_form_section.title"),
rows: create_form_section_tasks,
section_number: 1,
section_number:,
subsection: false,
}
end
Expand Down Expand Up @@ -74,10 +84,10 @@ def payment_link_subsection_tasks
]
end

def email_address_section
def email_address_section(section_number:)
{
title: I18n.t("forms.task_list_#{create_or_edit}.email_address_section.title"),
section_number: 2,
section_number:,
subsection: false,
rows: email_address_section_tasks,
}
Expand All @@ -104,11 +114,11 @@ def receive_csv_subsection_tasks
]
end

def privacy_and_contact_details_section
def privacy_and_contact_details_section(section_number:)
{
title: I18n.t("forms.task_list_#{create_or_edit}.privacy_and_contact_details_section.title"),
rows: privacy_and_contact_details_section_tasks,
section_number: 3,
section_number:,
subsection: false,
}
end
Expand All @@ -120,10 +130,25 @@ def privacy_and_contact_details_section_tasks
]
end

def make_form_live_section
def translations_section(section_number:)
{
title: I18n.t("forms.task_list_#{create_or_edit}.translations_section.title"),
rows: translations_section_task,
section_number:,
subsection: false,
}
end

def translations_section_task
[
{ task_name: I18n.t("forms.task_list_#{create_or_edit}.translations_section.add_welsh"), path: translations_path(@form.id), status: @task_statuses[:welsh_language_status] },
]
end

def make_form_live_section(section_number:)
section = {
title: live_title_name,
section_number: 4,
section_number:,
subsection: false,
}

Expand Down
15 changes: 14 additions & 1 deletion app/services/task_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def incomplete_tasks
end

def task_statuses
{
statuses = {
name_status:,
pages_status:,
declaration_status:,
Expand All @@ -28,6 +28,12 @@ def task_statuses
share_preview_status:,
make_live_status:,
}

if FeatureService.new(group: @form.group).enabled?(:welsh)
statuses.merge!({ welsh_language_status: })
end

statuses
end

private
Expand Down Expand Up @@ -74,6 +80,13 @@ def support_contact_details_status
:not_started
end

def welsh_language_status
return :completed if @form.welsh_completed?
return :in_progress if @form.available_languages.include?("cy") && !@form.welsh_completed?

:optional
end

def receive_csv_status
return :completed if @form.email_with_csv?

Expand Down
6 changes: 6 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@ en:
receive_csv_subsection:
receive_csv: Get completed forms as CSV files
title: Optional task
translations_section:
add_welsh: Add Welsh language version of your form
title: Add translations to your form (optional)
task_list_edit:
create_form_section:
declaration: Edit the declaration for people to agree to
Expand All @@ -433,6 +436,9 @@ en:
receive_csv_subsection:
receive_csv: Get completed forms as CSV files
title: Optional task
translations_section:
add_welsh: Edit Welsh language version of your form
title: Add translations to your form (optional)
group_forms:
edit:
body_html: "<p> We’ll send an email to members of the current group to let them know the form has moved and they may no longer have access to it. </p>\n"
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
post "/receive-csv" => "forms/receive_csv#create", as: :receive_csv_create
get "/share-preview" => "forms/share_preview#new", as: :share_preview
post "/share-preview" => "forms/share_preview#create", as: :share_preview_create
get "/translations" => "forms/translations#new", as: :translations
post "/translations" => "forms/translations#create", as: :translations_create

scope "/pages" do
get "/" => "pages#index", as: :form_pages
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20251020132955_add_welsh_completed_to_forms.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddWelshCompletedToForms < ActiveRecord::Migration[8.0]
def change
add_column :forms, :welsh_completed, :boolean, default: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions spec/factories/models/forms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@
payment_url { nil }
external_id { nil }

trait :with_group do
transient do
group { nil }
end

after(:build) do |form, evaluator|
g = evaluator.group || FactoryBot.create(:group)
form.instance_variable_set(:@associated_group, g)
form.define_singleton_method(:group) { g }
end

after(:create) do |form, _evaluator|
g = form.instance_variable_get(:@associated_group)
GroupForm.create!(form_id: form.id, group_id: g.id) unless GroupForm.exists?(form_id: form.id, group_id: g.id)
end
end

Comment thread
chao-xian marked this conversation as resolved.
trait :new_form do
submission_email { "" }
privacy_policy_url { "" }
Expand Down
5 changes: 5 additions & 0 deletions spec/factories/models/groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
organisation { association :organisation, id: 1, slug: "test-org" }
creator { association :user, organisation: }
status { :trial }
welsh_enabled { false }

trait :org_has_org_admin do
organisation { association :organisation, :with_org_admin, id: 1, slug: "test-org" }
end

trait :with_welsh_enabled do
welsh_enabled { true }
end
end
end
2 changes: 1 addition & 1 deletion spec/models/form_document/content_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
end

it "has all form attributes the original form has" do
expected_attributes = form.attributes.except(*%w[id state external_id pages question_section_completed declaration_section_completed share_preview_completed])
expected_attributes = form.attributes.except(*%w[id state external_id pages question_section_completed declaration_section_completed share_preview_completed welsh_completed])
Comment thread
chao-xian marked this conversation as resolved.
expect(form_document_content).to have_attributes(expected_attributes)
end

Expand Down
8 changes: 5 additions & 3 deletions spec/models/form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
end

it "has a ready for live trait" do
form = build :form, :ready_for_live
form = build :form, :ready_for_live, :with_group
expect(form.ready_for_live).to be true
expect(form.incomplete_tasks).to be_empty
expect(form.task_statuses).to include(
Expand Down Expand Up @@ -619,7 +619,8 @@
end

describe "#all_task_statuses" do
let(:completed_form) { build :form, :live }
let(:group) { create :group, :with_welsh_enabled }
let(:completed_form) { build :form, :live, :with_group, group: }

it "returns a hash with each of the task statuses" do
expected_hash = {
Expand All @@ -633,6 +634,7 @@
payment_link_status: :optional,
receive_csv_status: :optional,
support_contact_details_status: :completed,
welsh_language_status: :optional,
Comment thread
chao-xian marked this conversation as resolved.
share_preview_status: :completed,
make_live_status: :completed,
}
Expand Down Expand Up @@ -841,7 +843,7 @@
let(:form) { create :form, :ready_for_live }

it "includes all attributes for the form" do
form_attributes = described_class.attribute_names - %w[id state external_id pages question_section_completed declaration_section_completed share_preview_completed]
form_attributes = described_class.attribute_names - %w[id state external_id pages question_section_completed declaration_section_completed share_preview_completed welsh_completed]
expect(form.as_form_document).to match a_hash_including(*form_attributes)
end

Expand Down
31 changes: 28 additions & 3 deletions spec/services/form_task_list_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,34 @@
expect(all_sections).to be_an_instance_of(Array)
end

it "returns 5 sections" do
expected_sections = [{ title: "Task 1" }, { title: "Task 2" }, { title: "Task 3" }, { title: "Task 4" }, { title: "Task 5" }, { title: "Task 6" }]
expect(all_sections.count).to eq expected_sections.count
context "when welsh is not enabled" do
it "returns 6 sections" do
expect(all_sections.count).to eq 6
end

it "does not include translations section" do
section_titles = all_sections.map { |section| section[:title] }
expect(section_titles).not_to include(I18n.t("forms.task_list_create.translations_section.title"))
end
end

context "when welsh is enabled" do
let(:group) { create(:group, :with_welsh_enabled, name: "Group 1", organisation:, status: group_status) }

it "returns 7 sections" do
expect(all_sections.count).to eq 7
end

it "includes translations section" do
section_titles = all_sections.map { |section| section[:title] }
expect(section_titles).to include(I18n.t("forms.task_list_create.translations_section.title"))
end

it "has translations section before make form live section" do
translations_section_index = all_sections.index { |section| section[:title] == I18n.t("forms.task_list_create.translations_section.title") }
make_live_section_index = all_sections.index { |section| section[:title] == I18n.t("forms.task_list_create.make_form_live_section.title") }
expect(translations_section_index).to be < make_live_section_index
end
end

describe "create form section tasks" do
Expand Down
Loading
Loading