-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.ts
96 lines (85 loc) · 2.9 KB
/
index.test.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { CollisionHandler, CombinedAlignment, position } from '../src/index';
import { allData, Helper, SizeData } from './Helpers';
const windowSize: SizeData = {
height: 1000,
width: 1000,
},
anchorSize: SizeData = {
height: 100,
width: 100,
},
targetSize: SizeData = {
height: 100,
width: 100,
},
positionArray: CombinedAlignment[] = [
'top left',
'top center',
'top right',
'center left',
'center center',
'center right',
'bottom left',
'bottom center',
'bottom right',
],
helper = new Helper(CollisionHandler.ignore, anchorSize, targetSize);
helper.setupEnvironment(windowSize);
describe('HoverPosition (collisions ignored)', () => {
describe.each(positionArray)('Target Position: %s', (tP) => {
describe.each(positionArray)('options.my: %s', (myPlacement) => {
test.each(positionArray)('options.at: %s', (atPlacement) => {
helper.setupTest(tP);
const pData = position({
...{ debug: true },
...{
my: myPlacement,
at: atPlacement,
target: document.querySelector<HTMLDivElement>(
'.target',
)!,
anchor: document.querySelector<HTMLElement>('.anchor')!,
collision: CollisionHandler.ignore,
},
}) as allData;
expect({
left: parseInt(pData.left, 10),
top: parseInt(pData.top, 10),
}).toStrictEqual({
left: helper.getLeft(tP, myPlacement, atPlacement),
top: helper.getTop(tP, myPlacement, atPlacement),
});
});
});
});
});
test('Window scroll adjusts output', () => {
// Set the window scroll position
window.scrollX = 50;
window.scrollY = 50;
const targetWindowPosition = 'top left',
myPlacement = 'top center',
atPlacement = 'bottom center';
helper.setupTest(targetWindowPosition);
const pData = position({
...{ debug: true },
...{
my: myPlacement,
at: atPlacement,
target: document.querySelector<HTMLDivElement>('.target')!,
anchor: document.querySelector<HTMLElement>('.anchor')!,
collision: CollisionHandler.ignore,
},
}) as allData;
expect({
left: parseInt(pData.left, 10),
top: parseInt(pData.top, 10),
}).toStrictEqual({
left:
helper.getLeft(targetWindowPosition, myPlacement, atPlacement) + 50,
top: helper.getTop(targetWindowPosition, myPlacement, atPlacement) + 50,
});
// Reset the window scroll position
window.scrollX = 0;
window.scrollY = 0;
});