Skip to content
Open
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
1 change: 1 addition & 0 deletions app/models/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Form < ApplicationRecord
has_one :live_welsh_form_document, -> { where tag: "live", language: :cy }, class_name: "FormDocument"
has_one :archived_form_document, -> { where tag: "archived", language: :en }, class_name: "FormDocument"
has_one :archived_welsh_form_document, -> { where tag: "archived", language: :cy }, class_name: "FormDocument"
has_one :draft_welsh_form_document, -> { where tag: "draft", language: :cy }, class_name: "FormDocument"
has_one :draft_form_document, -> { where tag: "draft", language: :en }, class_name: "FormDocument"
has_many :conditions, through: :pages, source: :routing_conditions

Expand Down
12 changes: 11 additions & 1 deletion app/presenters/form_list_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def head

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

Expand All @@ -74,6 +74,16 @@ def change_group_link(form)
)
end

def welsh_status(form)
if form.live_welsh_form_document.present?
"<p class=\"govuk-!-margin-bottom-1 govuk-!-margin-top-2 govuk-hint\">With Welsh Version</p>".html_safe
elsif form.draft_welsh_form_document.present?
"<p class=\"govuk-!-margin-bottom-1 govuk-!-margin-top-2 govuk-hint\">With Welsh draft</p>".html_safe
elsif form.archived_welsh_form_document.present?
"<p class=\"govuk-!-margin-bottom-1 govuk-!-margin-top-2 govuk-hint\">With archived Welsh version</p>".html_safe
end
end

def form_status_tags(form)
# Create an instance of controller. We are using ApplicationController here.
view_context = ApplicationController.new.view_context
Expand Down
30 changes: 30 additions & 0 deletions spec/models/form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,36 @@
end
end

describe "draft_welsh_form_document" do
context "when there is no draft Welsh form document" do
subject(:form) { create :form }

it "returns nil" do
expect(form.draft_welsh_form_document).to be_nil
end
end

context "when there is a draft Welsh form document" do
subject(:form) { create :form, :draft, :with_welsh_translation }

it "returns nil" do
expect(form.draft_welsh_form_document).to be_a(FormDocument)
end
end

context "when there is only a live Welsh form document" do
subject(:form) { create :form, :live, :with_welsh_translation }

before do
FormDocument.find_by(form:, tag: "draft").destroy
end

it "returns nil" do
expect(form.draft_welsh_form_document).to be_nil
end
end
end

describe "draft_form_document" do
context "when there is no archived form document" do
it "returns nil" do
Expand Down
26 changes: 26 additions & 0 deletions spec/presenters/form_list_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,32 @@
expect(rows[3][0][:text]).to eq("<a class=\"govuk-link\" href=\"/forms/2\">b</a>")
end
end

context "when a welsh version of the form exists" do
let(:forms) do
[
create(:form, :live, :with_welsh_translation, id: 1, name: "form with a live Welsh Version"),
create(:form, :archived, :with_welsh_translation, id: 2, name: "form with an archived and a draft Welsh version"),
create(:form, :draft, :with_welsh_translation, id: 3, name: "form with Welsh draft"),
create(:form, id: 4, name: "form with no Welsh version"),
create(:form, :archived, :with_welsh_translation, id: 5, name: "form with only an archived Welsh version"),
]
end

before do
# remove the draft version of the welsh translation for the form with only archived version.
FormDocument.find_by(form: forms[4], tag: "draft", language: "cy").destroy!
end

it "appends the correct text" do
rows = presenter.data[:rows]
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>")
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>")
expect(rows[2][0][:text]).to eq("<a class=\"govuk-link\" href=\"/forms/4\">form with no Welsh version</a>")
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>")
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>")
end
end
end
end
end
Loading