Skip to content

Commit

Permalink
Add link to change name
Browse files Browse the repository at this point in the history
This adds a link to the summary list rows if the staff user has the
right permission, allowing them to change the given names and family
name of the applicant.
  • Loading branch information
thomasleese committed Sep 5, 2023
1 parent 4f398dd commit 08a2f80
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 16 deletions.
10 changes: 5 additions & 5 deletions app/components/application_form_overview/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

module ApplicationFormOverview
class Component < ViewComponent::Base
def initialize(application_form, highlight_email: false)
def initialize(application_form, current_staff:, highlight_email: false)
super
@application_form = application_form
@current_staff = current_staff
@highlight_email = highlight_email
end

Expand All @@ -15,6 +16,7 @@ def title
def summary_rows
application_form_summary_rows(
application_form,
current_staff:,
include_name: true,
highlight_email:,
) +
Expand All @@ -27,9 +29,7 @@ def summary_rows
text:
govuk_link_to(
I18n.t("application_form.overview.view_timeline"),
assessor_interface_application_form_timeline_events_path(
application_form,
),
[:assessor_interface, application_form, :timeline_events],
),
},
},
Expand All @@ -38,7 +38,7 @@ def summary_rows

private

attr_reader :application_form, :highlight_email
attr_reader :application_form, :current_staff, :highlight_email

delegate :application_form_summary_rows, to: :helpers
end
Expand Down
8 changes: 6 additions & 2 deletions app/components/application_form_search_result/component.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# frozen_string_literal: true

module ApplicationFormSearchResult
class Component < ViewComponent::Base
def initialize(application_form:)
def initialize(application_form, current_staff:)
super
@application_form = application_form
@current_staff = current_staff
end

def full_name
Expand All @@ -16,6 +19,7 @@ def href
def summary_rows
application_form_summary_rows(
application_form,
current_staff:,
include_name: false,
include_reviewer: application_form.reviewer.present?,
class_context: "app-search-result__item",
Expand All @@ -24,7 +28,7 @@ def summary_rows

private

attr_reader :application_form
attr_reader :application_form, :current_staff

delegate :application_form_full_name, to: :helpers
delegate :application_form_summary_rows, to: :helpers
Expand Down
12 changes: 12 additions & 0 deletions app/helpers/application_form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def application_form_full_name(application_form)

def application_form_summary_rows(
application_form,
current_staff:,
include_name:,
include_reviewer: true,
highlight_email: false,
Expand All @@ -27,6 +28,17 @@ def application_form_summary_rows(
value: {
text: application_form_full_name(application_form),
},
actions: [
if AssessorInterface::ApplicationFormPolicy.new(
current_staff,
application_form,
).edit?
{
visually_hidden_text: I18n.t("application_form.summary.name"),
href: [:edit, :assessor_interface, application_form],
}
end,
].compact,
}
end
),
Expand Down
8 changes: 4 additions & 4 deletions app/views/assessor_interface/application_forms/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@
</div>

<div class="govuk-grid-column-two-thirds">
<% if @view_object.application_forms_records.any? %>
<% if (records = @view_object.application_forms_records).present? %>
<ul class="app-search-results">
<%- @view_object.application_forms_records.each do |application_form| -%>
<%= render(ApplicationFormSearchResult::Component.new(application_form:)) %>
<%- end -%>
<% records.each do |application_form| %>
<%= render(ApplicationFormSearchResult::Component.new(application_form, current_staff:)) %>
<% end %>
</ul>

<%= govuk_pagination(pagy: @view_object.application_forms_pagy) %>
Expand Down
4 changes: 3 additions & 1 deletion app/views/assessor_interface/application_forms/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

<%= render "shared/assessor_header", title: "Application", application_form: %>

<%= render(ApplicationFormOverview::Component.new(application_form, highlight_email: @view_object.highlight_email?)) %>
<%= render(ApplicationFormOverview::Component.new(
application_form, current_staff:, highlight_email: @view_object.highlight_email?
)) %>

<h2 class="govuk-heading-l govuk-!-margin-top-9">Assessment</h2>

Expand Down
5 changes: 4 additions & 1 deletion spec/components/application_form_overview_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
require "rails_helper"

RSpec.describe ApplicationFormOverview::Component, type: :component do
subject(:component) { render_inline(described_class.new(application_form)) }
subject(:component) do
render_inline(described_class.new(application_form, current_staff:))
end

let(:application_form) { create(:application_form, :submitted) }
let(:current_staff) { create(:staff) }

describe "heading" do
subject(:text) { component.at_css("h2").text.strip }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
require "rails_helper"

RSpec.describe ApplicationFormSearchResult::Component, type: :component do
subject(:component) { render_inline(described_class.new(application_form:)) }
subject(:component) do
render_inline(described_class.new(application_form, current_staff:))
end

let(:application_form) do
create(
Expand All @@ -14,6 +16,7 @@
family_name: "Family",
)
end
let(:current_staff) { create(:staff) }

describe "heading text" do
subject(:text) { component.at_css("h2").text.strip }
Expand Down
44 changes: 42 additions & 2 deletions spec/helpers/application_form_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,27 @@

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

let(:current_staff) { create(:staff) }

it do
is_expected.to eq(
[
{ key: { text: "Name" }, value: { text: "Given Family" } },
{
key: {
text: "Name",
},
value: {
text: "Given Family",
},
actions: [],
},
{
key: {
text: "Country trained in",
Expand Down Expand Up @@ -115,10 +129,36 @@
)
end

context "user has change name permission" do
let(:current_staff) { create(:staff, :with_change_name_permission) }

it "has an action to change the name" do
name_row = summary_rows.find { |row| row[:key][:text] == "Name" }

expect(name_row).to eq(
{
key: {
text: "Name",
},
value: {
text: "Given Family",
},
actions: [
{
visually_hidden_text: "Name",
href: [:edit, :assessor_interface, application_form],
},
],
},
)
end
end

context "include_reviewer false" do
subject(:summary_rows_without_reviewer) do
application_form_summary_rows(
application_form,
current_staff:,
include_name: true,
include_reviewer: false,
)
Expand Down

0 comments on commit 08a2f80

Please sign in to comment.