Skip to content

Commit 6b48bc0

Browse files
committed
test: 💍 Added more tests to cover crucial logic parts
1 parent 81d864d commit 6b48bc0

23 files changed

Lines changed: 300 additions & 182 deletions

__tests__/features/animations/animations.base.spec.tsx

Lines changed: 0 additions & 43 deletions
This file was deleted.

__tests__/features/controls/controls.zoom.spec.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import { renderApp } from "../../utils/render-app";
44

55
describe("Controls [Base]", () => {
66
describe("When zooming in with controls button", () => {
7-
it("should increase css scale with animated zoom", async () => {
8-
const { content, zoomInBtn } = renderApp();
9-
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
10-
fireEvent(zoomInBtn, new MouseEvent("click", { bubbles: true }));
11-
// Animation starts
12-
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
13-
await waitFor(() => {
14-
// Animation ends
15-
expect(content.style.transform).toBe("translate(0px, 0px) scale(1.65)");
16-
});
17-
});
7+
// it("should increase css scale with animated zoom", async () => {
8+
// const { content, zoomInBtn } = renderApp();
9+
// expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
10+
// fireEvent(zoomInBtn, new MouseEvent("click", { bubbles: true }));
11+
// // Animation starts
12+
// expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
13+
// await waitFor(() => {
14+
// // Animation ends
15+
// expect(content.style.transform).toBe("translate(0px, 0px) scale(1.65)");
16+
// });
17+
// });
1818
});
1919
});

__tests__/features/pan-touch/pan-touch.base.spec.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ describe("Pan Touch [Base]", () => {
99
disablePadding: true,
1010
});
1111
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
12-
touchPan({ x: 100, y: 100 });
12+
touchPan({ x: -100, y: -100 });
1313
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
1414
});
1515
it("should return to position with padding enabled", async () => {
1616
const { content, touchPan } = renderApp({
17-
alignmentAnimation: {
17+
autoAlignment: {
1818
disabled: false,
1919
},
2020
});
2121
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
22-
touchPan({ x: 100, y: 100 });
23-
expect(content.style.transform).toBe("translate(100px, 100px) scale(1)");
22+
touchPan({ x: -100, y: -100 });
23+
expect(content.style.transform).toBe(
24+
"translate(-100px, -100px) scale(1)",
25+
);
2426
await waitFor(() => {
2527
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
2628
});
@@ -30,10 +32,10 @@ describe("Pan Touch [Base]", () => {
3032
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
3133
zoom({ value: 1.5 });
3234
expect(content.style.transform).toBe("translate(0px, 0px) scale(1.5)");
33-
touchPan({ x: 100, y: 100 });
35+
touchPan({ x: -100, y: -100 });
3436
await sleep(10);
3537
expect(content.style.transform).toBe(
36-
"translate(100px, 100px) scale(1.5)",
38+
"translate(-100px, -100px) scale(1.5)",
3739
);
3840
});
3941
});
@@ -45,8 +47,8 @@ describe("Pan Touch [Base]", () => {
4547
},
4648
});
4749
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
48-
touchPan({ x: 100, y: 100 });
49-
expect(content.style.transform).toBe("translate(0px, 100px) scale(1)");
50+
touchPan({ x: -100, y: -100 });
51+
expect(content.style.transform).toBe("translate(0px, -100px) scale(1)");
5052
});
5153
it("should not change y axis transform", async () => {
5254
const { content, touchPan } = renderApp({
@@ -55,8 +57,8 @@ describe("Pan Touch [Base]", () => {
5557
},
5658
});
5759
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
58-
touchPan({ x: 100, y: 100 });
59-
expect(content.style.transform).toBe("translate(100px, 0px) scale(1)");
60+
touchPan({ x: -100, y: -100 });
61+
expect(content.style.transform).toBe("translate(-100px, 0px) scale(1)");
6062
});
6163
});
6264
describe("When disabled", () => {
@@ -65,7 +67,7 @@ describe("Pan Touch [Base]", () => {
6567
disabled: true,
6668
});
6769
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
68-
touchPan({ x: 100, y: 100 });
70+
touchPan({ x: -100, y: -100 });
6971
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
7072
});
7173
it("should not change transform", async () => {
@@ -75,7 +77,7 @@ describe("Pan Touch [Base]", () => {
7577
},
7678
});
7779
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
78-
touchPan({ x: 100, y: 100 });
80+
touchPan({ x: -100, y: -100 });
7981
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
8082
});
8183
});

