-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathbase-node.test.tsx
More file actions
109 lines (97 loc) · 2.65 KB
/
base-node.test.tsx
File metadata and controls
109 lines (97 loc) · 2.65 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { createElement as h } from 'preact/compat'
jest.mock('../../src/LogicFlow', () => ({ __esModule: true, default: {} }))
jest.mock('../../src/model', () => ({}))
jest.mock('../../src/view/Anchor', () => ({
__esModule: true,
default: () => null,
}))
jest.mock('../../src/view/text', () => ({ BaseText: () => null }))
jest.mock('../../src/view/Rotate', () => ({
__esModule: true,
default: () => null,
}))
jest.mock('../../src/view/Control', () => ({
__esModule: true,
default: () => null,
}))
jest.mock('../../src/constant', () => ({
ElementState: {
ALLOW_CONNECT: 'ALLOW_CONNECT',
NOT_ALLOW_CONNECT: 'NOT_ALLOW_CONNECT',
},
EventType: {},
TextMode: { TEXT: 'TEXT' },
}))
jest.mock('../../src/util', () => ({
StepDrag: class {
setStep = jest.fn()
handleMouseDown = jest.fn()
setModel = jest.fn()
},
snapToGrid: jest.fn((value) => value),
isIe: jest.fn(() => false),
isMultipleSelect: jest.fn(() => false),
cancelRaf: jest.fn(),
createRaf: jest.fn(),
}))
import BaseNode from '../../src/view/node/BaseNode'
class TestNode extends BaseNode<any> {
getShape() {
return <g />
}
}
const createBaseNode = () => {
const model = {
id: 'node-1',
anchors: [],
autoToFront: false,
draggable: true,
isDragging: false,
isHitable: true,
isHovered: false,
isSelected: false,
isShowAnchor: false,
transform: '',
getData: jest.fn(() => ({ id: 'node-1' })),
getOuterGAttributes: jest.fn(() => ({})),
}
const graphModel = {
gridSize: 10,
eventCenter: { emit: jest.fn() },
transformModel: { SCALE_X: 2 },
editConfigModel: {
adjustNodePosition: true,
allowResize: false,
allowRotate: false,
hideAnchors: false,
},
}
const node = new TestNode({
model,
graphModel,
} as any)
;(node as any).props = { model, graphModel }
jest.spyOn(node.stepDrag, 'setStep')
jest.spyOn(node.stepDrag, 'handleMouseDown').mockImplementation(jest.fn())
return { node }
}
describe('BaseNode drag step', () => {
test('updates scaled drag step on pointer down instead of render', () => {
const { node } = createBaseNode()
node.render()
expect(node.stepDrag.setStep).not.toHaveBeenCalled()
const ev = {
clientX: 12,
clientY: 24,
pointerType: 'mouse',
} as PointerEvent
node.handleMouseDown(ev)
expect(node.stepDrag.setStep).toHaveBeenCalledWith(20)
expect(node.stepDrag.handleMouseDown).toHaveBeenCalledWith(ev)
expect(
(node.stepDrag.setStep as jest.Mock).mock.invocationCallOrder[0],
).toBeLessThan(
(node.stepDrag.handleMouseDown as jest.Mock).mock.invocationCallOrder[0],
)
})
})