forked from bigcommerce/stencil-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.image.spec.js
63 lines (51 loc) · 2.27 KB
/
tools.image.spec.js
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
import tools from '../src/tools';
describe('tools.image', () => {
test('should return a src if a valid image and size is passed (inherent width string)', () => {
const expected = 'https://cdn.example.com/path/to/100w/image.png?c=2';
const actual = tools.image.getSrc(
'https://cdn.example.com/path/to/{:size}/image.png?c=2',
'100w',
);
expect(actual).toEqual(expected);
});
test('should return a src if a valid image and size is passed (pixel size string)', () => {
const expected = 'https://cdn.example.com/path/to/100x100/image.png?c=2';
const actual = tools.image.getSrc(
'https://cdn.example.com/path/to/{:size}/image.png?c=2',
'100x100',
);
expect(actual).toEqual(expected);
});
test('should return a src if a valid image and size is passed (pixel size object)', () => {
const expected = 'https://cdn.example.com/path/to/123x123/image.png?c=2';
const actual = tools.image.getSrc(
'https://cdn.example.com/path/to/{:size}/image.png?c=2',
{ width: 123, height: 123 },
);
expect(actual).toEqual(expected);
});
test('should return a src 100px wide if width is missing (pixel size object)', () => {
const expected = 'https://cdn.example.com/path/to/100x123/image.png?c=2';
const actual = tools.image.getSrc(
'https://cdn.example.com/path/to/{:size}/image.png?c=2',
{ height: 123 },
);
expect(actual).toEqual(expected);
});
test('should return a src 100px high if height is missing (pixel size object)', () => {
const expected = 'https://cdn.example.com/path/to/123x100/image.png?c=2';
const actual = tools.image.getSrc(
'https://cdn.example.com/path/to/{:size}/image.png?c=2',
{ width: 123 },
);
expect(actual).toEqual(expected);
});
test('should return the original image if an invalid size is passed', () => {
const expected = 'https://cdn.example.com/path/to/original/image.png?c=2';
const actual = tools.image.getSrc(
'https://cdn.example.com/path/to/{:size}/image.png?c=2',
'100',
);
expect(actual).toEqual(expected);
});
});