diff options
| author | Shinigami <[email protected]> | 2022-02-10 21:19:11 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-02-10 21:19:11 +0100 |
| commit | 28048864d064b63efe3965d5d09a4a2ca401319b (patch) | |
| tree | 87a5e5d52bcb34ad2f8bbffa0800564e8b83f70a | |
| parent | 4b5afb3878b712e08df178aaa6b9c78302399749 (diff) | |
| download | faker-28048864d064b63efe3965d5d09a4a2ca401319b.tar.xz faker-28048864d064b63efe3965d5d09a4a2ca401319b.zip | |
test: rewrite image tests (#414)
| -rw-r--r-- | test/image.spec.ts | 228 |
1 files changed, 67 insertions, 161 deletions
diff --git a/test/image.spec.ts b/test/image.spec.ts index 41e46512..bbb99ffa 100644 --- a/test/image.spec.ts +++ b/test/image.spec.ts @@ -4,31 +4,31 @@ import { faker } from '../src'; describe('image', () => { describe('lorempicsum', () => { describe('imageUrl()', () => { - it('returns a random image url from lorempixel', () => { + it('should return a random image url from lorempixel', () => { const imageUrl = faker.image.lorempicsum.imageUrl(); expect(imageUrl).toBe('https://picsum.photos/640/480'); }); - it('returns a random image url from lorem picsum with width and height', () => { + it('should return a random image url from lorem picsum with width and height', () => { const imageUrl = faker.image.lorempicsum.imageUrl(100, 100); expect(imageUrl).toBe('https://picsum.photos/100/100'); }); - it('returns a random image url grayscaled', () => { + it('should return a random image url grayscaled', () => { const imageUrl = faker.image.lorempicsum.imageUrl(100, 100, true); expect(imageUrl).toBe('https://picsum.photos/100/100?grayscale'); }); - it('returns a random image url grayscaled and blurred', () => { + it('should return a random image url grayscaled and blurred', () => { const imageUrl = faker.image.lorempicsum.imageUrl(100, 100, true, 2); expect(imageUrl).toBe('https://picsum.photos/100/100?grayscale&blur=2'); }); - it('returns a random image url blurred', () => { + it('should return a random image url blurred', () => { const imageUrl = faker.image.lorempicsum.imageUrl( 100, 100, @@ -39,7 +39,7 @@ describe('image', () => { expect(imageUrl).toBe('https://picsum.photos/100/100?blur=2'); }); - it('returns a random image url with seed', () => { + it('should return a random image url with seed', () => { const imageUrl = faker.image.lorempicsum.imageUrl( 100, 100, @@ -53,7 +53,7 @@ describe('image', () => { }); describe('avatar()', () => { - it('return a random avatar from cloudflare-ipfs', () => { + it('should return a random avatar from cloudflare-ipfs', () => { expect( faker.image.lorempicsum .avatar() @@ -65,7 +65,7 @@ describe('image', () => { }); describe('imageGrayscale()', () => { - it('returns a random URL with grayscale image', () => { + it('should return a random URL with grayscale image', () => { const imageUrl = faker.image.lorempicsum.imageGrayscale(100, 100, true); expect(imageUrl).toBe('https://picsum.photos/100/100?grayscale'); @@ -73,7 +73,7 @@ describe('image', () => { }); describe('imageBlurred()', () => { - it('returns a random image url blurred', () => { + it('should return a random image url blurred', () => { const imageUrl = faker.image.lorempicsum.imageBlurred(100, 100, 2); expect(imageUrl).toBe('https://picsum.photos/100/100?blur=2'); @@ -81,7 +81,7 @@ describe('image', () => { }); describe('imageRandomSeeded()', () => { - it('returns a random image url blurred', () => { + it('should return a random image url blurred', () => { const imageUrl = faker.image.lorempicsum.imageRandomSeeded( 100, 100, @@ -97,19 +97,19 @@ describe('image', () => { describe('lorempixel', () => { describe('imageUrl()', () => { - it('returns a random image url from lorempixel', () => { + it('should return a random image url from lorempixel', () => { const imageUrl = faker.image.lorempixel.imageUrl(); expect(imageUrl).toBe('https://lorempixel.com/640/480'); }); - it('returns a random image url from lorempixel with width and height', () => { + it('should return a random image url from lorempixel with width and height', () => { const imageUrl = faker.image.lorempixel.imageUrl(100, 100); expect(imageUrl).toBe('https://lorempixel.com/100/100'); }); - it('returns a random image url for a specified category', () => { + it('should return a random image url for a specified category', () => { const imageUrl = faker.image.lorempixel.imageUrl(100, 100, 'abstract'); expect(imageUrl).toBe('https://lorempixel.com/100/100/abstract'); @@ -117,7 +117,7 @@ describe('image', () => { }); describe('avatar()', () => { - it('return a random avatar from cloudflare-ipfs', () => { + it('should return a random avatar from cloudflare-ipfs', () => { expect( faker.image.lorempixel .avatar() @@ -128,113 +128,47 @@ describe('image', () => { }); }); - describe('abstract()', () => { - it('returns a random abstract image url', () => { - const abstract = faker.image.lorempixel.abstract(); - expect(abstract).toBe('https://lorempixel.com/640/480/abstract'); - }); - }); - - describe('animals()', () => { - it('returns a random animals image url', () => { - const animals = faker.image.lorempixel.animals(); - expect(animals).toBe('https://lorempixel.com/640/480/animals'); - }); - }); - - describe('business()', () => { - it('returns a random business image url', () => { - const business = faker.image.lorempixel.business(); - expect(business).toBe('https://lorempixel.com/640/480/business'); - }); - }); - - describe('cats()', () => { - it('returns a random cats image url', () => { - const cats = faker.image.lorempixel.cats(); - expect(cats).toBe('https://lorempixel.com/640/480/cats'); - }); - }); - - describe('city()', () => { - it('returns a random city image url', () => { - const city = faker.image.lorempixel.city(); - expect(city).toBe('https://lorempixel.com/640/480/city'); - }); - }); - - describe('food()', () => { - it('returns a random food image url', () => { - const food = faker.image.lorempixel.food(); - expect(food).toBe('https://lorempixel.com/640/480/food'); - }); - }); - - describe('nightlife()', () => { - it('returns a random nightlife image url', () => { - const nightlife = faker.image.lorempixel.nightlife(); - expect(nightlife).toBe('https://lorempixel.com/640/480/nightlife'); - }); - }); - - describe('fashion()', () => { - it('returns a random fashion image url', () => { - const fashion = faker.image.lorempixel.fashion(); - expect(fashion).toBe('https://lorempixel.com/640/480/fashion'); - }); - }); - - describe('people()', () => { - it('returns a random people image url', () => { - const people = faker.image.lorempixel.people(); - expect(people).toBe('https://lorempixel.com/640/480/people'); - }); - }); - - describe('nature()', () => { - it('returns a random nature image url', () => { - const nature = faker.image.lorempixel.nature(); - expect(nature).toBe('https://lorempixel.com/640/480/nature'); - }); - }); - - describe('sports()', () => { - it('returns a random sports image url', () => { - const sports = faker.image.lorempixel.sports(); - expect(sports).toBe('https://lorempixel.com/640/480/sports'); - }); - }); - - describe('technics()', () => { - it('returns a random technics image url', () => { - const technics = faker.image.lorempixel.technics(); - expect(technics).toBe('https://lorempixel.com/640/480/technics'); - }); - }); - - describe('transport()', () => { - it('returns a random transport image url', () => { - const transport = faker.image.lorempixel.transport(); - expect(transport).toBe('https://lorempixel.com/640/480/transport'); - }); - }); + const categories = [ + 'abstract', + 'animals', + 'business', + 'cats', + 'city', + 'food', + 'nightlife', + 'fashion', + 'people', + 'nature', + 'sports', + 'technics', + 'transport', + ]; + + for (const category of categories) { + describe(`${category}()`, () => { + it(`should return a random ${category} image url`, () => { + const actual = faker.image.lorempixel[category](); + expect(actual).toBe(`https://lorempixel.com/640/480/${category}`); + }); + }); + } }); describe('unsplash', () => { describe('imageUrl()', () => { - it('returns a random image url from unsplash', () => { + it('should return a random image url from unsplash', () => { const imageUrl = faker.image.unsplash.imageUrl(); expect(imageUrl).toBe('https://source.unsplash.com/640x480'); }); - it('returns a random image url from unsplash with width and height', () => { + it('should return a random image url from unsplash with width and height', () => { const imageUrl = faker.image.unsplash.imageUrl(100, 100); expect(imageUrl).toBe('https://source.unsplash.com/100x100'); }); - it('returns a random image url for a specified category', () => { + it('should return a random image url for a specified category', () => { const imageUrl = faker.image.unsplash.imageUrl(100, 100, 'food'); expect(imageUrl).toBe( @@ -242,7 +176,7 @@ describe('image', () => { ); }); - it('returns a random image url with correct keywords for a specified category', () => { + it('should return a random image url with correct keywords for a specified category', () => { const imageUrl = faker.image.unsplash.imageUrl( 100, 100, @@ -255,7 +189,7 @@ describe('image', () => { ); }); - it('returns a random image url without keyword which format is wrong for a specified category', () => { + it('should return a random image url without keyword which format is wrong for a specified category', () => { const imageUrl = faker.image.unsplash.imageUrl( 100, 100, @@ -270,76 +204,48 @@ describe('image', () => { }); describe('image()', () => { - it('returns a searching image url with keyword', () => { - const food = faker.image.unsplash.image( + it('should return a searching image url with keyword', () => { + const imageUrl = faker.image.unsplash.image( 100, 200, 'keyword1,keyword2,keyword3' ); - expect(food).toBe( + expect(imageUrl).toBe( 'https://source.unsplash.com/100x200?keyword1,keyword2,keyword3' ); }); }); - describe('food()', () => { - it('returns a random food image url', () => { - const food = faker.image.unsplash.food(); - expect(food).toBe('https://source.unsplash.com/category/food/640x480'); - }); - }); + const categories = [ + 'buildings', + 'food', + 'nature', + 'objects', + 'people', + 'technology', + ]; - describe('people()', () => { - it('returns a random people image url', () => { - const people = faker.image.unsplash.people(); - expect(people).toBe( - 'https://source.unsplash.com/category/people/640x480' - ); + for (const category of categories) { + describe(`${category}()`, () => { + it(`should return a random ${category} image url`, () => { + const actual = faker.image.unsplash[category](); + expect(actual).toBe( + `https://source.unsplash.com/category/${category}/640x480` + ); + }); }); - }); - - describe('nature()', () => { - it('returns a random nature image url', () => { - const nature = faker.image.unsplash.nature(); - expect(nature).toBe( - 'https://source.unsplash.com/category/nature/640x480' - ); - }); - }); - - describe('technology()', () => { - it('returns a random technology image url', () => { - const transport = faker.image.unsplash.technology(); - expect(transport).toBe( - 'https://source.unsplash.com/category/technology/640x480' - ); - }); - }); - describe('objects()', () => { - it('returns a random objects image url', () => { - const transport = faker.image.unsplash.objects(); - expect(transport).toBe( - 'https://source.unsplash.com/category/objects/640x480' - ); - }); - }); - describe('buildings()', () => { - it('returns a random buildings image url', () => { - const transport = faker.image.unsplash.buildings(); - expect(transport).toBe( - 'https://source.unsplash.com/category/buildings/640x480' - ); - }); - }); + } }); + describe('dataUri', () => { - it('returns a blank data', () => { + it('should return a blank data', () => { const dataUri = faker.image.dataUri(200, 300); expect(dataUri).toBe( 'data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20version%3D%221.1%22%20baseProfile%3D%22full%22%20width%3D%22200%22%20height%3D%22300%22%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22grey%22%2F%3E%3Ctext%20x%3D%22100%22%20y%3D%22150%22%20font-size%3D%2220%22%20alignment-baseline%3D%22middle%22%20text-anchor%3D%22middle%22%20fill%3D%22white%22%3E200x300%3C%2Ftext%3E%3C%2Fsvg%3E' ); }); - it('returns a customed background color data URI', () => { + + it('should return a custom background color data URI', () => { const dataUri = faker.image.dataUri(200, 300, 'red'); expect(dataUri).toBe( 'data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20version%3D%221.1%22%20baseProfile%3D%22full%22%20width%3D%22200%22%20height%3D%22300%22%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22red%22%2F%3E%3Ctext%20x%3D%22100%22%20y%3D%22150%22%20font-size%3D%2220%22%20alignment-baseline%3D%22middle%22%20text-anchor%3D%22middle%22%20fill%3D%22white%22%3E200x300%3C%2Ftext%3E%3C%2Fsvg%3E' |
