From 31942a7029529f5fa3a0377e248438b0f6e37b8a Mon Sep 17 00:00:00 2001 From: Kat Date: Tue, 8 Nov 2022 12:28:59 +0000 Subject: [PATCH] Add show location page --- app/controllers/locations_controller.rb | 2 ++ app/models/location.rb | 10 +++++--- app/views/locations/edit_name.html.erb | 2 +- app/views/locations/index.html.erb | 2 +- app/views/locations/show.html.erb | 24 ++++++++++++++++++ spec/features/schemes_spec.rb | 33 ++++++++++++++++++++++--- spec/models/location_spec.rb | 18 ++++++++++++++ 7 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 app/views/locations/show.html.erb diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index 0a857bb13..c8de927d6 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -18,6 +18,8 @@ class LocationsController < ApplicationController @location = Location.new end + def show; end + def create if date_params_missing?(location_params) || valid_date_params?(location_params) @location = Location.new(location_params) diff --git a/app/models/location.rb b/app/models/location.rb index 40a115d43..da959069b 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -361,9 +361,13 @@ class Location < ApplicationRecord def display_attributes [ - { name: "Location code ", value: location_code, suffix: false }, - { name: "Postcode", value: postcode, suffix: county }, - { name: "Type of unit", value: type_of_unit, suffix: false }, + { name: "Postcode", value: postcode }, + { name: "Local authority", value: location_admin_district }, + { name: "Location name", value: name, edit: true }, + { name: "Total number of units at this location", value: units }, + { name: "Common type of unit", value: type_of_unit }, + { name: "Mobility type", value: mobility_type }, + { name: "Code", value: location_code }, ] end diff --git a/app/views/locations/edit_name.html.erb b/app/views/locations/edit_name.html.erb index ece4df866..66e1cb193 100644 --- a/app/views/locations/edit_name.html.erb +++ b/app/views/locations/edit_name.html.erb @@ -3,7 +3,7 @@ <% content_for :before_content do %> <%= govuk_back_link( text: "Back", - href: "/schemes/#{@scheme.id}/locations", + href: "/schemes/#{@scheme.id}/locations/#{@location.id}", ) %> <% end %> diff --git a/app/views/locations/index.html.erb b/app/views/locations/index.html.erb index 703fd9fa5..5b2cbae47 100644 --- a/app/views/locations/index.html.erb +++ b/app/views/locations/index.html.erb @@ -52,7 +52,7 @@ <%= table.body do |body| %> <%= body.row do |row| %> <% row.cell(text: location.id) %> - <% row.cell(text: simple_format(location_cell_postcode(location, "/schemes/#{@scheme.id}/locations/#{location.id}/edit-name"), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %> + <% row.cell(text: simple_format(location_cell_postcode(location, "/schemes/#{@scheme.id}/locations/#{location.id}"), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %> <% row.cell(text: location.units) %> <% row.cell(text: simple_format("#{location.type_of_unit}")) %> <% row.cell(text: location.mobility_type) %> diff --git a/app/views/locations/show.html.erb b/app/views/locations/show.html.erb new file mode 100644 index 000000000..96d8fd25d --- /dev/null +++ b/app/views/locations/show.html.erb @@ -0,0 +1,24 @@ +<% title = @location.name %> +<% content_for :title, title %> + +<% content_for :before_content do %> + <%= govuk_back_link( + text: "Back", + href: send("locations_path", @scheme), + ) %> +<% end %> + +<%= render partial: "organisations/headings", locals: { main: @location.postcode, sub: @location.name } %> + +

Location

+ +<%= govuk_summary_list do |summary_list| %> + + <% @location.display_attributes.each do |attr| %> + <%= summary_list.row do |row| %> + <% row.key { attr[:name] } %> + <% row.value { details_html(attr) } %> + <% row.action(text: "Change", href: location_edit_name_path(location_id: @location.id, id: @scheme.id)) if attr[:edit] %> + <% end %> + <% end %> +<% end %> \ No newline at end of file diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 35a380fb5..18d4be6ed 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -757,8 +757,21 @@ RSpec.describe "Schemes scheme Features" do click_link(location.postcode) end - it "shows available fields to edit" do - expect(page).to have_current_path("/schemes/#{scheme.id}/locations/#{location.id}/edit-name") + it "displays details about the selected location" do + expect(page).to have_current_path("/schemes/#{scheme.id}/locations/#{location.id}") + expect(page).to have_content(location.postcode) + expect(page).to have_content(location.location_admin_district) + expect(page).to have_content(location.name) + expect(page).to have_content(location.units) + expect(page).to have_content(location.type_of_unit) + expect(page).to have_content(location.mobility_type) + expect(page).to have_content(location.location_code) + end + + it "only allows to edit the location name" do + assert_selector "a", text: "Change", count: 1 + + click_link("Change") expect(page).to have_content "Location name for #{location.postcode}" end @@ -775,15 +788,27 @@ RSpec.describe "Schemes scheme Features" do context "and I change the location name" do before do - fill_in "location-name-field", with: "NewName" - click_button "Save and continue" + click_link("Change") end it "returns to locations check your answers page and shows the new name" do + fill_in "location-name-field", with: "NewName" + click_button "Save and continue" expect(page).to have_content location.id expect(page).to have_content "NewName" expect(page.current_url.split("/").last).to eq("check-answers#locations") end + + context "when I press the back button" do + before do + click_link "Back" + end + + it "I see location details" do + expect(page).to have_content location.name + expect(page).to have_current_path("/schemes/#{scheme.id}/locations/#{location.id}") + end + end end end diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb index 856575932..e87867cd5 100644 --- a/spec/models/location_spec.rb +++ b/spec/models/location_spec.rb @@ -111,4 +111,22 @@ RSpec.describe Location, type: :model do end end end + + describe "#display_attributes" do + let(:location) { FactoryBot.build(:location) } + + it "returns correct display attributes" do + attributes = [ + { name: "Postcode", value: location.postcode }, + { name: "Local authority", value: location.location_admin_district }, + { name: "Location name", value: location.name, edit: true }, + { name: "Total number of units at this location", value: location.units }, + { name: "Common type of unit", value: location.type_of_unit }, + { name: "Mobility type", value: location.mobility_type }, + { name: "Code", value: location.location_code }, + ] + + expect(location.display_attributes).to eq(attributes) + end + end end