Skip to content
This repository has been archived by the owner on Dec 23, 2017. It is now read-only.

Commit

Permalink
Merge pull request #610 from jmcarp/feature/election-summary
Browse files Browse the repository at this point in the history
Feature/election summary
  • Loading branch information
LindsayYoung committed Sep 10, 2015
2 parents 09ff91e + 9056b8b commit a2ed993
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
43 changes: 43 additions & 0 deletions static/js/modules/election-summary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

/* global require, module */

var $ = require('jquery');
var URI = require('URIjs');

var helpers = require('./helpers');

function buildUrl(opts) {
var parts = ['elections', opts.office, opts.state, opts.district, opts.cycle]
.filter(function(part) {
return !!part;
})
.concat('')
.join('/');
return URI(parts).toString();
}

function ElectionSummary(selector, opts) {
this.$elm = $(selector);
this.opts = opts;

this.$count = this.$elm.find('.js-count');
this.$receipts = this.$elm.find('.js-receipts');
this.$disbursements = this.$elm.find('.js-disbursements');

this.fetch();
this.$elm.find('.js-election-url').attr('href', buildUrl(this.opts));
}

ElectionSummary.prototype.fetch = function() {
var url = helpers.buildUrl(['elections', 'summary'], this.opts);
$.getJSON(url).done(this.draw.bind(this));
};

ElectionSummary.prototype.draw = function(response) {
this.$count.text(response.count);
this.$receipts.text(helpers.currency(response.receipts));
this.$disbursements.text(helpers.currency(response.disbursements));
};

module.exports = {ElectionSummary: ElectionSummary};
2 changes: 2 additions & 0 deletions static/js/pages/landing.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var $ = require('jquery');
var tables = require('../modules/tables');
var columns = require('../modules/columns');
var lookup = require('../modules/election-lookup');
var summary = require('../modules/election-summary');

var filingsColumns = columns.getColumns(
columns.filings,
Expand All @@ -23,4 +24,5 @@ $(document).ready(function() {
});

new lookup.ElectionLookupPreview('#election-preview');
new summary.ElectionSummary('#election-summary', {cycle: 2016, office: 'president'});
});
12 changes: 6 additions & 6 deletions templates/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,22 @@ <h2 class="icon-heading__title widget__title"><span class="t-short">Find electio
</form>
</div>

<div class="widget widget--neutral">
<div id="election-summary" class="widget widget--neutral">
<h2 class="widget__title"><span class="t-short">Right now in the 2016 presidential election:</span></h2>
<div class="widget__content">
<div>
<h5 class="t-data-header">Candidates Running</h5>
<span class="t-big-data">[number]</span>
<span class="t-big-data js-count"></span>
</div>
<div>
<h5 class="t-data-header">Funds raised</h5>
<span class="t-big-data">$[number]</span>
</div>
<span class="t-big-data js-receipts"></span>
</div>
<div>
<h5 class="t-data-header">Funds spent</h5>
<span class="t-big-data">$[number]</span>
<span class="t-big-data js-disbursements"></span>
</div>
<a href="" class="button--election button--neutral">Compare candidates in this election</a>
<a class="button--election button--neutral js-election-url">Compare candidates in this election</a>
</div>
</div>
</div>
Expand Down
7 changes: 5 additions & 2 deletions tests/selenium/error_page_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from selenium.webdriver.common.keys import Keys

from .base_test_class import BaseTest


Expand All @@ -15,7 +17,8 @@ def testErrorPageLoads(self):
def testErrorPageSearch(self):
self.driver.get(self.url)
main = self.driver.find_element_by_tag_name('main')
main.find_element_by_class_name('js-search-input').send_keys('obama')
main.find_element_by_class_name('button--search').click()
field = main.find_element_by_class_name('js-search-input')
field.send_keys('obama')
field.send_keys(Keys.ENTER)

self.elementExistsByClassName('tst-search_results')

0 comments on commit a2ed993

Please sign in to comment.