Skip to content
This repository has been archived by the owner on Jul 30, 2019. It is now read-only.

[WIP] Add jasmine to travis #636

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Rakefile
Expand Up @@ -9,3 +9,5 @@ if Rails.env.development?
end

Rails.application.load_tasks

task default: 'jasmine:ci'
14 changes: 10 additions & 4 deletions app/assets/javascripts/utility.js
Expand Up @@ -46,11 +46,13 @@
};

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;
};

Expand Down Expand Up @@ -78,6 +80,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') {
Expand Down
10 changes: 10 additions & 0 deletions app/assets/javascripts/winners/charts.js
Expand Up @@ -227,6 +227,16 @@
}
},
create: {
// Creates a scatterplot with a connecting sparkline
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally prefer clear code over code comments because inevitably someone will change the code without updating the codes. Any way we could update this js to make it clearer / mitigate need for code comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the names need some refactoring. It feels quite a bit outside the scope of this PR. Why don't I just remove the comment for now, and create a naming issue for later refactoring?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that works for me!

// Outputs 4 columns: [['bids_dates'], ['bids'], ['means_dates'],['means']]
// bids_dates: a list of dates that an auction occurred. There may be multiple
// of the same date if multiple auctions occurred on that day.
// bids: a list of corresponding winning bids. The index corresponds to
// the date with the same index in `bids_dates`.
// means_dates: a list of dates for the mean winning bid. There should only be
// one of each date.
// means: a list of mean winning bids. Matches a date of the same index
// in `means_dates`.
chart2: function chart2 (auctions) {
var settings = {};

Expand Down
8 changes: 6 additions & 2 deletions app/assets/javascripts/winners/metrics.js
Expand Up @@ -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);
},

Expand Down
4 changes: 3 additions & 1 deletion app/assets/javascripts/winners/previousWinners.js
Expand Up @@ -6,7 +6,9 @@
window.winners = {
onReady: function(){
// Retrieve data
$.getJSON('/auctions.json').success(function(data){
var MP = 'https://micropurchase.18f.gov/auctions.json'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we name this something more expressive than MP ? AUCTION_DATA perhaps?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, that data is on prod now but was removed at 32bafd1 so it won't be on prod once we do our next deploy -- can we use the actual API endpoint instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops. I just added this for dev purposes. Forgot to remove.

var relative = '/auctions.json'
$.getJSON(MP).success(function(data){
var auctions = _.sortBy(data.auctions, 'id');

window.winners.metrics = new Metrics(auctions);
Expand Down
4 changes: 2 additions & 2 deletions spec/javascripts/helpers/auctionsMock.js
Expand Up @@ -65,8 +65,8 @@ var auctionsMock = {
"description":"clever description 2",
"id":22,
"winning_bid": {
"amount": null,
"bidder_id": null
"amount": 3200,
"bidder_id": 30
},
"bids":[
{
Expand Down
19 changes: 12 additions & 7 deletions spec/javascripts/previous_winners_spec.js
Expand Up @@ -83,7 +83,7 @@ describe('PreviousWinners', function () {

it("with 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(){
Expand Down Expand Up @@ -145,7 +145,8 @@ describe('PreviousWinners', function () {
["ruby",2],
["python",2],
["yml",1],
[]
[],
["go",1]
]
}
})
Expand All @@ -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]
]
}
})
Expand Down Expand Up @@ -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"
}
}
Expand Down
8 changes: 8 additions & 0 deletions spec/javascripts/utility_spec.js
Expand Up @@ -11,12 +11,15 @@ 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(){
Expand All @@ -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');
Expand All @@ -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');
Expand Down