imageEditor.spec.js
2.01 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
69
70
71
72
/**
* @fileoverview Test env
* @author NHN Ent. FE Development Lab <dl_javascript@nhn.com>
*/
import snippet from 'tui-code-snippet';
import ImageEditor from '../src/js/imageEditor';
import fabric from 'fabric';
import { eventNames, keyCodes } from '../src/js/consts';
const { OBJECT_ROTATED } = eventNames;
describe('ImageEditor', () => {
// hostnameSent module scope variable can not be reset.
// maintain cases with xit as it always fail, if you want to test these cases, change xit to fit one by one
describe('constructor', () => {
let imageEditor, el;
beforeEach(() => {
el = document.createElement('div');
spyOn(snippet, 'sendHostname');
imageEditor = new ImageEditor(el, {
usageStatistics: false,
});
});
afterEach(() => {
imageEditor.destroy();
});
xit('should send hostname by default', () => {
imageEditor = new ImageEditor(el);
expect(snippet.sendHostname).toHaveBeenCalled();
});
xit('should not send hostname on usageStatistics option false', () => {
imageEditor = new ImageEditor(el, {
usageStatistics: false,
});
expect(snippet.sendHostname).not.toHaveBeenCalled();
});
it('`preventDefault` of BACKSPACE key events should not be executed when object is selected state.', () => {
const spyCallback = jasmine.createSpy();
spyOn(imageEditor._graphics, 'getActiveObject').and.returnValue(null);
imageEditor._onKeyDown({
keyCode: keyCodes.BACKSPACE,
preventDefault: spyCallback,
});
expect(spyCallback).not.toHaveBeenCalled();
});
it('"objectRotated" event should be fire at object is rotate.', () => {
const canvas = imageEditor._graphics.getCanvas();
const obj = new fabric.Object({});
const mock = { target: obj };
canvas.add(obj);
spyOn(imageEditor, 'fire').and.callThrough();
canvas.fire('object:rotating', mock);
expect(imageEditor.fire.calls.mostRecent().args[0]).toBe(OBJECT_ROTATED);
});
});
});