Skip to content

Commit 7f92d85

Browse files
committed
Clean up state level refactor + fix its styles
1 parent 3b05f0f commit 7f92d85

File tree

8 files changed

+45
-60
lines changed

8 files changed

+45
-60
lines changed

app/assets/javascripts/application/tools/email.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ $(document).on('ready', function() {
2626
}
2727
update_tabs(1, 2);
2828
$(".progress-striped").hide();
29-
$form.remove();
29+
$(".address-lookup").remove();
3030
} else if (data.responseText) {
3131
show_error(data.responseText, $form);
3232
} else {

app/assets/stylesheets/application/action_page.scss

+6
Original file line numberDiff line numberDiff line change
@@ -1316,3 +1316,9 @@ html.js #affiliations {
13161316
}
13171317
}
13181318

1319+
.state-email-body {
1320+
padding: 0.5rem 1.5rem;
1321+
form {
1322+
padding: 0;
1323+
}
1324+
}
+29-32
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,40 @@
1-
<div class="state-rep-lookup">
1+
<div class="address-lookup">
22
<p>Enter your address below and we'll help you email your representatives (US addresses only).</p>
3-
<div class="address-lookup">
4-
<%= form_tag(tools_state_reps_path, method: :post, remote: true, class: "form state-rep-lookup") do %>
5-
<%= hidden_field_tag :email_campaign_id, @actionPage.email_campaign.id %>
3+
<%= form_tag(tools_state_reps_path, method: :post, remote: true, class: "form state-rep-lookup") do %>
4+
<%= hidden_field_tag :email_campaign_id, @actionPage.email_campaign.id %>
65

7-
<fieldset id="lookup-address">
8-
<h3>
9-
<span class="customize-message-popover" data-toggle="tooltip" data-trigger="hover">?
10-
<span class="tooltiptext">We'll use your address to find your state representatives.</span>
11-
</span>
12-
Look up your state representatives
13-
</h3>
14-
<div id="errors"></div>
6+
<fieldset id="lookup-address">
7+
<h3>
8+
<span class="customize-message-popover" data-toggle="tooltip" data-trigger="hover">?
9+
<span class="tooltiptext">We'll use your address to find your state representatives.</span>
10+
</span>
11+
Look up your state representatives
12+
</h3>
13+
<div id="errors"></div>
1514

16-
<div class="form-group">
17-
<%= text_field_tag :street_address, (current_user && current_user.street_address),
18-
placeholder: "Street Address", "aria-label": "Street Address",
19-
required: true, class: "form-control" %>
20-
</div>
15+
<div class="form-group">
16+
<%= text_field_tag :street_address, (current_user && current_user.street_address),
17+
placeholder: "Street Address", "aria-label": "Street Address",
18+
required: true, class: "form-control" %>
19+
</div>
2120

22-
<div class="form-group">
23-
<%= text_field_tag :zipcode, (current_user && current_user.zipcode),
24-
placeholder: "Zip Code", "aria-label": "Zip Code", required: true,
25-
class: "form-control", title: "Must be 5 numeric numbers",
26-
pattern: "\\d{5}", maxlength: 5 %>
27-
</div>
21+
<div class="form-group">
22+
<%= text_field_tag :zipcode, (current_user && current_user.zipcode),
23+
placeholder: "Zip Code", "aria-label": "Zip Code", required: true,
24+
class: "form-control", title: "Must be 5 numeric numbers",
25+
pattern: "\\d{5}", maxlength: 5 %>
26+
</div>
2827

29-
<div class="form-errors info-circle error hidden"></div>
28+
<div class="form-errors info-circle error hidden"></div>
3029

31-
<p class="privacy-notice">Uses <a href="https://developers.google.com/terms/api-services-user-data-policy" target="_blank">Google</a>'s APIs (
30+
<p class="privacy-notice">Uses <a href="https://developers.google.com/terms/api-services-user-data-policy" target="_blank">Google</a>'s APIs (
3231
<span class="privacy-notice-popover" data-toggle="tooltip" data-trigger="hover">why?
3332
<!-- Attribution Guidelines: https://developers.google.com/civic-information/docs/data_guidelines?hl=en#data-availability -->
3433
<span class="tooltiptext">Representative information powered by the Civic Information API.</span>
3534
</span>).
36-
</p>
37-
</fieldset>
38-
<input type="submit" class="eff-button" value="Find your reps">
39-
<%= render "tools/loading" -%>
40-
</div>
41-
<% end %>
35+
</p>
36+
</fieldset>
37+
<input type="submit" class="eff-button" value="Find your reps">
38+
<%= render "tools/loading" -%>
39+
<% end %>
4240
</div>
43-
<div class="state-reps"></div>

