forked from zuriby/Faker.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to lorempixel image provider
- Loading branch information
1 parent
1bd1d73
commit 41688ef
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
var Faker = require('../index'); | ||
var imageProviderUrl = 'http://lorempixel.com/'; | ||
var image = { | ||
imageUrl: function (width, height, category) { | ||
var width = width || 640; | ||
var height = height || 480; | ||
|
||
var url = imageProviderUrl + width + '/' + height; | ||
if (typeof category !== 'undefined') { | ||
url += '/' + category; | ||
} | ||
|
||
return url; | ||
}, | ||
abstract: function (width, height) { | ||
return image.imageUrl(width, height, 'abstract'); | ||
}, | ||
animals: function(width, height) { | ||
return image.imageUrl(width, height, 'animals'); | ||
}, | ||
business: function(width, height) { | ||
return image.imageUrl(width, height, 'business'); | ||
}, | ||
cats: function(width, height) { | ||
return image.imageUrl(width, height, 'cats'); | ||
}, | ||
city: function(width, height) { | ||
return image.imageUrl(width, height, 'city'); | ||
}, | ||
food: function(width, height) { | ||
return image.imageUrl(width, height, 'food'); | ||
}, | ||
nightlife: function(width, height) { | ||
return image.imageUrl(width, height, 'nightlife'); | ||
}, | ||
fashion: function(width, height) { | ||
return image.imageUrl(width, height, 'fashion'); | ||
}, | ||
people: function(width, height) { | ||
return image.imageUrl(width, height, 'people'); | ||
}, | ||
nature: function(width, height) { | ||
return image.imageUrl(width, height, 'nature'); | ||
}, | ||
sports: function(width, height) { | ||
return image.imageUrl(width, height, 'sports'); | ||
}, | ||
technics: function(width, height) { | ||
return image.imageUrl(width, height, 'technics'); | ||
}, | ||
transport: function(width, height) { | ||
return image.imageUrl(width, height, 'transport'); | ||
} | ||
}; | ||
|
||
module.exports = image; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
if (typeof module !== 'undefined') { | ||
var assert = require('assert'); | ||
var sinon = require('sinon'); | ||
var Faker = require('../index'); | ||
} | ||
|
||
describe("image.js", function () { | ||
describe("imageUrl()", function () { | ||
it("returns a random image url from lorempixel", function () { | ||
var imageUrl = Faker.Image.imageUrl(); | ||
|
||
assert.equal(imageUrl, 'http://lorempixel.com/640/480'); | ||
}); | ||
it("returns a random image url from lorempixel with width and height", function () { | ||
var imageUrl = Faker.Image.imageUrl(100, 100); | ||
|
||
assert.equal(imageUrl, 'http://lorempixel.com/100/100'); | ||
}); | ||
it("returns a random image url in a abstract category", function () { | ||
var imageUrl = Faker.Image.imageUrl(100, 100, 'abstract'); | ||
|
||
assert.equal(imageUrl, 'http://lorempixel.com/100/100/abstract'); | ||
}); | ||
it("returns a random image url in a category via proxy methods", function () { | ||
var nightlife = Faker.Image.nightlife(); | ||
assert.equal(nightlife, 'http://lorempixel.com/640/480/nightlife'); | ||
|
||
var city = Faker.Image.city(); | ||
assert.equal(city, 'http://lorempixel.com/640/480/city'); | ||
|
||
var fashion = Faker.Image.fashion(); | ||
assert.equal(fashion, 'http://lorempixel.com/640/480/fashion'); | ||
}); | ||
}); | ||
}); |