diff --git a/app/views/admin/historical_accounts/index.html.erb b/app/views/admin/historical_accounts/index.html.erb index e680453abbf..771f0f9a96e 100644 --- a/app/views/admin/historical_accounts/index.html.erb +++ b/app/views/admin/historical_accounts/index.html.erb @@ -55,7 +55,7 @@ text: @historical_account.summary, }, { - text: link_to(sanitize("View #{tag.span(@historical_account.role.name, class: 'govuk-visually-hidden')}"), Whitehall.public_host + @historical_account.public_path, class: "govuk-link") + + text: link_to(sanitize("View #{tag.span(@historical_account.role.name, class: 'govuk-visually-hidden')}"), @historical_account.public_url, class: "govuk-link") + link_to(sanitize("Edit #{tag.span(@historical_account.role.name, class: 'govuk-visually-hidden')}"), edit_admin_person_historical_account_path(@person, @historical_account), class: "govuk-link govuk-!-margin-left-2") + link_to(sanitize("Delete #{tag.span(@historical_account.role.name, class: 'govuk-visually-hidden')}"), confirm_destroy_admin_person_historical_account_path(@person, @historical_account), class: "govuk-link govuk-!-margin-left-2 gem-link--destructive"), }, diff --git a/test/functional/admin/historical_accounts_controller_test.rb b/test/functional/admin/historical_accounts_controller_test.rb index e1006712373..9770f480dd0 100644 --- a/test/functional/admin/historical_accounts_controller_test.rb +++ b/test/functional/admin/historical_accounts_controller_test.rb @@ -8,19 +8,25 @@ class Admin::HistoricalAccountsControllerTest < ActionController::TestCase end test "GET on :index assigns the person, their historical accounts and renders the :index template" do - @historical_account = create(:historical_account, person: @person, role: @role) + historical_account = create(:historical_account, person: @person, role: @role) get :index, params: { person_id: @person } assert_response :success assert_template :index assert_equal @person, assigns(:person) - assert_equal @person.historical_account, assigns(:historical_account) + assert_equal historical_account, assigns(:historical_account) end - view_test "GET on :index should not show Create historical accounts button when historical account is already created" do - @historical_account = create(:historical_account, person: @person, role: @role) + + view_test "GET on :index should display a historical account's details and prevent creation of a second historical account" do + create(:historic_role_appointment, person: @person, role: @role) + historical_account = create(:historical_account, person: @person, role: @role) + get :index, params: { person_id: @person } - assert_select(".govuk-button", text: "Create historical account", count: 0) + assert_select ".govuk-table__cell a:nth-child(1)[href='#{historical_account.public_url}']", text: "View #{@role.name}" + assert_select ".govuk-table__cell a:nth-child(2)[href='#{edit_admin_person_historical_account_path(@person, historical_account)}']", text: "Edit #{@role.name}" + assert_select ".govuk-table__cell a:nth-child(3)[href='#{confirm_destroy_admin_person_historical_account_path(@person, historical_account)}']", text: "Delete #{@role.name}" + assert_select ".govuk-button", text: "Create historical account", count: 0 end view_test "GET on :index should show Create historical accounts button when historical account is not created" do