Skip to content

Commit 88bd96b

Browse files
committed
write test for position
1 parent 5ac5dfd commit 88bd96b

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/packages/tour/position.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { setPositionRelativeToStep } from "./position";
2+
import { setPositionRelativeTo } from "../../util/positionRelativeTo";
3+
import { TourStep } from "./steps";
4+
5+
jest.mock("../../util/positionRelativeTo", () => ({
6+
setPositionRelativeTo: jest.fn(),
7+
}));
8+
9+
beforeAll(() => {
10+
// Mock requestAnimationFrame to call callback immediately
11+
global.requestAnimationFrame = (cb) => {
12+
cb(0);
13+
return 0;
14+
};
15+
});
16+
17+
afterAll(() => {
18+
global.requestAnimationFrame = undefined as any;
19+
});
20+
21+
test("requestAnimationFrame runs and calls setPositionRelativeTo", () => {
22+
const relativeElement = document.createElement("div");
23+
const element = document.createElement("div");
24+
const step: TourStep = {
25+
step: 0,
26+
title: "My Step Title",
27+
intro: "My step description",
28+
element: element,
29+
position: "bottom",
30+
tooltipClass: "my-tooltip-class",
31+
highlightClass: "my-highlight-class",
32+
scrollTo: "element",
33+
disableInteraction: false,
34+
};
35+
36+
setPositionRelativeToStep(relativeElement, element, step, 10);
37+
38+
expect(setPositionRelativeTo).toHaveBeenCalledWith(
39+
relativeElement,
40+
element,
41+
step.element,
42+
10
43+
);
44+
});

src/util/getOffset.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export default function getOffset(
3030
const scrollTop = window.pageYOffset || docEl.scrollTop || body.scrollTop;
3131
const scrollLeft = window.pageXOffset || docEl.scrollLeft || body.scrollLeft;
3232

33-
3433
relativeEl = relativeEl || docEl || body;
3534

3635
const x = element.getBoundingClientRect();

0 commit comments

Comments
 (0)