Skip to content

Commit

Permalink
Refactor application_form_summary_rows
Browse files Browse the repository at this point in the history
This removes an argument which was always set to true, and simplifies
the actions.
  • Loading branch information
thomasleese committed Sep 5, 2023
1 parent 96e1af8 commit 4f398dd
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 121 deletions.
1 change: 0 additions & 1 deletion app/components/application_form_overview/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def summary_rows
application_form_summary_rows(
application_form,
include_name: true,
include_reference: true,
highlight_email:,
) +
[
Expand Down
2 changes: 1 addition & 1 deletion app/components/application_form_search_result/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def summary_rows
application_form_summary_rows(
application_form,
include_name: false,
include_reference: true,
include_reviewer: application_form.reviewer.present?,
class_context: "app-search-result__item",
)
end

Expand Down
172 changes: 102 additions & 70 deletions app/helpers/application_form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,97 +13,129 @@ def application_form_full_name(application_form)
def application_form_summary_rows(
application_form,
include_name:,
include_reference:,
include_reviewer: true,
highlight_email: false
highlight_email: false,
class_context: nil
)
[
(
if include_name
[
I18n.t("application_form.summary.name"),
application_form_full_name(application_form),
]
{
key: {
text: I18n.t("application_form.summary.name"),
},
value: {
text: application_form_full_name(application_form),
},
}
end
),
[
I18n.t("application_form.summary.country"),
CountryName.from_country(application_form.region.country),
],
[
I18n.t("application_form.summary.email"),
(
if highlight_email
"<em class=\"app-highlight\">#{ERB::Util.html_escape(application_form.teacher.email)}</em>".html_safe
else
application_form.teacher.email
end
),
],
{
key: {
text: I18n.t("application_form.summary.country"),
},
value: {
text: CountryName.from_country(application_form.region.country),
},
},
(
if application_form.region.name.present?
[
I18n.t("application_form.summary.region"),
application_form.region.name,
]
{
key: {
text: I18n.t("application_form.summary.region"),
},
value: {
text: application_form.region.name,
},
}
end
),
[
I18n.t("application_form.summary.submitted_at"),
application_form.submitted_at.strftime("%e %B %Y"),
],
[
I18n.t("application_form.summary.days_since_submission"),
pluralize(application_form.working_days_since_submission, "day"),
],
[
I18n.t("application_form.summary.assessor"),
application_form.assessor&.name ||
I18n.t("application_form.summary.unassigned"),
[
{
key: {
text: I18n.t("application_form.summary.email"),
},
value: {
text:
(
if highlight_email
"<em class=\"app-highlight\">#{ERB::Util.html_escape(application_form.teacher.email)}</em>".html_safe
else
application_form.teacher.email
end
),
},
},
{
key: {
text: I18n.t("application_form.summary.submitted_at"),
},
value: {
text: application_form.submitted_at.strftime("%e %B %Y"),
},
},
{
key: {
text: I18n.t("application_form.summary.days_since_submission"),
},
value: {
text:
pluralize(application_form.working_days_since_submission, "day"),
},
},
{
key: {
text: I18n.t("application_form.summary.assessor"),
},
value: {
text:
application_form.assessor&.name ||
I18n.t("application_form.summary.unassigned"),
},
actions: [
{
href:
assessor_interface_application_form_assign_assessor_path(
application_form,
),
visually_hidden_text: I18n.t("application_form.summary.assessor"),
href: [:assessor_interface, application_form, :assign_assessor],
},
],
],
},
(
if include_reviewer
[
I18n.t("application_form.summary.reviewer"),
application_form.reviewer&.name ||
I18n.t("application_form.summary.unassigned"),
[
{
key: {
text: I18n.t("application_form.summary.reviewer"),
},
value: {
text:
application_form.reviewer&.name ||
I18n.t("application_form.summary.unassigned"),
},
actions: [
{
href:
assessor_interface_application_form_assign_reviewer_path(
application_form,
),
visually_hidden_text:
I18n.t("application_form.summary.reviewer"),
href: [:assessor_interface, application_form, :assign_reviewer],
},
],
]
end
),
(
if include_reference
[
I18n.t("application_form.summary.reference"),
application_form.reference,
]
}
end
),
[
I18n.t("application_form.summary.status"),
application_form_status_tags(
application_form,
class_context: "app-search-result__item",
),
],
].compact.map do |key, value, actions|
{ key: { text: key }, value: { text: value }, actions: actions || [] }
end
{
key: {
text: I18n.t("application_form.summary.reference"),
},
value: {
text: application_form.reference,
},
},
{
key: {
text: I18n.t("application_form.summary.status"),
},
value: {
text: application_form_status_tags(application_form, class_context:),
},
},
].compact
end

def application_form_display_work_history_before_teaching_qualification_banner?(
Expand Down
60 changes: 11 additions & 49 deletions spec/helpers/application_form_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,20 @@

describe "#application_form_summary_rows" do
subject(:summary_rows) do
application_form_summary_rows(
application_form,
include_name: true,
include_reference: true,
)
application_form_summary_rows(application_form, include_name: true)
end

it do
is_expected.to eq(
[
{
key: {
text: "Name",
},
value: {
text: "Given Family",
},
actions: [],
},
{ key: { text: "Name" }, value: { text: "Given Family" } },
{
key: {
text: "Country trained in",
},
value: {
text: "United States",
},
actions: [],
},
{
key: {
text: "Email",
},
value: {
text: application_form.teacher.email,
},
actions: [],
},
{
key: {
Expand All @@ -77,25 +55,23 @@
value: {
text: "Region",
},
actions: [],
},
{
key: {
text: "Created on",
text: "Email",
},
value: {
text: " 1 January 2020",
text: application_form.teacher.email,
},
actions: [],
},
{ key: { text: "Created on" }, value: { text: " 1 January 2020" } },
{
key: {
text: "Working days since submission",
},
value: {
text: "0 days",
},
actions: [],
},
{
key: {
Expand All @@ -106,10 +82,8 @@
},
actions: [
{
href:
assessor_interface_application_form_assign_assessor_path(
application_form,
),
visually_hidden_text: "Assigned to",
href: [:assessor_interface, application_form, :assign_assessor],
},
],
},
Expand All @@ -122,31 +96,20 @@
},
actions: [
{
href:
assessor_interface_application_form_assign_reviewer_path(
application_form,
),
visually_hidden_text: "Reviewer",
href: [:assessor_interface, application_form, :assign_reviewer],
},
],
},
{
key: {
text: "Reference",
},
value: {
text: "0000001",
},
actions: [],
},
{ key: { text: "Reference" }, value: { text: "0000001" } },
{
key: {
text: "Status",
},
value: {
text:
"<strong class=\"govuk-tag govuk-tag--grey app-search-result__item__tag\">Not started</strong>\n",
"<strong class=\"govuk-tag govuk-tag--grey\">Not started</strong>\n",
},
actions: [],
},
],
)
Expand All @@ -157,7 +120,6 @@
application_form_summary_rows(
application_form,
include_name: true,
include_reference: true,
include_reviewer: false,
)
end
Expand Down

0 comments on commit 4f398dd

Please sign in to comment.