Skip to content

Commit 06c6710

Browse files
committed
test: dynamically test image categories
1 parent 634ecc3 commit 06c6710

File tree

1 file changed

+66
-163
lines changed

1 file changed

+66
-163
lines changed

test/image.spec.ts

Lines changed: 66 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
import { describe, expect, it } from 'vitest';
22
import { faker } from '../dist/cjs';
3+
import cat from '../dist/cjs/locales/en/animal/cat';
34

45
describe('image', () => {
56
describe('lorempicsum', () => {
67
describe('imageUrl()', () => {
7-
it('returns a random image url from lorempixel', () => {
8+
it('should return a random image url from lorempixel', () => {
89
const imageUrl = faker.image.lorempicsum.imageUrl();
910

1011
expect(imageUrl).toBe('https://picsum.photos/640/480');
1112
});
1213

13-
it('returns a random image url from lorem picsum with width and height', () => {
14+
it('should return a random image url from lorem picsum with width and height', () => {
1415
const imageUrl = faker.image.lorempicsum.imageUrl(100, 100);
1516

1617
expect(imageUrl).toBe('https://picsum.photos/100/100');
1718
});
1819

19-
it('returns a random image url grayscaled', () => {
20+
it('should return a random image url grayscaled', () => {
2021
const imageUrl = faker.image.lorempicsum.imageUrl(100, 100, true);
2122

2223
expect(imageUrl).toBe('https://picsum.photos/100/100?grayscale');
2324
});
2425

25-
it('returns a random image url grayscaled and blurred', () => {
26+
it('should return a random image url grayscaled and blurred', () => {
2627
const imageUrl = faker.image.lorempicsum.imageUrl(100, 100, true, 2);
2728

2829
expect(imageUrl).toBe('https://picsum.photos/100/100?grayscale&blur=2');
2930
});
3031

31-
it('returns a random image url blurred', () => {
32+
it('should return a random image url blurred', () => {
3233
const imageUrl = faker.image.lorempicsum.imageUrl(
3334
100,
3435
100,
@@ -39,7 +40,7 @@ describe('image', () => {
3940
expect(imageUrl).toBe('https://picsum.photos/100/100?blur=2');
4041
});
4142

42-
it('returns a random image url with seed', () => {
43+
it('should return a random image url with seed', () => {
4344
const imageUrl = faker.image.lorempicsum.imageUrl(
4445
100,
4546
100,
@@ -53,7 +54,7 @@ describe('image', () => {
5354
});
5455

5556
describe('avatar()', () => {
56-
it('return a random avatar from cloudflare-ipfs', () => {
57+
it('should return a random avatar from cloudflare-ipfs', () => {
5758
expect(
5859
faker.image.lorempicsum
5960
.avatar()
@@ -65,23 +66,23 @@ describe('image', () => {
6566
});
6667

6768
describe('imageGrayscale()', () => {
68-
it('returns a random URL with grayscale image', () => {
69+
it('should return a random URL with grayscale image', () => {
6970
const imageUrl = faker.image.lorempicsum.imageGrayscale(100, 100, true);
7071

7172
expect(imageUrl).toBe('https://picsum.photos/100/100?grayscale');
7273
});
7374
});
7475

7576
describe('imageBlurred()', () => {
76-
it('returns a random image url blurred', () => {
77+
it('should return a random image url blurred', () => {
7778
const imageUrl = faker.image.lorempicsum.imageBlurred(100, 100, 2);
7879

7980
expect(imageUrl).toBe('https://picsum.photos/100/100?blur=2');
8081
});
8182
});
8283

8384
describe('imageRandomSeeded()', () => {
84-
it('returns a random image url blurred', () => {
85+
it('should return a random image url blurred', () => {
8586
const imageUrl = faker.image.lorempicsum.imageRandomSeeded(
8687
100,
8788
100,
@@ -97,27 +98,27 @@ describe('image', () => {
9798

9899
describe('lorempixel', () => {
99100
describe('imageUrl()', () => {
100-
it('returns a random image url from lorempixel', () => {
101+
it('should return a random image url from lorempixel', () => {
101102
const imageUrl = faker.image.lorempixel.imageUrl();
102103

103104
expect(imageUrl).toBe('https://lorempixel.com/640/480');
104105
});
105106

106-
it('returns a random image url from lorempixel with width and height', () => {
107+
it('should return a random image url from lorempixel with width and height', () => {
107108
const imageUrl = faker.image.lorempixel.imageUrl(100, 100);
108109

109110
expect(imageUrl).toBe('https://lorempixel.com/100/100');
110111
});
111112

112-
it('returns a random image url for a specified category', () => {
113+
it('should return a random image url for a specified category', () => {
113114
const imageUrl = faker.image.lorempixel.imageUrl(100, 100, 'abstract');
114115

115116
expect(imageUrl).toBe('https://lorempixel.com/100/100/abstract');
116117
});
117118
});
118119

119120
describe('avatar()', () => {
120-
it('return a random avatar from cloudflare-ipfs', () => {
121+
it('should return a random avatar from cloudflare-ipfs', () => {
121122
expect(
122123
faker.image.lorempixel
123124
.avatar()
@@ -128,121 +129,55 @@ describe('image', () => {
128129
});
129130
});
130131

131-
describe('abstract()', () => {
132-
it('returns a random abstract image url', () => {
133-
const abstract = faker.image.lorempixel.abstract();
134-
expect(abstract).toBe('https://lorempixel.com/640/480/abstract');
135-
});
136-
});
137-
138-
describe('animals()', () => {
139-
it('returns a random animals image url', () => {
140-
const animals = faker.image.lorempixel.animals();
141-
expect(animals).toBe('https://lorempixel.com/640/480/animals');
142-
});
143-
});
144-
145-
describe('business()', () => {
146-
it('returns a random business image url', () => {
147-
const business = faker.image.lorempixel.business();
148-
expect(business).toBe('https://lorempixel.com/640/480/business');
149-
});
150-
});
151-
152-
describe('cats()', () => {
153-
it('returns a random cats image url', () => {
154-
const cats = faker.image.lorempixel.cats();
155-
expect(cats).toBe('https://lorempixel.com/640/480/cats');
156-
});
157-
});
158-
159-
describe('city()', () => {
160-
it('returns a random city image url', () => {
161-
const city = faker.image.lorempixel.city();
162-
expect(city).toBe('https://lorempixel.com/640/480/city');
163-
});
164-
});
165-
166-
describe('food()', () => {
167-
it('returns a random food image url', () => {
168-
const food = faker.image.lorempixel.food();
169-
expect(food).toBe('https://lorempixel.com/640/480/food');
170-
});
171-
});
172-
173-
describe('nightlife()', () => {
174-
it('returns a random nightlife image url', () => {
175-
const nightlife = faker.image.lorempixel.nightlife();
176-
expect(nightlife).toBe('https://lorempixel.com/640/480/nightlife');
177-
});
178-
});
179-
180-
describe('fashion()', () => {
181-
it('returns a random fashion image url', () => {
182-
const fashion = faker.image.lorempixel.fashion();
183-
expect(fashion).toBe('https://lorempixel.com/640/480/fashion');
184-
});
185-
});
186-
187-
describe('people()', () => {
188-
it('returns a random people image url', () => {
189-
const people = faker.image.lorempixel.people();
190-
expect(people).toBe('https://lorempixel.com/640/480/people');
191-
});
192-
});
193-
194-
describe('nature()', () => {
195-
it('returns a random nature image url', () => {
196-
const nature = faker.image.lorempixel.nature();
197-
expect(nature).toBe('https://lorempixel.com/640/480/nature');
198-
});
199-
});
200-
201-
describe('sports()', () => {
202-
it('returns a random sports image url', () => {
203-
const sports = faker.image.lorempixel.sports();
204-
expect(sports).toBe('https://lorempixel.com/640/480/sports');
205-
});
206-
});
207-
208-
describe('technics()', () => {
209-
it('returns a random technics image url', () => {
210-
const technics = faker.image.lorempixel.technics();
211-
expect(technics).toBe('https://lorempixel.com/640/480/technics');
212-
});
213-
});
214-
215-
describe('transport()', () => {
216-
it('returns a random transport image url', () => {
217-
const transport = faker.image.lorempixel.transport();
218-
expect(transport).toBe('https://lorempixel.com/640/480/transport');
219-
});
220-
});
132+
const categories = [
133+
'abstract',
134+
'animals',
135+
'business',
136+
'cats',
137+
'city',
138+
'food',
139+
'nightlife',
140+
'fashion',
141+
'people',
142+
'nature',
143+
'sports',
144+
'technics',
145+
'transport',
146+
];
147+
148+
for (const category of categories) {
149+
describe(`${category}()`, () => {
150+
it(`should return a random ${category} image url`, () => {
151+
const actual = faker.image.lorempixel[category]();
152+
expect(actual).toBe(`https://lorempixel.com/640/480/${category}`);
153+
});
154+
});
155+
}
221156
});
222157

223158
describe('unsplash', () => {
224159
describe('imageUrl()', () => {
225-
it('returns a random image url from unsplash', () => {
160+
it('should return a random image url from unsplash', () => {
226161
const imageUrl = faker.image.unsplash.imageUrl();
227162

228163
expect(imageUrl).toBe('https://source.unsplash.com/640x480');
229164
});
230165

231-
it('returns a random image url from unsplash with width and height', () => {
166+
it('should return a random image url from unsplash with width and height', () => {
232167
const imageUrl = faker.image.unsplash.imageUrl(100, 100);
233168

234169
expect(imageUrl).toBe('https://source.unsplash.com/100x100');
235170
});
236171

237-
it('returns a random image url for a specified category', () => {
172+
it('should return a random image url for a specified category', () => {
238173
const imageUrl = faker.image.unsplash.imageUrl(100, 100, 'food');
239174

240175
expect(imageUrl).toBe(
241176
'https://source.unsplash.com/category/food/100x100'
242177
);
243178
});
244179

245-
it('returns a random image url with correct keywords for a specified category', () => {
180+
it('should return a random image url with correct keywords for a specified category', () => {
246181
const imageUrl = faker.image.unsplash.imageUrl(
247182
100,
248183
100,
@@ -255,7 +190,7 @@ describe('image', () => {
255190
);
256191
});
257192

258-
it('returns a random image url without keyword which format is wrong for a specified category', () => {
193+
it('should return a random image url without keyword which format is wrong for a specified category', () => {
259194
const imageUrl = faker.image.unsplash.imageUrl(
260195
100,
261196
100,
@@ -270,7 +205,7 @@ describe('image', () => {
270205
});
271206

272207
describe('image()', () => {
273-
it('returns a searching image url with keyword', () => {
208+
it('should return a searching image url with keyword', () => {
274209
const imageUrl = faker.image.unsplash.image(
275210
100,
276211
200,
@@ -282,68 +217,36 @@ describe('image', () => {
282217
});
283218
});
284219

285-
describe('food()', () => {
286-
it('returns a random food image url', () => {
287-
const food = faker.image.unsplash.food();
288-
expect(food).toBe('https://source.unsplash.com/category/food/640x480');
289-
});
290-
});
291-
292-
describe('people()', () => {
293-
it('returns a random people image url', () => {
294-
const people = faker.image.unsplash.people();
295-
expect(people).toBe(
296-
'https://source.unsplash.com/category/people/640x480'
297-
);
298-
});
299-
});
300-
301-
describe('nature()', () => {
302-
it('returns a random nature image url', () => {
303-
const nature = faker.image.unsplash.nature();
304-
expect(nature).toBe(
305-
'https://source.unsplash.com/category/nature/640x480'
306-
);
307-
});
308-
});
309-
310-
describe('technology()', () => {
311-
it('returns a random technology image url', () => {
312-
const technology = faker.image.unsplash.technology();
313-
expect(technology).toBe(
314-
'https://source.unsplash.com/category/technology/640x480'
315-
);
316-
});
317-
});
318-
319-
describe('objects()', () => {
320-
it('returns a random objects image url', () => {
321-
const objects = faker.image.unsplash.objects();
322-
expect(objects).toBe(
323-
'https://source.unsplash.com/category/objects/640x480'
324-
);
325-
});
326-
});
327-
328-
describe('buildings()', () => {
329-
it('returns a random buildings image url', () => {
330-
const buildings = faker.image.unsplash.buildings();
331-
expect(buildings).toBe(
332-
'https://source.unsplash.com/category/buildings/640x480'
333-
);
334-
});
335-
});
220+
const categories = [
221+
'buildings',
222+
'food',
223+
'nature',
224+
'objects',
225+
'people',
226+
'technology',
227+
];
228+
229+
for (const category of categories) {
230+
describe(`${category}()`, () => {
231+
it(`should return a random ${category} image url`, () => {
232+
const actual = faker.image.unsplash[category]();
233+
expect(actual).toBe(
234+
`https://source.unsplash.com/category/${category}/640x480`
235+
);
236+
});
237+
});
238+
}
336239
});
337240

338241
describe('dataUri', () => {
339-
it('returns a blank data', () => {
242+
it('should return a blank data', () => {
340243
const dataUri = faker.image.dataUri(200, 300);
341244
expect(dataUri).toBe(
342245
'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'
343246
);
344247
});
345248

346-
it('returns a custom background color data URI', () => {
249+
it('should return a custom background color data URI', () => {
347250
const dataUri = faker.image.dataUri(200, 300, 'red');
348251
expect(dataUri).toBe(
349252
'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'

0 commit comments

Comments
 (0)