diff --git a/Rakefile b/Rakefile index 7c16938f..9f59ecc2 100644 --- a/Rakefile +++ b/Rakefile @@ -9,3 +9,5 @@ if Rails.env.development? end Rails.application.load_tasks + +task default: 'jasmine:ci' diff --git a/app/assets/javascripts/utility.js b/app/assets/javascripts/utility.js index af0f88df..4e455078 100644 --- a/app/assets/javascripts/utility.js +++ b/app/assets/javascripts/utility.js @@ -46,18 +46,23 @@ }; microp.format.stardardizeUrl = function(str) { - var lastChar = str.length - 1; - if (str.charAt(lastChar) === '/') { - str = str.substring(0, lastChar); + if (typeof(str) === 'string'){ + var lastChar = str.length - 1; + if (str.charAt(lastChar) === '/') { + str = str.substring(0, lastChar); + } + str = str.toLowerCase(); } - str = str.toLowerCase(); return str; }; microp.format.removeGitPrefix = function(str) { - return str.includes('https') - ? str.split("https://github.com/").join("") - : str; + if (typeof(str) === 'string'){ + return str.includes('https') + ? str.split("https://github.com/").join("") + : str; + } + return str }; microp.format.transformDollars = function(str) { @@ -78,6 +83,10 @@ // Outputs a date object formatted like so: %Y-%m-%d // Or like so %m/%d if a separator is included microp.format.date = function (date, seperator) { + if (typeof(date) === 'undefined' || typeof(date) === undefined) { + return date; + } + var dateObj, date; if (typeof(date) === 'string') { diff --git a/app/assets/javascripts/winners/metrics.js b/app/assets/javascripts/winners/metrics.js index d6652d9e..e094751e 100644 --- a/app/assets/javascripts/winners/metrics.js +++ b/app/assets/javascripts/winners/metrics.js @@ -67,8 +67,12 @@ getBidsPerAuction: function() { var bidsPerAuction = _.map(this.auctions, function(auction, key){ - return auction.bids.length - }) + if (auction.bids) { + return auction.bids.length + } else { + return 0; + } + }); return d3.mean(bidsPerAuction); }, diff --git a/spec/javascripts/drawer_spec.js b/spec/javascripts/drawer_spec.js index 154942ee..8aa03357 100644 --- a/spec/javascripts/drawer_spec.js +++ b/spec/javascripts/drawer_spec.js @@ -1,87 +1,87 @@ describe('Drawer', function () { var drawer - describe('When you first see the page', function () { + describe('When you first go to the homepage, the drawer', function () { beforeEach(function () { drawer = new Drawer(); }); - it('then the drawer is hidden', function() { + it('is hidden', function() { expect(drawer.isOpen).not.toBeTruthy(); }); }); - describe('When show is triggered', function () { + describe('When show is triggered, the drawer', function () { beforeEach(function () { drawer = new Drawer(); drawer.show() }); - it('then the drawer is open', function() { + it('is open', function() { expect(drawer.isOpen).toBeTruthy(); }); }); - describe('When show is triggered twice', function () { + describe('When show is triggered twice, the drawer', function () { beforeEach(function () { drawer = new Drawer(); drawer.show(); drawer.show(); }); - it('then the drawer is open', function() { + it('is open', function() { expect(drawer.isOpen).toBeTruthy(); }); }); - describe('When hide is triggered twice', function () { + describe('When hide is triggered twice, the drawer', function () { beforeEach(function () { drawer = new Drawer(); drawer.hide(); drawer.hide(); }); - it('then the drawer is closed', function() { + it('is closed', function() { expect(drawer.isOpen).not.toBeTruthy(); }); }); - describe('When the drawer is toggled', function () { + describe('When the drawer is toggled, the drawer', function () { beforeEach(function () { drawer = new Drawer(); drawer.toggle(); }) - it('then it opens', function() { + it('is open', function() { expect(drawer.isOpen).toBeTruthy(); }) }); - describe('When the drawer is opened, then closed', function () { + describe('When the drawer is opened, then closed, the drawer', function () { beforeEach(function () { drawer = new Drawer(); drawer.show(); drawer.hide(); }) - it('then it is closed', function() { + it('is closed', function() { expect(drawer.isOpen).not.toBeTruthy() }); }); - describe('When the drawer is toggled twice', function () { + describe('When the drawer is toggled twice, the drawer', function () { beforeEach(function () { drawer = new Drawer(); drawer.toggle(); drawer.toggle(); }) - it('then it is closed', function() { + it('is closed', function() { expect(drawer.isOpen).not.toBeTruthy(); }); }); - describe('When the drawer is toggled three times', function () { + describe('When the drawer is toggled three times, the drawer', function () { beforeEach(function () { drawer = new Drawer(); drawer.toggle(); @@ -89,7 +89,7 @@ describe('Drawer', function () { drawer.toggle(); }) - it('then it is open', function() { + it('is open', function() { expect(drawer.isOpen).toBeTruthy(); }) }); diff --git a/spec/javascripts/helpers/auctionsMock.js b/spec/javascripts/helpers/auctionsMock.js index 56a79468..4df0fa0e 100644 --- a/spec/javascripts/helpers/auctionsMock.js +++ b/spec/javascripts/helpers/auctionsMock.js @@ -1,314 +1,314 @@ var auctionsMock = { - "auctions":[ - { - "issue_url":"https://github.com/18F/tock/issues/328", - "github_repo":"https://github.com/18F/tock", - "start_price":3500, - "started_at":"2016-03-10T18:00:00+00:00", - "ended_at":"2016-03-17T18:00:00+00:00", - "title":"Clever title 1", - "description":"clever description 1", - "id":23, - "winning_bid":{ - "amount":2000, - "bidder_id":30 - }, - "bids":[ - { - "bidder_id":69, - "auction_id":23, - "amount":3000, - "created_at":"2016-03-14T16:09:49+00:00", - "updated_at":"2016-03-14T16:09:49+00:00", - "id":200, - "bidder":{ - "github_id":"15251877", - "duns_number":"079859219", - "name":"Cat Woman", - "sam_account":true, - "created_at":"2016-01-05T18:43:53+00:00", - "updated_at":"2016-01-11T03:15:51+00:00", - "id":69, - "github_login":null - } - }, - { - "bidder_id":30, - "auction_id":23, - "amount":2000, - "created_at":"2016-03-14T15:34:58+00:00", - "updated_at":"2016-03-14T15:34:58+00:00", - "id":195, - "bidder":{ - "github_id":"387035", - "duns_number":"080033077", - "name":"George Michael Bluth", - "sam_account":true, - "created_at":"2015-12-29T16:14:47+00:00", - "updated_at":"2016-01-11T03:15:25+00:00", - "id":30, - "github_login":null - } - } - ], - "created_at":"2016-03-08T23:54:11+00:00", - "updated_at":"2016-03-08T23:54:11+00:00", - "summary":"We want some kind of change" + "auctions":[ + { + "issue_url":"https://github.com/18F/tock/issues/328", + "github_repo":"https://github.com/18F/tock", + "start_price":3500, + "started_at":"2016-03-10T18:00:00+00:00", + "ended_at":"2016-03-17T18:00:00+00:00", + "title":"Clever title 1", + "description":"clever description 1", + "id":23, + "winning_bid":{ + "amount":2000, + "bidder_id":30 }, - { - "issue_url":"https://github.com/18F/micropurchase/issues/332", - "github_repo":"https://github.com/18F/micropurchase", - "start_price":3500, - "started_at":"2016-03-01T18:00:00+00:00", - "ended_at":"2016-03-14T18:00:00+00:00", - "title":"clever title 2", - "description":"clever description 2", - "id":22, - "winning_bid": { - "amount": null, - "bidder_id": null - }, - "bids":[ - { - "bidder_id":30, - "auction_id":22, - "amount":3200, - "created_at":"2016-03-14T17:59:37+00:00", - "updated_at":"2016-03-14T17:59:37+00:00", - "id":227, - "bidder":{ - "github_id":"387035", - "duns_number":"080033077", - "name":"George Michael Bluth", - "sam_account":true, - "created_at":"2015-12-29T16:14:47+00:00", - "updated_at":"2016-01-11T03:15:25+00:00", - "id":30, - "github_login":null - } - } - ], - "created_at":"2016-03-08T23:23:31+00:00", - "updated_at":"2016-03-08T23:23:31+00:00", - "summary":"We want some kind of change" + "bids":[ + { + "bidder_id":69, + "auction_id":23, + "amount":3000, + "created_at":"2016-03-14T16:09:49+00:00", + "updated_at":"2016-03-14T16:09:49+00:00", + "id":200, + "bidder":{ + "github_id":"15251877", + "duns_number":"079859219", + "name":"Cat Woman", + "sam_account":true, + "created_at":"2016-01-05T18:43:53+00:00", + "updated_at":"2016-01-11T03:15:51+00:00", + "id":69, + "github_login":null + } + }, + { + "bidder_id":30, + "auction_id":23, + "amount":2000, + "created_at":"2016-03-14T15:34:58+00:00", + "updated_at":"2016-03-14T15:34:58+00:00", + "id":195, + "bidder":{ + "github_id":"387035", + "duns_number":"080033077", + "name":"George Michael Bluth", + "sam_account":true, + "created_at":"2015-12-29T16:14:47+00:00", + "updated_at":"2016-01-11T03:15:25+00:00", + "id":30, + "github_login":null + } + } + ], + "created_at":"2016-03-08T23:54:11+00:00", + "updated_at":"2016-03-08T23:54:11+00:00", + "summary":"We want some kind of change" + }, + { + "issue_url":"https://github.com/18F/micropurchase/issues/332", + "github_repo":"https://github.com/18F/micropurchase", + "start_price":3500, + "started_at":"2016-03-01T18:00:00+00:00", + "ended_at":"2016-03-14T18:00:00+00:00", + "title":"clever title 2", + "description":"clever description 2", + "id":22, + "winning_bid": { + "amount": 3200, + "bidder_id": 30 }, - { - "issue_url":"https://github.com/18F/fedramp-micropurchase/issues", - "github_repo":"https://github.com/18F/fedramp-micropurchase", - "start_price":3500, - "started_at":"2016-03-08T18:00:00+00:00", - "ended_at":"2016-03-14T18:00:00+00:00", - "title":"Clever title 3", - "description":"clever description 3", - "id":21, - "winning_bid":{ - "amount":250, - "bidder_id":44 - }, - "bids":[ - { - "bidder_id":69, - "auction_id":21, - "amount":3000, - "created_at":"2016-03-14T16:10:36+00:00", - "updated_at":"2016-03-14T16:10:36+00:00", - "id":201, - "bidder":{ - "github_id":"15251877", - "duns_number":"079859219", - "name":"Cat Woman", - "sam_account":true, - "created_at":"2016-01-05T18:43:53+00:00", - "updated_at":"2016-01-11T03:15:51+00:00", - "id":69, - "github_login":null - } - }, - { - "bidder_id":44, - "auction_id":21, - "amount":250, - "created_at":"2016-03-14T07:05:19+00:00", - "updated_at":"2016-03-14T07:05:19+00:00", - "id":193, - "bidder":{ - "github_id":"1451399", - "duns_number":"080014807", - "name":"Brienne of Tarth", - "sam_account":true, - "created_at":"2015-12-29T23:22:12+00:00", - "updated_at":"2016-01-29T18:07:33+00:00", - "id":44, - "github_login":null - } - }, - { - "bidder_id":18, - "auction_id":21, - "amount":1000, - "created_at":"2016-03-11T16:07:34+00:00", - "updated_at":"2016-03-11T16:07:34+00:00", - "id":187, - "bidder":{ - "github_id":"2124927", - "duns_number":"078327018", - "name":null, - "sam_account":true, - "created_at":"2015-12-19T15:32:41+00:00", - "updated_at":"2016-01-11T00:44:40+00:00", - "id":18, - "github_login":null - } - }, - { - "bidder_id":46, - "auction_id":21, - "amount":3500, - "created_at":"2016-03-11T00:50:50+00:00", - "updated_at":"2016-03-11T00:50:50+00:00", - "id":184, - "bidder":{ - "github_id":"1251540", - "duns_number":"079150065", - "name":"Kevin Garnett", - "sam_account":true, - "created_at":"2015-12-30T00:55:27+00:00", - "updated_at":"2016-01-11T03:15:30+00:00", - "id":46, - "github_login":null - } - }, - { - "bidder_id":148, - "auction_id":21, - "amount":2800, - "created_at":"2016-03-11T00:24:25+00:00", - "updated_at":"2016-03-11T00:24:25+00:00", - "id":183, - "bidder":{ - "github_id":"15351828", - "duns_number":"080034592", - "name":"Arya Stark", - "sam_account":true, - "created_at":"2016-02-12T01:57:50+00:00", - "updated_at":"2016-02-22T18:41:13+00:00", - "id":148, - "github_login":null - } - } - ], - "created_at":"2016-03-08T17:16:04+00:00", - "updated_at":"2016-03-08T17:16:04+00:00", - "summary":"We want some kind of update to our application" + "bids":[ + { + "bidder_id":30, + "auction_id":22, + "amount":3200, + "created_at":"2016-03-14T17:59:37+00:00", + "updated_at":"2016-03-14T17:59:37+00:00", + "id":227, + "bidder":{ + "github_id":"387035", + "duns_number":"080033077", + "name":"George Michael Bluth", + "sam_account":true, + "created_at":"2015-12-29T16:14:47+00:00", + "updated_at":"2016-01-11T03:15:25+00:00", + "id":30, + "github_login":null + } + } + ], + "created_at":"2016-03-08T23:23:31+00:00", + "updated_at":"2016-03-08T23:23:31+00:00", + "summary":"We want some kind of change" + }, + { + "issue_url":"https://github.com/18F/fedramp-micropurchase/issues", + "github_repo":"https://github.com/18F/fedramp-micropurchase", + "start_price":3500, + "started_at":"2016-03-08T18:00:00+00:00", + "ended_at":"2016-03-14T18:00:00+00:00", + "title":"Clever title 3", + "description":"clever description 3", + "id":21, + "winning_bid":{ + "amount":250, + "bidder_id":44 }, - { - "issue_url":"https://github.com/18F/openopps-platform/issues/1236", - "github_repo":"https://github.com/18F/openopps-platform", - "start_price":3500, - "started_at":"2016-03-01T18:00:00+00:00", - "ended_at":"2016-03-04T18:00:00+00:00", - "title":"Some clever title 4", - "description":"Some clever description 4", - "id":18, - "winning_bid":{ - "amount":3000, - "bidder_id":69 - }, - "bids":[ - { - "bidder_id":69, - "auction_id":18, - "amount":3000, - "created_at":"2016-03-14T17:59:58+00:00", - "updated_at":"2016-03-14T17:59:58+00:00", - "id":238, - "bidder":{ - "github_id":"15251877", - "duns_number":"079859219", - "name":"Cat Woman", - "sam_account":true, - "created_at":"2016-01-05T18:43:53+00:00", - "updated_at":"2016-01-11T03:15:51+00:00", - "id":69, - "github_login":null - } - }, - { - "bidder_id":30, - "auction_id":18, - "amount":3200, - "created_at":"2016-03-14T17:59:39+00:00", - "updated_at":"2016-03-14T17:59:39+00:00", - "id":230, - "bidder":{ - "github_id":"387035", - "duns_number":"080033077", - "name":"George Michael Bluth", - "sam_account":true, - "created_at":"2015-12-29T16:14:47+00:00", - "updated_at":"2016-01-11T03:15:25+00:00", - "id":30, - "github_login":null - } - }, - { - "bidder_id":69, - "auction_id":18, - "amount":3200, - "created_at":"2016-03-14T17:59:21+00:00", - "updated_at":"2016-03-14T17:59:21+00:00", - "id":223, - "bidder":{ - "github_id":"15251877", - "duns_number":"079859219", - "name":"Cat Woman", - "sam_account":true, - "created_at":"2016-01-05T18:43:53+00:00", - "updated_at":"2016-01-11T03:15:51+00:00", - "id":69, - "github_login":null - } - }, - { - "bidder_id":90, - "auction_id":18, - "amount":3300, - "created_at":"2016-03-14T17:58:52+00:00", - "updated_at":"2016-03-14T17:58:52+00:00", - "id":217, - "bidder":{ - "github_id":"684965", - "duns_number":"080126095", - "name":"Tayne", - "sam_account":true, - "created_at":"2016-01-11T18:33:42+00:00", - "updated_at":"2016-02-24T18:04:37+00:00", - "id":90, - "github_login":null - } - }, - { - "bidder_id":49, - "auction_id":18, - "amount":3100, - "created_at":"2016-03-14T17:58:42+00:00", - "updated_at":"2016-03-14T17:58:42+00:00", - "id":213, - "bidder":{ - "github_id":"688980", - "duns_number":"313210696", - "name":"Peter Pan", - "sam_account":true, - "created_at":"2015-12-30T06:05:37+00:00", - "updated_at":"2016-01-11T03:15:33+00:00", - "id":49, - "github_login":null - } - } - ], - "created_at":"2016-03-07T22:22:58+00:00", - "updated_at":"2016-03-07T22:22:58+00:00", - "summary":"Some clever summary 4" - } - ] + "bids":[ + { + "bidder_id":69, + "auction_id":21, + "amount":3000, + "created_at":"2016-03-14T16:10:36+00:00", + "updated_at":"2016-03-14T16:10:36+00:00", + "id":201, + "bidder":{ + "github_id":"15251877", + "duns_number":"079859219", + "name":"Cat Woman", + "sam_account":true, + "created_at":"2016-01-05T18:43:53+00:00", + "updated_at":"2016-01-11T03:15:51+00:00", + "id":69, + "github_login":null + } + }, + { + "bidder_id":44, + "auction_id":21, + "amount":250, + "created_at":"2016-03-14T07:05:19+00:00", + "updated_at":"2016-03-14T07:05:19+00:00", + "id":193, + "bidder":{ + "github_id":"1451399", + "duns_number":"080014807", + "name":"Brienne of Tarth", + "sam_account":true, + "created_at":"2015-12-29T23:22:12+00:00", + "updated_at":"2016-01-29T18:07:33+00:00", + "id":44, + "github_login":null + } + }, + { + "bidder_id":18, + "auction_id":21, + "amount":1000, + "created_at":"2016-03-11T16:07:34+00:00", + "updated_at":"2016-03-11T16:07:34+00:00", + "id":187, + "bidder":{ + "github_id":"2124927", + "duns_number":"078327018", + "name":null, + "sam_account":true, + "created_at":"2015-12-19T15:32:41+00:00", + "updated_at":"2016-01-11T00:44:40+00:00", + "id":18, + "github_login":null + } + }, + { + "bidder_id":46, + "auction_id":21, + "amount":3500, + "created_at":"2016-03-11T00:50:50+00:00", + "updated_at":"2016-03-11T00:50:50+00:00", + "id":184, + "bidder":{ + "github_id":"1251540", + "duns_number":"079150065", + "name":"Kevin Garnett", + "sam_account":true, + "created_at":"2015-12-30T00:55:27+00:00", + "updated_at":"2016-01-11T03:15:30+00:00", + "id":46, + "github_login":null + } + }, + { + "bidder_id":148, + "auction_id":21, + "amount":2800, + "created_at":"2016-03-11T00:24:25+00:00", + "updated_at":"2016-03-11T00:24:25+00:00", + "id":183, + "bidder":{ + "github_id":"15351828", + "duns_number":"080034592", + "name":"Arya Stark", + "sam_account":true, + "created_at":"2016-02-12T01:57:50+00:00", + "updated_at":"2016-02-22T18:41:13+00:00", + "id":148, + "github_login":null + } + } + ], + "created_at":"2016-03-08T17:16:04+00:00", + "updated_at":"2016-03-08T17:16:04+00:00", + "summary":"We want some kind of update to our application" + }, + { + "issue_url":"https://github.com/18F/openopps-platform/issues/1236", + "github_repo":"https://github.com/18F/openopps-platform", + "start_price":3500, + "started_at":"2016-03-01T18:00:00+00:00", + "ended_at":"2016-03-04T18:00:00+00:00", + "title":"Some clever title 4", + "description":"Some clever description 4", + "id":18, + "winning_bid":{ + "amount":3000, + "bidder_id":69 + }, + "bids":[ + { + "bidder_id":69, + "auction_id":18, + "amount":3000, + "created_at":"2016-03-14T17:59:58+00:00", + "updated_at":"2016-03-14T17:59:58+00:00", + "id":238, + "bidder":{ + "github_id":"15251877", + "duns_number":"079859219", + "name":"Cat Woman", + "sam_account":true, + "created_at":"2016-01-05T18:43:53+00:00", + "updated_at":"2016-01-11T03:15:51+00:00", + "id":69, + "github_login":null + } + }, + { + "bidder_id":30, + "auction_id":18, + "amount":3200, + "created_at":"2016-03-14T17:59:39+00:00", + "updated_at":"2016-03-14T17:59:39+00:00", + "id":230, + "bidder":{ + "github_id":"387035", + "duns_number":"080033077", + "name":"George Michael Bluth", + "sam_account":true, + "created_at":"2015-12-29T16:14:47+00:00", + "updated_at":"2016-01-11T03:15:25+00:00", + "id":30, + "github_login":null + } + }, + { + "bidder_id":69, + "auction_id":18, + "amount":3200, + "created_at":"2016-03-14T17:59:21+00:00", + "updated_at":"2016-03-14T17:59:21+00:00", + "id":223, + "bidder":{ + "github_id":"15251877", + "duns_number":"079859219", + "name":"Cat Woman", + "sam_account":true, + "created_at":"2016-01-05T18:43:53+00:00", + "updated_at":"2016-01-11T03:15:51+00:00", + "id":69, + "github_login":null + } + }, + { + "bidder_id":90, + "auction_id":18, + "amount":3300, + "created_at":"2016-03-14T17:58:52+00:00", + "updated_at":"2016-03-14T17:58:52+00:00", + "id":217, + "bidder":{ + "github_id":"684965", + "duns_number":"080126095", + "name":"Tayne", + "sam_account":true, + "created_at":"2016-01-11T18:33:42+00:00", + "updated_at":"2016-02-24T18:04:37+00:00", + "id":90, + "github_login":null + } + }, + { + "bidder_id":49, + "auction_id":18, + "amount":3100, + "created_at":"2016-03-14T17:58:42+00:00", + "updated_at":"2016-03-14T17:58:42+00:00", + "id":213, + "bidder":{ + "github_id":"688980", + "duns_number":"313210696", + "name":"Peter Pan", + "sam_account":true, + "created_at":"2015-12-30T06:05:37+00:00", + "updated_at":"2016-01-11T03:15:33+00:00", + "id":49, + "github_login":null + } + } + ], + "created_at":"2016-03-07T22:22:58+00:00", + "updated_at":"2016-03-07T22:22:58+00:00", + "summary":"Some clever summary 4" + } + ] } diff --git a/spec/javascripts/previous_winners_spec.js b/spec/javascripts/previous_winners_spec.js index 2b30863b..e0d42eae 100644 --- a/spec/javascripts/previous_winners_spec.js +++ b/spec/javascripts/previous_winners_spec.js @@ -20,9 +20,9 @@ describe('PreviousWinners', function () { charts = winners.charts }) - describe('receive mock data', function () { + describe('mock data', function () { - it('establish the object is correct', function() { + it('is the correct data', function() { expect(mock.auctions).not.toBe(undefined) expect(mock.auctions).toEqual(jasmine.any(Object)) expect(mock.auctions.length).toEqual(4) @@ -30,7 +30,7 @@ describe('PreviousWinners', function () { }) }) - describe('there is a winnersPage object', function() { + describe('winners page object', function() { it("called winners, and it exists", function(){ expect(winners).not.toBe(undefined) @@ -38,20 +38,20 @@ describe('PreviousWinners', function () { }) }) - describe('there is a Charts object', function() { + describe('Charts object', function() { - it("it exists", function(){ + it("exists", function(){ expect(charts).not.toBe(undefined) expect(charts).toEqual(jasmine.any(Object)) }) - it("it has an attribute, textRotation", function(){ + it("has an attribute, textRotation", function(){ expect(charts.textRotation).not.toBe(undefined) expect(charts.textRotation).toEqual(jasmine.any(Number)) }) - it("it has several methods", function(){ + it("has several methods", function(){ expect(charts.create).toEqual(jasmine.any(Object)) expect(charts.load).toEqual(jasmine.any(Object)) expect(charts.generate).toEqual(jasmine.any(Function)) @@ -62,57 +62,57 @@ describe('PreviousWinners', function () { }) }) - describe('there is a Metrics object', function() { + describe('Metrics object', function() { - it("and it exists", function(){ + it("exists", function(){ expect(metrics).not.toBe(undefined) expect(metrics).toEqual(jasmine.any(Object)) }) - it("with the correct number of auctions", function(){ + it("has the correct number of auctions", function(){ expect(metrics.auctions).not.toBe(undefined) expect(metrics.auctions).toEqual(jasmine.any(Array)) expect(metrics.auctions.length).toBe(4) }) - it("with the correct auction duration", function(){ + it("has the correct auction duration", function(){ expect(metrics.auctionLength).not.toBe(undefined) expect(metrics.auctionLength).toEqual(7.25) }) - it("with the correct average winning bid", function(){ + it("has the correct average winning bid", function(){ expect(metrics.avgWinningBids).not.toBe(undefined) - expect(metrics.avgWinningBids).toEqual(1750) + expect(metrics.avgWinningBids).toEqual(2112.5) }) - it("with the correct number of bids per auction", function(){ + it("has the correct number of bids per auction", function(){ expect(metrics.bidsPerAuction).not.toBe(undefined) expect(metrics.bidsPerAuction).toEqual(3.25) }) - it("with the correct number of repos", function(){ + it("has the correct number of repos", function(){ expect(metrics.repos).not.toBe(undefined) expect(metrics.repos).toEqual(4) }) - it("with the correct number of unique winners", function(){ + it("has the correct number of unique winners", function(){ expect(metrics.uniqueWinners).not.toBe(undefined) expect(metrics.uniqueWinners).toEqual(3) }) - it("with the correct number of bidding vendors", function(){ + it("has the correct number of bidding vendors", function(){ expect(metrics.biddingVendors).not.toBe(undefined) expect(metrics.biddingVendors).toEqual(8) }) - it("with javascript selectors", function(){ + it("has javascript selectors", function(){ expect(metrics.selectors).not.toBe(undefined) expect(metrics.selectors).toEqual(jasmine.any(Object)) }) }) - describe('donut 1 data', function () { + describe('donut 1 (Projects) data', function () { beforeEach(function(){ settings = charts.settings.donut1 matcher = { @@ -136,7 +136,7 @@ describe('PreviousWinners', function () { }) }) - describe('donut 2 data', function () { + describe('donut 2 (Languages) data', function () { beforeEach(function(){ settings = charts.settings.donut2 matcher = { @@ -145,7 +145,8 @@ describe('PreviousWinners', function () { ["ruby",2], ["python",2], ["yml",1], - [] + [], + ["go",1] ] } }) @@ -156,12 +157,12 @@ describe('PreviousWinners', function () { expect(settings.cols).toEqual(jasmine.any(Array)) }) - it('the array has the correct objects', function(){ + it('has an array with the correct objects', function(){ expect(settings).toEqual(matcher) }) }) - describe('chart 2 data', function () { + describe('chart 2 (Average winning bid) data', function () { beforeEach(function(){ settings = charts.settings.chart2 matcher = { @@ -170,16 +171,17 @@ describe('PreviousWinners', function () { "bids_dates", "2016-3-4", "2016-3-14", + "2016-3-14", "2016-3-17" ], - ["bids",3000,250,2000], + ["bids",3000,250,3200,2000], [ "means_dates", "2016-3-4", "2016-3-14", "2016-3-17" ], - ["means",3000,250,2000] + ["means",3000,1725,2000] ] } }) @@ -188,12 +190,12 @@ describe('PreviousWinners', function () { expect(settings).toEqual(matcher) }) - it('correct number of columns', function(){ + it('has the correct number of columns', function(){ expect(settings.cols.length).toEqual(4) }) }) - describe('chart 4 data', function () { + describe('chart 4 (Histogram timeseries) data', function () { beforeEach(function(){ settings = charts.settings.chart4 matcher = { @@ -210,16 +212,16 @@ describe('PreviousWinners', function () { expect(settings).toEqual(matcher) }) - it('correct number of columns', function(){ + it('has the correct number of columns', function(){ expect(settings.cols.length).toEqual(4) }) - it('correct x attribute', function(){ + it('has the correct x attribute', function(){ expect(settings.x).toEqual(matcher.x) }) }) - describe('chart 5 data', function () { + describe('chart 5 (Bubble chart) data', function () { beforeEach(function(){ settings = charts.settings.chart5 matcher = { @@ -228,17 +230,20 @@ describe('PreviousWinners', function () { ["18",5], ["date_1","2016-3-14"], ["21",5], + ["22",1], ["date_2","2016-3-17"], ["23",2] ], "z":{ - "18":3000, - "21":250, - "23":2000 + "18": 3000, + "21": 250, + "22": 3200, + "23": 2000 }, "xs":{ "18":"date_0", "21":"date_1", + "22":"date_1", "23":"date_2" } } @@ -248,11 +253,11 @@ describe('PreviousWinners', function () { expect(settings).toEqual(matcher) }) - it('winning bids are correct', function(){ + it('has the correct winning bids', function(){ expect(settings.z).toEqual(matcher.z) }) - it('dates are correct', function(){ + it('has the correct dates', function(){ expect(settings.xs).toEqual(matcher.xs) }) }) diff --git a/spec/javascripts/support/jasmine.yml b/spec/javascripts/support/jasmine.yml index 272aae7d..f12c4b5e 100644 --- a/spec/javascripts/support/jasmine.yml +++ b/spec/javascripts/support/jasmine.yml @@ -39,7 +39,6 @@ stylesheets: # - helpers/**/*.js # helpers: - - 'helpers/*.js' - 'helpers/**/*.js' # spec_files diff --git a/spec/javascripts/support/jasmine_helper.rb b/spec/javascripts/support/jasmine_helper.rb index 83377814..4d73aec5 100644 --- a/spec/javascripts/support/jasmine_helper.rb +++ b/spec/javascripts/support/jasmine_helper.rb @@ -1,15 +1,15 @@ -# Use this file to set/override Jasmine configuration options -# You can remove it if you don't need it. -# This file is loaded *after* jasmine.yml is interpreted. +#Use this file to set/override Jasmine configuration options +#You can remove it if you don't need it. +#This file is loaded *after* jasmine.yml is interpreted. # -# Example: using a different boot file. -# Jasmine.configure do |config| +#Example: using a different boot file. +#Jasmine.configure do |config| # config.boot_dir = '/absolute/path/to/boot_dir' # config.boot_files = lambda { ['/absolute/path/to/boot_dir/file.js'] } -# end +#end # -# Example: prevent PhantomJS auto install, uses PhantomJS already on your path. -# Jasmine.configure do |config| +#Example: prevent PhantomJS auto install, uses PhantomJS already on your path. +#Jasmine.configure do |config| # config.prevent_phantom_js_auto_install = true -# end +#end # diff --git a/spec/javascripts/utility_spec.js b/spec/javascripts/utility_spec.js index 749a477d..58a037d8 100644 --- a/spec/javascripts/utility_spec.js +++ b/spec/javascripts/utility_spec.js @@ -11,15 +11,18 @@ describe('Utility', function () { var a = 'https://google.com/'; var b = 'https://google.com'; var c = 'https://google.com//'; + var d = undefined; + it("removes a forward slash at the end", function(){ expect(stardardizeUrl(a)).toBe(b); expect(stardardizeUrl(a)).not.toBe(a); expect(stardardizeUrl(a)).not.toBe(c); expect(stardardizeUrl(b)).toBe(b); + expect(stardardizeUrl(d)).toBe(d); }); - it("it only removes the last forward slash", function(){ + it("only removes the last forward slash", function(){ expect(stardardizeUrl(c)).toBe(a); expect(stardardizeUrl(a)).not.toBe(c); expect(stardardizeUrl(c)).not.toBe(b); @@ -34,6 +37,7 @@ describe('Utility', function () { var april20 = 'Wed Apr 20 2016 17:42:46 GMT-0500 (CDT)' var april20Date = new Date('Wed Apr 20 2016 17:42:46 GMT-0500 (CDT)') + var dateUndefined = undefined; it("defaults to a dash delimiter", function(){ expect(format.date('10/14/1988')).toBe('1988-10-14'); @@ -50,6 +54,10 @@ describe('Utility', function () { expect(format.date(april20)).toBe('2016-4-20'); }); + it("handles undefined", function(){ + expect(format.date(dateUndefined)).toBe(undefined); + }); + it("has a / seperator option", function(){ expect(format.date('10/14/1988', '/')).not.toBe('1988-10-14'); expect(format.date('10/14/1988', '/')).toBe('10/14'); @@ -129,6 +137,7 @@ describe('Utility', function () { describe('microp.format.removeGitPrefix', function(){ var calc = 'https://github.com/18f/calc' var accordion = 'https://github.com/18f/accordion' + var undefinedProject = undefined beforeEach(function(){ removeGitPrefix = microp.format.removeGitPrefix; @@ -151,6 +160,9 @@ describe('Utility', function () { expect(removeGitPrefix('http://github.com/18f')).not.toBe('18f'); }); + it("handles undefined", function(){ + expect(removeGitPrefix(undefinedProject)).toBe(undefined); + }); });