Skip to content

Commit 0421b35

Browse files
author
Nir Maoz
authored
Refactor toJson tests (#467)
1 parent 33b31b8 commit 0421b35

File tree

3 files changed

+263
-258
lines changed

3 files changed

+263
-258
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import {Transformation} from '../../../src';
2+
import {Delivery} from "../../../src/actions";
3+
import {ChromaSubSampling, ColorSpace, Format, Quality} from "../../../src/qualifiers";
4+
import {Progressive} from "../../../src/qualifiers/progressive";
5+
6+
describe('Delivery.toJson()', () => {
7+
it('delivery.colorSpace', () => {
8+
const transformation = new Transformation()
9+
.addAction(Delivery.colorSpace(ColorSpace.trueColor()));
10+
expect(transformation.toJson()).toStrictEqual(
11+
[
12+
{
13+
actionType: 'colorSpace',
14+
mode: 'srgbTrueColor'
15+
}
16+
]
17+
);
18+
});
19+
20+
it('delivery.dpr', () => {
21+
const transformation = new Transformation()
22+
.addAction(Delivery.dpr('auto'));
23+
expect(transformation.toJson()).toStrictEqual([
24+
{
25+
actionType: 'dpr',
26+
type: 'auto'
27+
}
28+
]);
29+
});
30+
31+
it('delivery.colorSpaceFromICC', () => {
32+
const transformation = new Transformation()
33+
.addAction(Delivery.colorSpaceFromICC('sample'));
34+
expect(transformation.toJson()).toStrictEqual([
35+
{
36+
actionType: 'colorSpaceFromICC',
37+
publicId: 'sample'
38+
}
39+
]);
40+
});
41+
42+
it('delivery.density', () => {
43+
const transformation = new Transformation()
44+
.addAction(Delivery.density(1));
45+
expect(transformation.toJson()).toStrictEqual([
46+
{
47+
actionType: 'density',
48+
density: 1
49+
}
50+
]);
51+
});
52+
53+
it('jpg.progressive.semi()', () => {
54+
const transformation = new Transformation()
55+
.addAction(Delivery.format(Format.jpg()).progressive(Progressive.semi()));
56+
expect(transformation.toJson()).toStrictEqual([
57+
{
58+
progressive: { mode: 'semi' },
59+
actionType: 'format',
60+
formatType: 'jpg'
61+
}
62+
]);
63+
});
64+
65+
it('jpg.progressive.semi()', () => {
66+
const transformation = new Transformation()
67+
.addAction(Delivery.format(Format.jpg()).progressive('semi'));
68+
expect(transformation.toJson()).toStrictEqual([
69+
{
70+
progressive: { mode: 'semi' },
71+
actionType: 'format',
72+
formatType: 'jpg'
73+
}
74+
]);
75+
});
76+
77+
it('gif.lossy()', () => {
78+
const transformation = new Transformation()
79+
.addAction(Delivery.format(Format.gif()).lossy());
80+
expect(transformation.toJson()).toStrictEqual([
81+
{
82+
actionType: 'format',
83+
formatType: 'gif',
84+
lossy: true
85+
}
86+
]);
87+
});
88+
89+
it('quality:80', () => {
90+
const transformation = new Transformation()
91+
.addAction(Delivery.quality('80'));
92+
expect(transformation.toJson()).toStrictEqual([
93+
{
94+
actionType: 'quality',
95+
level: '80'
96+
}
97+
]);
98+
});
99+
100+
it('quality:80.quantization', () => {
101+
const transformation = new Transformation()
102+
.addAction(Delivery.quality('80').quantization(10));
103+
expect(transformation.toJson()).toStrictEqual([
104+
{
105+
actionType: 'quality',
106+
level: '80',
107+
quantization: 10
108+
}
109+
]);
110+
});
111+
112+
it('quality:auto', () => {
113+
const transformation = new Transformation()
114+
.addAction(Delivery.quality(Quality.auto()));
115+
expect(transformation.toJson()).toStrictEqual([
116+
{
117+
actionType: 'quality',
118+
level: 'auto'
119+
}
120+
]);
121+
});
122+
123+
it('chromaSubSampling', () => {
124+
const transformation = new Transformation()
125+
.addAction(Delivery.quality('75').chromaSubSampling(ChromaSubSampling.chroma420()));
126+
expect(transformation.toJson()).toStrictEqual([
127+
{
128+
actionType: 'quality',
129+
level: '75',
130+
chromaSubSampling: 'CHROMA_420'
131+
}
132+
]);
133+
});
134+
});
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import {Transformation} from '../../../src';
2+
import {Resize} from "../../../src/actions";
3+
import {AspectRatio} from "../../../src/qualifiers";
4+
5+
describe('resize.toJson()', () => {
6+
it('scale', () => {
7+
const transformation = new Transformation()
8+
.addAction(Resize.scale(200));
9+
expect(transformation.toJson()).toStrictEqual([
10+
{
11+
"actionType": "scale",
12+
"dimensions": {
13+
"width": 200
14+
}
15+
}
16+
]);
17+
});
18+
19+
it('scale.fit.limitFit.minimumFit.crop.fill.limitFill.thumbnail.pad.limitPad.minimumPad', () => {
20+
const transformation = new Transformation()
21+
.addAction(Resize.scale(200).aspectRatio(7))
22+
.addAction(Resize.fit(100, 200).aspectRatio('16:9'))
23+
.addAction(Resize.limitFit(100).aspectRatio(AspectRatio.ar16X9()))
24+
.addAction(Resize.minimumFit(100).aspectRatio(AspectRatio.ignoreInitialAspectRatio()))
25+
.addAction(Resize.crop(100).x(3).y(4).gravity('north_east').zoom(10))
26+
.addAction(Resize.fill(200).x(3).y(4).gravity('south'))
27+
.addAction(Resize.limitFill(200).x(3).y(4).gravity('south'))
28+
.addAction(Resize.thumbnail(100).gravity('south').zoom(4))
29+
.addAction(Resize.pad(100).gravity('south').offsetX(3).offsetY(4))
30+
.addAction(Resize.limitPad(100).gravity('south').offsetX(3).offsetY(4))
31+
.addAction(Resize.minimumPad(100).gravity('south').offsetX(3).offsetY(4));
32+
expect(transformation.toJson()).toStrictEqual([
33+
{
34+
"actionType": "scale",
35+
"dimensions": {
36+
"aspectRatio": "7.0",
37+
"width": 200
38+
}
39+
},
40+
{
41+
"actionType": "fit",
42+
"dimensions": {
43+
"aspectRatio": "16:9",
44+
"height": 200,
45+
"width": 100
46+
}
47+
},
48+
{
49+
"actionType": "limitFit",
50+
"dimensions": {
51+
"aspectRatio": "16:9",
52+
"width": 100
53+
}
54+
},
55+
{
56+
"actionType": "minimumFit",
57+
"dimensions": {
58+
"aspectRatio": "ignore_aspect_ratio",
59+
"width": 100
60+
}
61+
},
62+
{
63+
"actionType": "crop",
64+
"dimensions": {
65+
"width": 100
66+
},
67+
x: 3,
68+
y: 4,
69+
gravity: 'north_east',
70+
zoom: 10
71+
},
72+
{
73+
"actionType": "fill",
74+
"dimensions": {
75+
"width": 200
76+
},
77+
x: 3,
78+
y: 4,
79+
gravity: 'south'
80+
},
81+
{
82+
"actionType": "limitFill",
83+
"dimensions": {
84+
"width": 200
85+
},
86+
x: 3,
87+
y: 4,
88+
gravity: 'south'
89+
},
90+
{
91+
"actionType": "thumbnail",
92+
"dimensions": {
93+
"width": 100
94+
},
95+
gravity: 'south',
96+
zoom: 4
97+
},
98+
{
99+
"actionType": "pad",
100+
"dimensions": {
101+
"width": 100
102+
},
103+
gravity: 'south',
104+
x: 3,
105+
y: 4
106+
},
107+
{
108+
"actionType": "limitPad",
109+
"dimensions": {
110+
"width": 100
111+
},
112+
gravity: 'south',
113+
x: 3,
114+
y: 4
115+
},
116+
{
117+
"actionType": "minimumPad",
118+
"dimensions": {
119+
"width": 100
120+
},
121+
gravity: 'south',
122+
x: 3,
123+
y: 4
124+
}
125+
]);
126+
});
127+
});

0 commit comments

Comments
 (0)