__tests__/features/pan-touch/pan-touch.callbacks.spec.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ describe("Pan Touch [Callbacks]", () => {
1212
onPanningStop: spy3,
1313
});
1414
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
15-
touchPan({ x: 100, y: 100 });
15+
touchPan({ x: -100, y: -100 });
16+
expect(content.style.transform).toBe(
17+
"translate(-100px, -100px) scale(1)",
18+
);
1619
expect(spy1).toBeCalledTimes(1);
1720
expect(spy2).toBeCalled();
1821
expect(spy3).toBeCalledTimes(1);

__tests__/features/pan-touch/pan-touch.velocity.spec.tsx

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,42 @@ import { renderApp, sleep } from "../../utils";
55
describe("Pan Touch [Velocity]", () => {
66
describe("When panning to coords", () => {
77
it("should trigger velocity", async () => {
8-
const { content, touchPan, pinch } = renderApp();
8+
const { content, touchPan, pinch, ref } = renderApp({
9+
velocityAnimation: {
10+
disabled: false,
11+
},
12+
});
913
pinch({ value: 1.5 });
1014
expect(content.style.transform).toBe("translate(0px, 0px) scale(1.5)");
11-
await sleep(10);
12-
touchPan({ x: 20, y: 20 });
13-
expect(content.style.transform).toBe("translate(20px, 20px) scale(1.5)");
15+
touchPan({ x: -10, y: -10, steps: 5 });
16+
expect(content.style.transform).toBe(
17+
"translate(-10px, -10px) scale(1.5)",
18+
);
19+
await waitFor(() => {
20+
expect(content.style.transform).not.toBe(
21+
"translate(-10px, -10px) scale(1.5)",
22+
);
23+
expect(ref.current?.instance.state.positionX).toBeLessThan(100);
24+
expect(ref.current?.instance.state.positionY).toBeLessThan(100);
25+
expect(ref.current?.instance.state.scale).toBe(1.5);
26+
});
27+
});
28+
it("should not trigger disabled velocity", async () => {
29+
const { content, touchPan, pinch } = renderApp({
30+
velocityAnimation: {
31+
disabled: true,
32+
},
33+
});
34+
pinch({ value: 1.5 });
35+
expect(content.style.transform).toBe("translate(0px, 0px) scale(1.5)");
36+
touchPan({ x: -10, y: -10, steps: 5 });
37+
expect(content.style.transform).toBe(
38+
"translate(-10px, -10px) scale(1.5)",
39+
);
40+
await sleep(20);
41+
expect(content.style.transform).toBe(
42+
"translate(-10px, -10px) scale(1.5)",
43+
);
1444
});
15-
// it("should not trigger disabled velocity", async () => {
16-
// const { content, touchPan, pinch } = renderApp({
17-
// disablePadding: false,
18-
// });
19-
// pinch({ value: 1.2 });
20-
// expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
21-
// touchPan({ x: 100, y: 100 });
22-
// expect(content.style.transform).toBe("translate(100px, 100px) scale(1)");
23-
// await waitFor(() => {
24-
// expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
25-
// });
26-
// });
27-
// it("should accelerate to certain point", async () => {
28-
// const { content, touchPan, zoom } = renderApp();
29-
// expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
30-
// zoom({ value: 1.5 });
31-
// expect(content.style.transform).toBe("translate(0px, 0px) scale(1.5)");
32-
// touchPan({ x: 100, y: 100 });
33-
// await sleep(10);
34-
// expect(content.style.transform).toBe(
35-
// "translate(100px, 100px) scale(1.5)",
36-
// );
37-
// });
3845
});
3946
});

__tests__/features/pan/pan.base.spec.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,21 @@ describe("Pan [Base]", () => {
99
disablePadding: true,
1010
});
1111
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
12-
pan({ x: 100, y: 100 });
12+
pan({ x: -100, y: -100 });
1313
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
1414
});
1515
it("should return to position with padding enabled", async () => {
1616
const { content, pan } = renderApp({
1717
disablePadding: false,
18-
alignmentAnimation: {
18+
autoAlignment: {
1919
disabled: false,
2020
},
2121
});
22-
2322
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
24-
pan({ x: 100, y: 100 });
25-
expect(content.style.transform).toBe("translate(100px, 100px) scale(1)");
23+
pan({ x: -100, y: -100 });
24+
expect(content.style.transform).toBe(
25+
"translate(-100px, -100px) scale(1)",
26+
);
2627
await waitFor(() => {
2728
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
2829
});
@@ -32,10 +33,10 @@ describe("Pan [Base]", () => {
3233
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
3334
zoom({ value: 1.5 });
3435
expect(content.style.transform).toBe("translate(0px, 0px) scale(1.5)");
35-
pan({ x: 100, y: 100 });
36+
pan({ x: -100, y: -100 });
3637
await sleep(10);
3738
expect(content.style.transform).toBe(
38-
"translate(100px, 100px) scale(1.5)",
39+
"translate(-100px, -100px) scale(1.5)",
3940
);
4041
});
4142
});
@@ -48,8 +49,8 @@ describe("Pan [Base]", () => {
4849
},
4950
});
5051
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
51-
pan({ x: 100, y: 100 });
52-
expect(content.style.transform).toBe("translate(0px, 100px) scale(1)");
52+
pan({ x: -100, y: -100 });
53+
expect(content.style.transform).toBe("translate(0px, -100px) scale(1)");
5354
});
5455
it("should not change y axis transform", async () => {
5556
const { content, pan } = renderApp({
@@ -58,8 +59,8 @@ describe("Pan [Base]", () => {
5859
},
5960
});
6061
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
61-
pan({ x: 100, y: 100 });
62-
expect(content.style.transform).toBe("translate(100px, 0px) scale(1)");
62+
pan({ x: -100, y: -100 });
63+
expect(content.style.transform).toBe("translate(-100px, 0px) scale(1)");
6364
});
6465
});
6566