app/views/tools/_state_leg_email.html.erb

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
<h2 class="tool-title">Take action</h2>
1010
</div>
1111

12-
<div class="state-email-body">
12+
<div class="tool-body state-email-body">
1313
<%= render 'tools/lookup_state_rep' %>
14+
<div class="state-reps"></div>
1415
</div>
1516
</div>
1617
</div>

app/views/tools/_state_reps.html.erb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<div class="state-rep-names-and-emails">
2-
<%= "This action is for the #{legislative_level_from_state_representative_info(@email_campaign.leg_level)}." %>
2+
<p><%= "This action is for the #{legislative_level_from_state_representative_info(@email_campaign.leg_level)}." %></p>
33
<% @state_reps.each do |sr| %>
44
<div>
5+
<p>
56
<%= "Your representative is #{sr['name']}" %>.
67
<% if sr["emails"].present? %>
78
<%= "They can be reached at: #{sr['emails'].join(', ')}" %>
89
<% else %>
910
<%= "We could not find their email address." %>
1011
<% end %>
12+
</p>
1113
</div>
1214
<% end %>
1315
</div>

spec/controllers/tools_controller_spec.rb

-20
Original file line numberDiff line numberDiff line change
@@ -80,26 +80,6 @@
8080
expect(response).to redirect_to(uri)
8181
end
8282
end
83-
84-
describe "#state_reps" do
85-
let(:email_campaign) { FactoryBot.create(:email_campaign, :state_leg) }
86-
let(:address) { "815 Eddy St 94109" }
87-
let(:json_parseable_state_officials) { '{"officials": [{"name": "Sponge Bob", "party": "Sandy Party", "emails": ["[email protected]"]}]}' }
88-
89-
before do
90-
Rails.application.config.google_civic_api_url = "http://civic.example.com"
91-
Rails.application.secrets.google_civic_api_key = "test-key-for-civic-api"
92-
93-
stub_request(:get, "http://civic.example.com/?address=%20&includeOffices=true&key=test-key-for-civic-api&levels=administrativeArea1&roles=legislatorUpperBody")
94-
.to_return(status: 200, body: json_parseable_state_officials, headers: {})
95-
end
96-
97-
it "should render JSON with the state officials array" do
98-
get :state_reps, params: { email_campaign_id: email_campaign.action_page.email_campaign_id }
99-
100-
expect(response).to have_http_status(200)
101-
end
102-
end
10383
end
10484

10585
def create_signature_and_have_user_sign

spec/requests/tools_spec.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,22 @@
1818
}
1919
end
2020
let!(:address) { "#{params[:street_address]} #{params[:zipcode]}" }
21+
let!(:headers) { { "CONTENT_TYPE" => "application/javascript" } }
2122

2223
before do
2324
Rails.application.config.google_civic_api_url = "https://civic.example.com"
2425
Rails.application.secrets.google_civic_api_key = "test-key-for-civic-api"
2526
end
2627

27-
describe "GET tools/state_reps" do
28-
# TODO: should this be a POST?
28+
describe "POST tools/state_reps" do
2929
it "returns json containing rep data for a given address" do
30-
# mock civic api
3130
civic_api = class_double("CivicApi")
3231
.as_stubbed_const(transfer_nested_constants: true)
3332
allow(civic_api).to receive(:state_rep_search)
3433
.with(address, campaign.leg_level)
3534
.and_return(officials)
3635

37-
get "/tools/state_reps", params: params
36+
post "/tools/state_reps", params: params, xhr: true
3837

3938
expect(response).to have_http_status(200)
4039
expect(response.body).to include(officials.first["name"])

spec/system/action_pages/state_leg_email_action_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
fill_in "street_address", with: "815 Eddy St"
3030
fill_in "zipcode", with: "94109"
31-
click_on "See Your Representatives"
31+
click_on "Find your reps"
3232

3333
expect(page).to have_content("Sponge Bob")
3434
expect(page).not_to have_content("Thank You!")

0 commit comments

Comments
 (0)