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
|
describe('getData (method)', () => {
const initialData = {
x: 0,
y: 0,
width: 0,
height: 0,
rotate: 0,
scaleX: 1,
scaleY: 1,
};
it('should get initial data when it is not ready', () => {
const image = window.createImage();
const cropper = new Cropper(image);
expect(cropper.getData()).to.deep.equal(initialData);
});
it('should get initial data when it is not cropped', (done) => {
const image = window.createImage();
const cropper = new Cropper(image, {
autoCrop: false,
ready() {
expect(cropper.cropped).to.be.false;
expect(cropper.getData()).to.deep.equal(initialData);
done();
},
});
});
it('should get data with expected properties', (done) => {
const image = window.createImage();
const cropper = new Cropper(image, {
ready() {
const data = cropper.getData();
expect(data).to.be.an('object').that.has.all.keys(['x', 'y', 'width', 'height', 'rotate', 'scaleX', 'scaleY']);
expect(data.x).to.be.a('number');
expect(data.y).to.be.a('number');
expect(data.width).to.be.a('number');
expect(data.height).to.be.a('number');
expect(data.rotate).to.be.a('number');
expect(data.scaleX).to.be.a('number');
expect(data.scaleY).to.be.a('number');
done();
},
});
});
it('should get data with rounded property values', (done) => {
const image = window.createImage();
const cropper = new Cropper(image, {
ready() {
const data = cropper.getData(true);
expect(data.x % 1).to.equal(0);
expect(data.y % 1).to.equal(0);
expect(data.width % 1).to.equal(0);
expect(data.height % 1).to.equal(0);
done();
},
});
});
it('should not exceed the natural width/height after rounded', (done) => {
const image = window.createImage();
const cropper = new Cropper(image, {
viewMode: 1,
ready() {
const imageData = cropper.getImageData();
const left = 155.5;
const top = 155.5;
cropper.setData({
left,
top,
width: imageData.naturalWidth - left,
height: imageData.naturalHeight - top,
});
const roundedData = cropper.getData(true);
expect(roundedData.x + roundedData.width).to.be.at.most(imageData.naturalWidth);
expect(roundedData.y + roundedData.height).to.be.at.most(imageData.naturalHeight);
done();
},
});
});
});
|