@@ -69,7 +70,7 @@ describe("Pan [Base]", () => {
6970
disabled: true,
7071
});
7172
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
72-
pan({ x: 100, y: 100 });
73+
pan({ x: -100, y: -100 });
7374
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
7475
});
7576
it("should not change transform", async () => {
@@ -79,7 +80,7 @@ describe("Pan [Base]", () => {
7980
},
8081
});
8182
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
82-
pan({ x: 100, y: 100 });
83+
pan({ x: -100, y: -100 });
8384
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
8485
});
8586
});

__tests__/features/pan/pan.callbacks.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe("Pan [Callbacks]", () => {
1212
onPanningStop: spy3,
1313
});
1414
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
15-
pan({ x: 100, y: 100 });
15+
pan({ x: -100, y: -100 });
1616
expect(spy1).toBeCalledTimes(1);
1717
expect(spy2).toBeCalled();
1818
expect(spy3).toBeCalledTimes(1);

__tests__/features/pan/pan.keys.spec.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe("Pan [Keys]", () => {
1111
},
1212
});
1313
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
14-
pan({ x: 100, y: 100 });
14+
pan({ x: -100, y: -100 });
1515
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
1616
});
1717
it("should change translate with activated key", async () => {
@@ -23,8 +23,10 @@ describe("Pan [Keys]", () => {
2323

2424
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
2525
fireEvent.keyDown(document, { key: "Control" });
26-
pan({ x: 100, y: 100 });
27-
expect(content.style.transform).toBe("translate(100px, 100px) scale(1)");
26+
pan({ x: -100, y: -100 });
27+
expect(content.style.transform).toBe(
28+
"translate(-100px, -100px) scale(1)",
29+
);
2830
});
2931
});
3032
describe("When panning with multiple activation keys", () => {
@@ -37,7 +39,7 @@ describe("Pan [Keys]", () => {
3739

3840
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
3941
fireEvent.keyDown(document, { key: "Control" });
40-
pan({ x: 100, y: 100 });
42+
pan({ x: -100, y: -100 });
4143
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
4244
});
4345
it("should change translate when activated", async () => {
@@ -50,8 +52,10 @@ describe("Pan [Keys]", () => {
5052
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
5153
fireEvent.keyDown(document, { key: "Control" });
5254
fireEvent.keyDown(document, { key: "Shift" });
53-
pan({ x: 100, y: 100 });
54-
expect(content.style.transform).toBe("translate(100px, 100px) scale(1)");
55+
pan({ x: -100, y: -100 });
56+
expect(content.style.transform).toBe(
57+
"translate(-100px, -100px) scale(1)",
58+
);
5559
});
5660
});
5761

@@ -67,8 +71,10 @@ describe("Pan [Keys]", () => {
6771
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
6872
fireEvent.keyDown(document, { key: "Control" });
6973
fireEvent.keyDown(document, { key: "Shift" });
70-
pan({ x: 100, y: 100 });
71-
expect(content.style.transform).toBe("translate(100px, 100px) scale(1)");
74+
pan({ x: -100, y: -100 });
75+
expect(content.style.transform).toBe(
76+
"translate(-100px, -100px) scale(1)",
77+
);
7278
});
7379
it("should not change translate with partial activation", async () => {
7480
const { content, pan } = renderApp({
@@ -80,7 +86,7 @@ describe("Pan [Keys]", () => {
8086

8187
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
8288
fireEvent.keyDown(document, { key: "Control" });
83-
pan({ x: 100, y: 100 });
89+
pan({ x: -100, y: -100 });
8490
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)");
8591
});
8692
});

0 commit comments

Comments
 (0)