Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/plugin-cover/test/cover.test.js
1129 views
1
import { Jimp, mkJGD, hasOwnProp } from '@jimp/test-utils';
2
import configure from '@jimp/custom';
3
import crop from '@jimp/plugin-crop';
4
import scale from '@jimp/plugin-scale';
5
import resize from '@jimp/plugin-resize';
6
7
import cover from '../src';
8
9
const jimp = configure({ plugins: [resize, scale, crop, cover] }, Jimp);
10
11
describe('All align combinations for cover', () => {
12
const verticalJGD = mkJGD(
13
'▴▴▴▴▸▸▸▸',
14
'▴▴▴▴▸▸▸▸',
15
'▴▴▴▴▸▸▸▸',
16
'▴▴▴▴▸▸▸▸',
17
'▴▴▴▴▸▸▸▸',
18
'▴▴▴▴▸▸▸▸',
19
'▾▾▾▾◆◆◆◆',
20
'▾▾▾▾◆◆◆◆',
21
'▾▾▾▾◆◆◆◆',
22
'▾▾▾▾◆◆◆◆',
23
'▾▾▾▾◆◆◆◆',
24
'▾▾▾▾◆◆◆◆'
25
);
26
27
const horizontalJGD = mkJGD(
28
'▴▴▴▴▴▴▸▸▸▸▸▸',
29
'▴▴▴▴▴▴▸▸▸▸▸▸',
30
'▴▴▴▴▴▴▸▸▸▸▸▸',
31
'▴▴▴▴▴▴▸▸▸▸▸▸',
32
'▾▾▾▾▾▾◆◆◆◆◆◆',
33
'▾▾▾▾▾▾◆◆◆◆◆◆',
34
'▾▾▾▾▾▾◆◆◆◆◆◆',
35
'▾▾▾▾▾▾◆◆◆◆◆◆'
36
);
37
38
let vertical;
39
let horizontal; // stores the Jimp instances of the JGD images above.
40
41
before(done => {
42
const img1 = jimp.read(verticalJGD);
43
const img2 = jimp.read(horizontalJGD);
44
Promise.all([img1, img2])
45
.then(images => {
46
vertical = images[0];
47
horizontal = images[1];
48
done();
49
})
50
.catch(done);
51
});
52
53
const tests = {}; // Stores the expected result for each alignment combination.
54
tests['LEFT TOP'] = {
55
cover: {
56
verti: mkJGD('▴▴▸▸', '▴▴▸▸', '▴▴▸▸', '▾▾◆◆'),
57
horiz: mkJGD('▴▴▴▸', '▴▴▴▸', '▾▾▾◆', '▾▾▾◆')
58
}
59
};
60
tests['CENTER TOP'] = {
61
cover: {
62
verti: mkJGD('▴▴▸▸', '▴▴▸▸', '▴▴▸▸', '▾▾◆◆'),
63
horiz: mkJGD('▴▴▸▸', '▴▴▸▸', '▾▾◆◆', '▾▾◆◆')
64
}
65
};
66
tests['RIGHT TOP'] = {
67
cover: {
68
verti: mkJGD('▴▴▸▸', '▴▴▸▸', '▴▴▸▸', '▾▾◆◆'),
69
horiz: mkJGD('▴▸▸▸', '▴▸▸▸', '▾◆◆◆', '▾◆◆◆')
70
}
71
};
72
73
tests['LEFT MIDDLE'] = {
74
cover: {
75
verti: mkJGD('▴▴▸▸', '▴▴▸▸', '▾▾◆◆', '▾▾◆◆'),
76
horiz: mkJGD('▴▴▴▸', '▴▴▴▸', '▾▾▾◆', '▾▾▾◆')
77
}
78
};
79
tests['CENTER MIDDLE'] = {
80
cover: {
81
verti: mkJGD('▴▴▸▸', '▴▴▸▸', '▾▾◆◆', '▾▾◆◆'),
82
horiz: mkJGD('▴▴▸▸', '▴▴▸▸', '▾▾◆◆', '▾▾◆◆')
83
}
84
};
85
tests['RIGHT MIDDLE'] = {
86
cover: {
87
verti: mkJGD('▴▴▸▸', '▴▴▸▸', '▾▾◆◆', '▾▾◆◆'),
88
horiz: mkJGD('▴▸▸▸', '▴▸▸▸', '▾◆◆◆', '▾◆◆◆')
89
}
90
};
91
92
tests['LEFT BOTTOM'] = {
93
cover: {
94
verti: mkJGD('▴▴▸▸', '▾▾◆◆', '▾▾◆◆', '▾▾◆◆'),
95
horiz: mkJGD('▴▴▴▸', '▴▴▴▸', '▾▾▾◆', '▾▾▾◆')
96
}
97
};
98
tests['CENTER BOTTOM'] = {
99
cover: {
100
verti: mkJGD('▴▴▸▸', '▾▾◆◆', '▾▾◆◆', '▾▾◆◆'),
101
horiz: mkJGD('▴▴▸▸', '▴▴▸▸', '▾▾◆◆', '▾▾◆◆')
102
}
103
};
104
tests['RIGHT BOTTOM'] = {
105
cover: {
106
verti: mkJGD('▴▴▸▸', '▾▾◆◆', '▾▾◆◆', '▾▾◆◆'),
107
horiz: mkJGD('▴▸▸▸', '▴▸▸▸', '▾◆◆◆', '▾◆◆◆')
108
}
109
};
110
111
function runAlignTest(align) {
112
const jgdCoverV = tests[align].cover.verti;
113
const jgdCoverH = tests[align].cover.horiz;
114
let a = align.split(' ');
115
a = Jimp['HORIZONTAL_ALIGN_' + a[0]] | Jimp['VERTICAL_ALIGN_' + a[1]];
116
it('cover aligned to ' + align, () => {
117
vertical
118
.clone()
119
.cover(4, 4, a)
120
.getJGDSync()
121
.should.be.sameJGD(jgdCoverV, 'Vertical image');
122
horizontal
123
.clone()
124
.cover(4, 4, a)
125
.getJGDSync()
126
.should.be.sameJGD(jgdCoverH, 'Horizontal image');
127
});
128
}
129
130
for (const align in tests) if (hasOwnProp(tests, align)) runAlignTest(align);
131
});
132
133