1
1
import { describe , expect , it } from 'vitest' ;
2
2
import { faker } from '../dist/cjs' ;
3
+ import cat from '../dist/cjs/locales/en/animal/cat' ;
3
4
4
5
describe ( 'image' , ( ) => {
5
6
describe ( 'lorempicsum' , ( ) => {
6
7
describe ( 'imageUrl()' , ( ) => {
7
- it ( 'returns a random image url from lorempixel' , ( ) => {
8
+ it ( 'should return a random image url from lorempixel' , ( ) => {
8
9
const imageUrl = faker . image . lorempicsum . imageUrl ( ) ;
9
10
10
11
expect ( imageUrl ) . toBe ( 'https://picsum.photos/640/480' ) ;
11
12
} ) ;
12
13
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' , ( ) => {
14
15
const imageUrl = faker . image . lorempicsum . imageUrl ( 100 , 100 ) ;
15
16
16
17
expect ( imageUrl ) . toBe ( 'https://picsum.photos/100/100' ) ;
17
18
} ) ;
18
19
19
- it ( 'returns a random image url grayscaled' , ( ) => {
20
+ it ( 'should return a random image url grayscaled' , ( ) => {
20
21
const imageUrl = faker . image . lorempicsum . imageUrl ( 100 , 100 , true ) ;
21
22
22
23
expect ( imageUrl ) . toBe ( 'https://picsum.photos/100/100?grayscale' ) ;
23
24
} ) ;
24
25
25
- it ( 'returns a random image url grayscaled and blurred' , ( ) => {
26
+ it ( 'should return a random image url grayscaled and blurred' , ( ) => {
26
27
const imageUrl = faker . image . lorempicsum . imageUrl ( 100 , 100 , true , 2 ) ;
27
28
28
29
expect ( imageUrl ) . toBe ( 'https://picsum.photos/100/100?grayscale&blur=2' ) ;
29
30
} ) ;
30
31
31
- it ( 'returns a random image url blurred' , ( ) => {
32
+ it ( 'should return a random image url blurred' , ( ) => {
32
33
const imageUrl = faker . image . lorempicsum . imageUrl (
33
34
100 ,
34
35
100 ,
@@ -39,7 +40,7 @@ describe('image', () => {
39
40
expect ( imageUrl ) . toBe ( 'https://picsum.photos/100/100?blur=2' ) ;
40
41
} ) ;
41
42
42
- it ( 'returns a random image url with seed' , ( ) => {
43
+ it ( 'should return a random image url with seed' , ( ) => {
43
44
const imageUrl = faker . image . lorempicsum . imageUrl (
44
45
100 ,
45
46
100 ,
@@ -53,7 +54,7 @@ describe('image', () => {
53
54
} ) ;
54
55
55
56
describe ( 'avatar()' , ( ) => {
56
- it ( 'return a random avatar from cloudflare-ipfs' , ( ) => {
57
+ it ( 'should return a random avatar from cloudflare-ipfs' , ( ) => {
57
58
expect (
58
59
faker . image . lorempicsum
59
60
. avatar ( )
@@ -65,23 +66,23 @@ describe('image', () => {
65
66
} ) ;
66
67
67
68
describe ( 'imageGrayscale()' , ( ) => {
68
- it ( 'returns a random URL with grayscale image' , ( ) => {
69
+ it ( 'should return a random URL with grayscale image' , ( ) => {
69
70
const imageUrl = faker . image . lorempicsum . imageGrayscale ( 100 , 100 , true ) ;
70
71
71
72
expect ( imageUrl ) . toBe ( 'https://picsum.photos/100/100?grayscale' ) ;
72
73
} ) ;
73
74
} ) ;
74
75
75
76
describe ( 'imageBlurred()' , ( ) => {
76
- it ( 'returns a random image url blurred' , ( ) => {
77
+ it ( 'should return a random image url blurred' , ( ) => {
77
78
const imageUrl = faker . image . lorempicsum . imageBlurred ( 100 , 100 , 2 ) ;
78
79
79
80
expect ( imageUrl ) . toBe ( 'https://picsum.photos/100/100?blur=2' ) ;
80
81
} ) ;
81
82
} ) ;
82
83
83
84
describe ( 'imageRandomSeeded()' , ( ) => {
84
- it ( 'returns a random image url blurred' , ( ) => {
85
+ it ( 'should return a random image url blurred' , ( ) => {
85
86
const imageUrl = faker . image . lorempicsum . imageRandomSeeded (
86
87
100 ,
87
88
100 ,
@@ -97,27 +98,27 @@ describe('image', () => {
97
98
98
99
describe ( 'lorempixel' , ( ) => {
99
100
describe ( 'imageUrl()' , ( ) => {
100
- it ( 'returns a random image url from lorempixel' , ( ) => {
101
+ it ( 'should return a random image url from lorempixel' , ( ) => {
101
102
const imageUrl = faker . image . lorempixel . imageUrl ( ) ;
102
103
103
104
expect ( imageUrl ) . toBe ( 'https://lorempixel.com/640/480' ) ;
104
105
} ) ;
105
106
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' , ( ) => {
107
108
const imageUrl = faker . image . lorempixel . imageUrl ( 100 , 100 ) ;
108
109
109
110
expect ( imageUrl ) . toBe ( 'https://lorempixel.com/100/100' ) ;
110
111
} ) ;
111
112
112
- it ( 'returns a random image url for a specified category' , ( ) => {
113
+ it ( 'should return a random image url for a specified category' , ( ) => {
113
114
const imageUrl = faker . image . lorempixel . imageUrl ( 100 , 100 , 'abstract' ) ;
114
115
115
116
expect ( imageUrl ) . toBe ( 'https://lorempixel.com/100/100/abstract' ) ;
116
117
} ) ;
117
118
} ) ;
118
119
119
120
describe ( 'avatar()' , ( ) => {
120
- it ( 'return a random avatar from cloudflare-ipfs' , ( ) => {
121
+ it ( 'should return a random avatar from cloudflare-ipfs' , ( ) => {
121
122
expect (
122
123
faker . image . lorempixel
123
124
. avatar ( )
@@ -128,121 +129,55 @@ describe('image', () => {
128
129
} ) ;
129
130
} ) ;
130
131
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
+ }
221
156
} ) ;
222
157
223
158
describe ( 'unsplash' , ( ) => {
224
159
describe ( 'imageUrl()' , ( ) => {
225
- it ( 'returns a random image url from unsplash' , ( ) => {
160
+ it ( 'should return a random image url from unsplash' , ( ) => {
226
161
const imageUrl = faker . image . unsplash . imageUrl ( ) ;
227
162
228
163
expect ( imageUrl ) . toBe ( 'https://source.unsplash.com/640x480' ) ;
229
164
} ) ;
230
165
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' , ( ) => {
232
167
const imageUrl = faker . image . unsplash . imageUrl ( 100 , 100 ) ;
233
168
234
169
expect ( imageUrl ) . toBe ( 'https://source.unsplash.com/100x100' ) ;
235
170
} ) ;
236
171
237
- it ( 'returns a random image url for a specified category' , ( ) => {
172
+ it ( 'should return a random image url for a specified category' , ( ) => {
238
173
const imageUrl = faker . image . unsplash . imageUrl ( 100 , 100 , 'food' ) ;
239
174
240
175
expect ( imageUrl ) . toBe (
241
176
'https://source.unsplash.com/category/food/100x100'
242
177
) ;
243
178
} ) ;
244
179
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' , ( ) => {
246
181
const imageUrl = faker . image . unsplash . imageUrl (
247
182
100 ,
248
183
100 ,
@@ -255,7 +190,7 @@ describe('image', () => {
255
190
) ;
256
191
} ) ;
257
192
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' , ( ) => {
259
194
const imageUrl = faker . image . unsplash . imageUrl (
260
195
100 ,
261
196
100 ,
@@ -270,7 +205,7 @@ describe('image', () => {
270
205
} ) ;
271
206
272
207
describe ( 'image()' , ( ) => {
273
- it ( 'returns a searching image url with keyword' , ( ) => {
208
+ it ( 'should return a searching image url with keyword' , ( ) => {
274
209
const imageUrl = faker . image . unsplash . image (
275
210
100 ,
276
211
200 ,
@@ -282,68 +217,36 @@ describe('image', () => {
282
217
} ) ;
283
218
} ) ;
284
219
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
+ }
336
239
} ) ;
337
240
338
241
describe ( 'dataUri' , ( ) => {
339
- it ( 'returns a blank data' , ( ) => {
242
+ it ( 'should return a blank data' , ( ) => {
340
243
const dataUri = faker . image . dataUri ( 200 , 300 ) ;
341
244
expect ( dataUri ) . toBe (
342
245
'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'
343
246
) ;
344
247
} ) ;
345
248
346
- it ( 'returns a custom background color data URI' , ( ) => {
249
+ it ( 'should return a custom background color data URI' , ( ) => {
347
250
const dataUri = faker . image . dataUri ( 200 , 300 , 'red' ) ;
348
251
expect ( dataUri ) . toBe (
349
252
'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