Skip to content

Commit 38a302b

Browse files
committed
add test for animation
1 parent 7fd5949 commit 38a302b

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/packages/hint/hintItem.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
describe("hintAnimation logic", () => {
2+
const dataHintAnimationAttribute = "data-hint-animation";
3+
4+
let element: HTMLElement;
5+
let hint: { getOption: (key: string) => boolean };
6+
7+
beforeEach(() => {
8+
element = document.createElement("div");
9+
10+
hint = {
11+
getOption: jest.fn(() => true), // default: true
12+
};
13+
});
14+
15+
function getHintAnimation(element: HTMLElement, hint: any): boolean {
16+
const hintAnimationAttr = element.getAttribute(dataHintAnimationAttribute);
17+
let hintAnimation: boolean = hint.getOption("hintAnimation");
18+
if (hintAnimationAttr) {
19+
hintAnimation = hintAnimationAttr === "true";
20+
}
21+
return hintAnimation;
22+
}
23+
24+
test("should use hint.getOption when no attribute is set", () => {
25+
(hint.getOption as jest.Mock).mockReturnValue(true);
26+
27+
const result = getHintAnimation(element, hint);
28+
29+
expect(result).toBe(true);
30+
expect(hint.getOption).toHaveBeenCalledWith("hintAnimation");
31+
});
32+
33+
test("should override with true when attribute is 'true'", () => {
34+
element.setAttribute(dataHintAnimationAttribute, "true");
35+
(hint.getOption as jest.Mock).mockReturnValue(false); // default false
36+
37+
const result = getHintAnimation(element, hint);
38+
39+
expect(result).toBe(true);
40+
});
41+
42+
test("should override with false when attribute is 'false'", () => {
43+
element.setAttribute(dataHintAnimationAttribute, "false");
44+
(hint.getOption as jest.Mock).mockReturnValue(true); // default true
45+
46+
const result = getHintAnimation(element, hint);
47+
48+
expect(result).toBe(false);
49+
});
50+
});

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)