rotation.spec.js
1.9 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
/**
* @author NHN Ent. FE Development Team <dl_javascript@nhn.com>
* @fileoverview Test cases of "src/js/component/rotation.js"
*/
import fabric from 'fabric';
import $ from 'jquery';
import Graphics from '../src/js/graphics';
import Rotation from '../src/js/component/rotation';
describe('Rotation', () => {
let graphics, rotationModule, mockImage, canvas;
beforeAll(() => {
graphics = new Graphics($('<canvas>')[0]);
canvas = graphics.getCanvas();
rotationModule = new Rotation(graphics);
});
beforeEach(() => {
mockImage = new fabric.Image();
graphics.setCanvasImage('mockImage', mockImage);
});
it('"getCurrentAngle()" should return current angle value', () => {
mockImage.angle = 30;
expect(rotationModule.getCurrentAngle()).toEqual(30);
});
it('"setAngle()" should set angle value', () => {
rotationModule.setAngle(40);
expect(rotationModule.getCurrentAngle()).toEqual(40);
});
it('"rotate()" should add angle value', () => {
let current = rotationModule.getCurrentAngle();
rotationModule.rotate(10);
expect(rotationModule.getCurrentAngle()).toBe(current + 10);
current = rotationModule.getCurrentAngle();
rotationModule.rotate(20);
expect(rotationModule.getCurrentAngle()).toBe(current + 20);
});
it('"rotate()" should add angle value modular 360(===2*PI)', (done) => {
rotationModule
.setAngle(10)
.then(() => rotationModule.rotate(380))
.then(() => {
expect(rotationModule.getCurrentAngle()).toBe(30);
done();
});
});
// @todo Move this tc to main.spec.js
it('"adjustCanvasDimension()" should set canvas dimension from image-rect', () => {
spyOn(mockImage, 'getBoundingRect').and.returnValue({
width: 100,
height: 110,
});
rotationModule.adjustCanvasDimension();
expect(canvas.getWidth()).toEqual(100);
expect(canvas.getHeight()).toEqual(110);
});
});