Skip to content

Commit 70c263e

Browse files
committed
Update list of forms to include indication of Welsh versions
form list now includes text underneath the form name to indicate if the form has a welsh version, and if that version is live archived or draft
1 parent 3a3938d commit 70c263e

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

app/models/form.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Form < ApplicationRecord
1414
has_one :live_welsh_form_document, -> { where tag: "live", language: :cy }, class_name: "FormDocument"
1515
has_one :archived_form_document, -> { where tag: "archived", language: :en }, class_name: "FormDocument"
1616
has_one :archived_welsh_form_document, -> { where tag: "archived", language: :cy }, class_name: "FormDocument"
17+
has_one :draft_welsh_form_document, -> { where tag: "draft", language: :cy }, class_name: "FormDocument"
1718
has_one :draft_form_document, -> { where tag: "draft", language: :en }, class_name: "FormDocument"
1819
has_many :conditions, through: :pages, source: :routing_conditions
1920

app/presenters/form_list_presenter.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def head
5050

5151
def rows
5252
rows = forms.sort_by { |form| [form.name.downcase, form.created_at] }.map do |form|
53-
row = [{ text: form_name_link(form) },
53+
row = [{ text: form_name_link(form) + welsh_status(form) },
5454
{ text: find_creator_name(form) },
5555
{ text: form_status_tags(form), numeric: true }]
5656

@@ -74,6 +74,16 @@ def change_group_link(form)
7474
)
7575
end
7676

77+
def welsh_status(form)
78+
if form.live_welsh_form_document.present?
79+
"<p class=\"govuk-!-margin-bottom-1 govuk-!-margin-top-2 govuk-hint\">With Welsh Version</p>".html_safe
80+
elsif form.draft_welsh_form_document.present?
81+
"<p class=\"govuk-!-margin-bottom-1 govuk-!-margin-top-2 govuk-hint\">With Welsh draft</p>".html_safe
82+
elsif form.archived_welsh_form_document.present?
83+
"<p class=\"govuk-!-margin-bottom-1 govuk-!-margin-top-2 govuk-hint\">With archived Welsh version</p>".html_safe
84+
end
85+
end
86+
7787
def form_status_tags(form)
7888
# Create an instance of controller. We are using ApplicationController here.
7989
view_context = ApplicationController.new.view_context

spec/models/form_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,36 @@
444444
end
445445
end
446446

447+
describe "draft_welsh_form_document" do
448+
context "when there is no draft Welsh form document" do
449+
subject(:form) { create :form }
450+
451+
it "returns nil" do
452+
expect(form.draft_welsh_form_document).to be_nil
453+
end
454+
end
455+
456+
context "when there is a draft Welsh form document" do
457+
subject(:form) { create :form, :draft, :with_welsh_translation }
458+
459+
it "returns nil" do
460+
expect(form.draft_welsh_form_document).to be_a(FormDocument)
461+
end
462+
end
463+
464+
context "when there is only a live Welsh form document" do
465+
subject(:form) { create :form, :live, :with_welsh_translation }
466+
467+
before do
468+
FormDocument.find_by(form:, tag: "draft").destroy
469+
end
470+
471+
it "returns nil" do
472+
expect(form.draft_welsh_form_document).to be_nil
473+
end
474+
end
475+
end
476+
447477
describe "draft_form_document" do
448478
context "when there is no archived form document" do
449479
it "returns nil" do

spec/presenters/form_list_presenter_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,32 @@
114114
expect(rows[3][0][:text]).to eq("<a class=\"govuk-link\" href=\"/forms/2\">b</a>")
115115
end
116116
end
117+
118+
context "when a welsh version of the form exists" do
119+
let(:forms) do
120+
[
121+
create(:form, :live, :with_welsh_translation, id: 1, name: "form with a live Welsh Version"),
122+
create(:form, :archived, :with_welsh_translation, id: 2, name: "form with an archived and a draft Welsh version"),
123+
create(:form, :draft, :with_welsh_translation, id: 3, name: "form with Welsh draft"),
124+
create(:form, id: 4, name: "form with no Welsh version"),
125+
create(:form, :archived, :with_welsh_translation, id: 5, name: "form with only an archived Welsh version"),
126+
]
127+
end
128+
129+
before do
130+
# remove the draft version of the welsh translation for the form with only archived version.
131+
FormDocument.find_by(form: forms[4], tag: "draft", language: "cy").destroy!
132+
end
133+
134+
it "appends the correct text" do
135+
rows = presenter.data[:rows]
136+
expect(rows[0][0][:text]).to eq("<a class=\"govuk-link\" href=\"/forms/1/live\">form with a live Welsh Version</a><p class=\"govuk-!-margin-bottom-1 govuk-!-margin-top-2 govuk-hint\">With Welsh Version</p>")
137+
expect(rows[1][0][:text]).to eq("<a class=\"govuk-link\" href=\"/forms/2/archived\">form with an archived and a draft Welsh version</a><p class=\"govuk-!-margin-bottom-1 govuk-!-margin-top-2 govuk-hint\">With Welsh draft</p>")
138+
expect(rows[2][0][:text]).to eq("<a class=\"govuk-link\" href=\"/forms/4\">form with no Welsh version</a>")
139+
expect(rows[3][0][:text]).to eq("<a class=\"govuk-link\" href=\"/forms/5/archived\">form with only an archived Welsh version</a><p class=\"govuk-!-margin-bottom-1 govuk-!-margin-top-2 govuk-hint\">With archived Welsh version</p>")
140+
expect(rows[4][0][:text]).to eq("<a class=\"govuk-link\" href=\"/forms/3\">form with Welsh draft</a><p class=\"govuk-!-margin-bottom-1 govuk-!-margin-top-2 govuk-hint\">With Welsh draft</p>")
141+
end
142+
end
117143
end
118144
end
119145
end

0 commit comments

Comments
 (0)