Browse Source

Add show location page

pull/976/head
Kat 3 years ago
parent
commit
31942a7029
  1. 2
      app/controllers/locations_controller.rb
  2. 10
      app/models/location.rb
  3. 2
      app/views/locations/edit_name.html.erb
  4. 2
      app/views/locations/index.html.erb
  5. 24
      app/views/locations/show.html.erb
  6. 33
      spec/features/schemes_spec.rb
  7. 18
      spec/models/location_spec.rb

2
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)

10
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

2
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 %>

2
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("<span>#{location.type_of_unit}</span>")) %>
<% row.cell(text: location.mobility_type) %>

24
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 } %>
<h2 class="govuk-visually-hidden">Location</h2>
<%= 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 %>

33
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

18
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

Loading…
Cancel
Save