Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Remove upcoming elections" #3462

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
16 changes: 15 additions & 1 deletion app/presenters/electoral_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def presented_registration_address
end

def upcoming_elections
dates.flat_map { |date| present_ballots(date) } if dates.present?

fake_response["dates"].flat_map { |date| present_ballots(date) }
# dates.flat_map { |date| present_ballots(date) } if dates.present?
end

def use_electoral_services_contact_details?
Expand Down Expand Up @@ -62,7 +64,19 @@ def duplicate_contact_details?
end
end

def present_ballots(date)
if date["ballots"].present?
date["ballots"].map { |b| "#{b['poll_open_date']} - #{b['ballot_title']}" } +
date["ballots"].map { |b| "#{b['poll_open_date']} - #{b['ballot_title']}" } +
date["ballots"].map { |b| "#{b['poll_open_date']} - #{b['ballot_title']}" }
end
end

def no_contact_details?
registration.nil? && electoral_services.nil?
end

def fake_response
JSON.parse('{"dates":[{"date":"2017-05-04","polling_station":{"polling_station_known":true,"custom_finder":null,"report_problem_url":"http://wheredoivote.co.uk/report_problem/?source=testing&source_url=testing","station":{"id":"w06000015.QK","type":"Feature","geometry":{"type":"Point","coordinates":[-3.119229,51.510885]},"properties":{"postcode":"","address":"EarlswoodSocialClub,160-164GreenwayRoad,Rumney"}}},"advance_voting_station":null,"notifications":[{"title":"Someunexpectedeventishappening","type":"cancelled_election","detail":"Somemoredetails","url":"https://foo.bar/baz"}],"ballots":[{"ballot_paper_id":"local.cardiff.pontprennauold-st-mellons.2017-05-04","ballot_title":"CardifflocalelectionPontprennau/OldSt.Mellons","ballot_url":"https://developers.democracyclub.org.uk/api/v1/local.cardiff.pontprennauold-st-mellons.2017-05-04/","poll_open_date":"2017-05-04","elected_role":"LocalCouncillor","metadata":null,"cancelled":false,"replaced_by":null,"replaces":null,"election_id":"local.cardiff.2017-05-04","election_name":"Cardifflocalelection","post_name":"Pontprennau/OldSt.Mellons","candidates_verified":false,"voting_system":{"slug":"FPTP","name":"First-past-the-post","uses_party_lists":false},"seats_contested":1,"candidates":[{"list_position":null,"party":{"party_id":"party:90","party_name":"LiberalDemocrats"},"person":{"ynr_id":23417,"name":"DavidKeigwin","absolute_url":"https://whocanivotefor.co.uk/person/23417/david-keigwin","email":"dave@example.com","photo_url":null}},{"list_position":null,"party":{"party_id":"party:52","party_name":"ConservativeandUnionistParty"},"person":{"ynr_id":8071,"name":"JoelWilliams","absolute_url":"https://whocanivotefor.co.uk/person/8071/joel-williams","email":null,"photo_url":"https://static-candidates.democracyclub.org.uk/media/images/images/8071.png"}}],"wcivf_url":"https://whocanivotefor.co.uk/elections/local.cardiff.2017-05-04/post-UTE:W05000900/pontprennauold-st-mellons"}]}]}')
end
end
14 changes: 14 additions & 0 deletions app/views/electoral/_upcoming_elections.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%= render "govuk_publishing_components/components/heading",
text: "Next elections",
font_size: "m",
margin_bottom: 4
%>
<% if elections %>
<p class="govuk-body">The upcoming elections for your area are as follows:</p>
<%= render "govuk_publishing_components/components/list", {
visible_counters: true,
items: elections
} %>
<% else %>
<p class="govuk-body">There are no upcoming elections for your area</p>
<% end %>
2 changes: 2 additions & 0 deletions app/views/electoral/results.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@
}
%>
<% end %>

<%= render partial: "upcoming_elections", locals: { elections: @presenter.upcoming_elections } %>
<% end %>
24 changes: 24 additions & 0 deletions test/integration/electoral_look_up_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ def search_for(postcode:)

context "searching by postcode" do
context "when a valid postcode is entered which matches a single address" do
should "display upcoming elections if available" do
with_electoral_api_url do
stub_api_postcode_lookup("LS11UR", response: api_response)

search_for(postcode: "LS11UR")
assert page.has_selector?("h2", text: "Next elections")
assert page.has_text?("2017-05-04 - Cardiff local election Pontprennau/Old St. Mellons")
assert page.has_selector?("meta[name=robots][content=noindex]", visible: :all)
end
end

should "display the electoral service (council) address if it's different to the registration office address" do
with_different_address = JSON.parse(api_response)
with_different_address["registration"] = { "address" => "foo" }
Expand Down Expand Up @@ -59,6 +70,19 @@ def search_for(postcode:)
end
end

should "inform user if there are no upcoming elections " do
without_dates = JSON.parse(api_response)
without_dates["dates"] = []
stub_api_postcode_lookup("LS11UR", response: without_dates.to_json)

with_electoral_api_url do
search_for(postcode: "LS11UR")

assert page.has_selector?("h2", text: "Next elections")
assert page.has_text?("There are no upcoming elections for your area")
end
end

should "with an invalid postcode" do
with_electoral_api_url do
search_for(postcode: "INVALID POSTCODE")
Expand Down
8 changes: 8 additions & 0 deletions test/unit/presenters/electoral_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ def electoral_presenter(payload)
end
end

context "when dates and ballots are present in the api response" do
should "should present upcoming elections" do
subject = electoral_presenter(api_response)
expected = ["2017-05-04 - Cardiff local election Pontprennau/Old St. Mellons"]
assert_equal subject.upcoming_elections, expected
end
end

context "presenting addresses" do
context "when duplicate contact details are provided" do
should "we should not show the electoral services address" do
Expand Down