-
Notifications
You must be signed in to change notification settings - Fork 2k
/
OffsetUtils.spec.ts
73 lines (68 loc) · 1.65 KB
/
OffsetUtils.spec.ts
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
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import {
getDragPreviewOffset,
getEventClientOffset,
getNodeClientOffset,
} from '../OffsetUtils.js'
describe('OffsetUtils', () => {
describe('getNodeClientOffset', () => {
it('should get node client offset for element node', () => {
const el = document.createElement('div')
expect(getNodeClientOffset(el)).toEqual({
x: 0,
y: 0,
})
})
it('should return get parent node client offset if element type is not ELEMENT NODE', () => {
const el = document.createElement('p')
el.textContent = 'Text inside paragraph'
expect(getNodeClientOffset(el.firstChild!)).toEqual({
x: 0,
y: 0,
})
})
it('should return null if parent node is not of Node.ELEMENT_NODE', () => {
const el = document.createComment('this is comment node of type 3')
expect(getNodeClientOffset(el)).toEqual(null)
})
})
describe('getEventClientOffset', () => {
it('should return client offset', () => {
const el = document.createEvent('MouseEvent')
expect(getEventClientOffset(el)).toEqual({
x: 0,
y: 0,
})
})
})
describe('getDragPreviewOffset', () => {
it('should get offset of drag preview component', () => {
const sourceNode = document.createElement('div')
const dragPreview = document.createElement('div')
const clientOffset = {
x: 0,
y: 0,
}
const anchorPoint = {
anchorX: 0,
anchorY: 0,
}
const offsetPoint = {
offsetX: 0,
offsetY: 0,
}
expect(
getDragPreviewOffset(
sourceNode,
dragPreview,
clientOffset,
anchorPoint,
offsetPoint,
),
).toEqual({
x: 0,
y: 0,
})
})
})
})