Browse Source

tab nav helper test

pull/719/head
JG 3 years ago
parent
commit
da8d0eca33
  1. 2
      app/helpers/tab_nav_helper.rb
  2. 2
      app/views/locations/index.html.erb
  3. 6
      db/seeds.rb
  4. 7
      spec/helpers/tab_nav_helper_spec.rb

2
app/helpers/tab_nav_helper.rb

@ -11,7 +11,7 @@ module TabNavHelper
[govuk_link_to(link_text, "/schemes/#{location.scheme.id}/locations/#{location.id}/edit", method: :patch), "<span class=\"govuk-visually-hidden\">Location </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{location.name}</span>"].join("\n") [govuk_link_to(link_text, "/schemes/#{location.scheme.id}/locations/#{location.id}/edit", method: :patch), "<span class=\"govuk-visually-hidden\">Location </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{location.name}</span>"].join("\n")
end end
def edit_location_cell(location) def edit_location_name_cell(location)
link_text = location.postcode link_text = location.postcode
[govuk_link_to(link_text, "/schemes/#{location.scheme.id}/locations/#{location.id}/edit-name", method: :patch), "<span class=\"govuk-visually-hidden\">Location </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{location.name}</span>"].join("\n") [govuk_link_to(link_text, "/schemes/#{location.scheme.id}/locations/#{location.id}/edit-name", method: :patch), "<span class=\"govuk-visually-hidden\">Location </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{location.name}</span>"].join("\n")
end end

2
app/views/locations/index.html.erb

@ -36,7 +36,7 @@
<%= table.body do |body| %> <%= table.body do |body| %>
<%= body.row do |row| %> <%= body.row do |row| %>
<% row.cell(text: location.id) %> <% row.cell(text: location.id) %>
<% row.cell(text: simple_format(edit_location_cell(location), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %> <% row.cell(text: simple_format(edit_location_name_cell(location), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: location.total_units) %> <% row.cell(text: location.total_units) %>
<% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>#{location.wheelchair_adaptation == 'Yes' ? "\n<span class=\"govuk-!-font-weight-regular app-!-colour-muted\">With wheelchair adaptations</span>" : ''}")) %> <% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>#{location.wheelchair_adaptation == 'Yes' ? "\n<span class=\"govuk-!-font-weight-regular app-!-colour-muted\">With wheelchair adaptations</span>" : ''}")) %>
<% end %> <% end %>

6
db/seeds.rb

@ -112,7 +112,7 @@ unless Rails.env.test?
Location.create!( Location.create!(
scheme: scheme1, scheme: scheme1,
location_code: "S254-CU193AA", location_code: "S254-CU193AA",
postcode: "CU19 3AA", postcode: "CU193AA",
name: "Rectory Road", name: "Rectory Road",
type_of_unit: 4, type_of_unit: 4,
type_of_building: "Purpose-built", type_of_building: "Purpose-built",
@ -123,7 +123,7 @@ unless Rails.env.test?
Location.create!( Location.create!(
scheme: scheme1, scheme: scheme1,
location_code: "S254-DM250DC", location_code: "S254-DM250DC",
postcode: "DM25 0DC", postcode: "DM250DC",
name: "Smithy Lane", name: "Smithy Lane",
type_of_unit: 1, type_of_unit: 1,
type_of_building: "Converted from previous residential or non-residential property", type_of_building: "Converted from previous residential or non-residential property",
@ -134,7 +134,7 @@ unless Rails.env.test?
Location.create!( Location.create!(
scheme: scheme2, scheme: scheme2,
location_code: "S254-YX130WP", location_code: "S254-YX130WP",
postcode: "YX13 0WP", postcode: "YX130WP",
name: "Smithy Lane", name: "Smithy Lane",
type_of_unit: 2, type_of_unit: 2,
type_of_building: "Converted from previous residential or non-residential property", type_of_building: "Converted from previous residential or non-residential property",

7
spec/helpers/tab_nav_helper_spec.rb

@ -20,6 +20,13 @@ RSpec.describe TabNavHelper do
end end
end end
describe "#edit_location_name_cell" do
it "returns the location link to the postcode with optional name" do
expected_html = "<a class=\"govuk-link\" rel=\"nofollow\" data-method=\"patch\" href=\"/schemes/#{scheme.id}/locations/#{location.id}/edit-name\">#{location.postcode}</a>\n<span class=\"govuk-visually-hidden\">Location </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{location.name}</span>"
expect(edit_location_name_cell(location)).to match(expected_html)
end
end
describe "#location_cell" do describe "#location_cell" do
it "returns the location link to the postcode with optional name" do it "returns the location link to the postcode with optional name" do
expected_html = "<a class=\"govuk-link\" rel=\"nofollow\" data-method=\"patch\" href=\"/schemes/#{scheme.id}/locations/#{location.id}/edit\">#{location.postcode}</a>\n<span class=\"govuk-visually-hidden\">Location </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{location.name}</span>" expected_html = "<a class=\"govuk-link\" rel=\"nofollow\" data-method=\"patch\" href=\"/schemes/#{scheme.id}/locations/#{location.id}/edit\">#{location.postcode}</a>\n<span class=\"govuk-visually-hidden\">Location </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{location.name}</span>"

Loading…
Cancel
Save