Socialify

Folder ..

Viewing image.spec.ts
349 lines (295 loc) • 11.5 KB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
import { describe, expect, it } from 'vitest';
import { faker } from '../dist/cjs';

describe('image', () => {
  describe('lorempicsum', () => {
    describe('imageUrl()', () => {
      it('returns 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', () => {
        const imageUrl = faker.image.lorempicsum.imageUrl(100, 100);

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

      it('returns 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', () => {
        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', () => {
        const imageUrl = faker.image.lorempicsum.imageUrl(
          100,
          100,
          undefined,
          2
        );

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

      it('returns a random image url with seed', () => {
        const imageUrl = faker.image.lorempicsum.imageUrl(
          100,
          100,
          undefined,
          undefined,
          'picsum'
        );

        expect(imageUrl).toBe('https://picsum.photos/seed/picsum/100/100');
      });
    });

    describe('avatar()', () => {
      it('return a random avatar from cloudflare-ipfs', () => {
        expect(
          faker.image.lorempicsum
            .avatar()
            .includes(
              'cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar'
            )
        ).toBeTruthy();
      });
    });

    describe('imageGrayscale()', () => {
      it('returns a random URL with grayscale image', () => {
        const imageUrl = faker.image.lorempicsum.imageGrayscale(100, 100, true);

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

    describe('imageBlurred()', () => {
      it('returns a random image url blurred', () => {
        const imageUrl = faker.image.lorempicsum.imageBlurred(100, 100, 2);

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

    describe('imageRandomSeeded()', () => {
      it('returns a random image url blurred', () => {
        const imageUrl = faker.image.lorempicsum.imageRandomSeeded(
          100,
          100,
          undefined,
          undefined,
          'picsum'
        );

        expect(imageUrl).toBe('https://picsum.photos/seed/picsum/100/100');
      });
    });
  });

  describe('lorempixel', () => {
    describe('imageUrl()', () => {
      it('returns 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', () => {
        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', () => {
        const imageUrl = faker.image.lorempixel.imageUrl(100, 100, 'abstract');

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

    describe('avatar()', () => {
      it('return a random avatar from cloudflare-ipfs', () => {
        expect(
          faker.image.lorempixel
            .avatar()
            .includes(
              'cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar'
            )
        ).toBeTruthy();
      });
    });

    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');
      });
    });
  });

  describe('unsplash', () => {
    describe('imageUrl()', () => {
      it('returns 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', () => {
        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', () => {
        const imageUrl = faker.image.unsplash.imageUrl(100, 100, 'food');

        expect(imageUrl).toBe(
          'https://source.unsplash.com/category/food/100x100'
        );
      });

      it('returns a random image url with correct keywords for a specified category', () => {
        const imageUrl = faker.image.unsplash.imageUrl(
          100,
          100,
          'food',
          'keyword1,keyword2'
        );

        expect(imageUrl).toBe(
          'https://source.unsplash.com/category/food/100x100?keyword1,keyword2'
        );
      });

      it('returns a random image url without keyword which format is wrong for a specified category', () => {
        const imageUrl = faker.image.unsplash.imageUrl(
          100,
          100,
          'food',
          'keyword1,?ds)0123$*908932409'
        );

        expect(imageUrl).toBe(
          'https://source.unsplash.com/category/food/100x100'
        );
      });
    });

    describe('image()', () => {
      it('returns a searching image url with keyword', () => {
        const food = faker.image.unsplash.image(
          100,
          200,
          'keyword1,keyword2,keyword3'
        );
        expect(food).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');
      });
    });

    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'
        );
      });
    });

    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', () => {
      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', () => {
      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'
      );
    });
  });
});