This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// photo-lister.js | |
PhotoLister = { | |
photoToListItem: function(photo) { | |
return ( | |
'<li><figure><img src="' + | |
photo.url + | |
'" alt=""/>' + | |
"<figcaption>" + | |
photo.title + | |
"</figcaption></figure></li>" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// photo-lister-spec.js | |
describe("#photoToListItem()", function() { | |
it("should take a photo object and return a list item string", function() { | |
var input = { | |
title: "This is a test", | |
url: "http://loremflickr.com/960/593", | |
}, | |
expected = | |
'<li><figure><img src="http://loremflickr.com/960/593" alt=""/>' + | |
"<figcaption>This is a test</figcaption></figure></li>"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// photo-lister.js | |
PhotoLister = { | |
photoToListItem: function() { | |
return ( | |
'<li><figure><img src="http://loremflickr.com/960/593" alt=""/>' + | |
"<figcaption>This is a test</figcaption></figure></li>" | |
); | |
}, | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// photo-lister.js | |
var PhotoLister; | |
PhotoLister = { | |
photoToListItem: function() {} | |
}; | |
module.exports = PhotoLister; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// photo-lister-spec.js | |
describe("#photoToListItem()", function() { | |
it("should take a photo object and return a list item string", function() { | |
var input = { | |
title: "This is a test", | |
url: "http://loremflickr.com/960/593", | |
}, | |
expected = | |
'<li><figure><img src="http://loremflickr.com/960/593" alt=""/>' + | |
"<figcaption>This is a test</figcaption></figure></li>"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// photo-lister-spec.js | |
var expect = require("chai").expect, | |
PhotoLister = require("./photo-lister"); | |
describe("PhotoLister", function() { | |
it("should exist", function() { | |
expect(PhotoLister).not.to.be.undefined; | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// flickr-fetcher-spec.js | |
describe("#fetchFlickrData()", function() { | |
it("should take an API key and fetcher function argument and return a promise for JSON data.", function() { | |
var apiKey = "does not matter much what this is right now", | |
fakeData = { | |
photos: { | |
page: 1, | |
pages: 2872, | |
perpage: 100, | |
total: "287170", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetchPhotos: function(apiKey, fetch) { | |
return FlickrFetcher.fetchFlickrData(apiKey, fetch).then(function(data) { | |
return data.photos.photo.map(FlickrFetcher.transformPhotoObj); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe("#fetchPhotos()", function() { | |
it("should take an API key and fetcher function, and return a promise for transformed photos", function() { | |
var apiKey = "does not matter what this is right now", | |
expected = [ | |
{ | |
title: "Dog goes to desperate measure to avoid walking on a leash", | |
url: | |
"https://farm2.staticflickr.com/1669/25373736106_146731fcb7_b.jpg", | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// flickr-fetcher.js | |
fetchFlickrData: function(apiKey, fetch) { | |
var url = 'https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=' | |
+ apiKey + '&text=pugs&format=json&nojsoncallback=1' | |
return fetch(url); | |
} |