|
| 1 | +import { fireEvent } from "@testing-library/react"; |
| 2 | + |
| 3 | +import { renderApp } from "../../utils"; |
| 4 | + |
| 5 | +describe("Zoom [Keys]", () => { |
| 6 | + describe("When zooming with activation keys", () => { |
| 7 | + it("should not change translate without activation", async () => { |
| 8 | + const { content, zoom } = renderApp({ |
| 9 | + wheel: { |
| 10 | + activationKeys: ["Control"], |
| 11 | + }, |
| 12 | + }); |
| 13 | + expect(content.style.transform).toBe("translate(0px, 0px) scale(1)"); |
| 14 | + zoom({ value: 2 }); |
| 15 | + expect(content.style.transform).toBe("translate(0px, 0px) scale(1)"); |
| 16 | + }); |
| 17 | + it("should change translate with activated key", async () => { |
| 18 | + const { content, zoom } = renderApp({ |
| 19 | + wheel: { |
| 20 | + activationKeys: ["Control"], |
| 21 | + }, |
| 22 | + }); |
| 23 | + |
| 24 | + expect(content.style.transform).toBe("translate(0px, 0px) scale(1)"); |
| 25 | + fireEvent.keyDown(document, { key: "Control" }); |
| 26 | + zoom({ value: 2 }); |
| 27 | + expect(content.style.transform).toBe("translate(0px, 0px) scale(2)"); |
| 28 | + }); |
| 29 | + }); |
| 30 | + describe("When zooming with multiple activation keys", () => { |
| 31 | + it("should not change translate when partially activated", async () => { |
| 32 | + const { content, zoom } = renderApp({ |
| 33 | + wheel: { |
| 34 | + activationKeys: ["Control", "Shift"], |
| 35 | + }, |
| 36 | + }); |
| 37 | + |
| 38 | + expect(content.style.transform).toBe("translate(0px, 0px) scale(1)"); |
| 39 | + fireEvent.keyDown(document, { key: "Control" }); |
| 40 | + zoom({ value: 2 }); |
| 41 | + expect(content.style.transform).toBe("translate(0px, 0px) scale(1)"); |
| 42 | + }); |
| 43 | + it("should change translate when activated", async () => { |
| 44 | + const { content, zoom } = renderApp({ |
| 45 | + wheel: { |
| 46 | + activationKeys: ["Control", "Shift"], |
| 47 | + }, |
| 48 | + }); |
| 49 | + |
| 50 | + expect(content.style.transform).toBe("translate(0px, 0px) scale(1)"); |
| 51 | + fireEvent.keyDown(document, { key: "Control" }); |
| 52 | + fireEvent.keyDown(document, { key: "Shift" }); |
| 53 | + zoom({ value: 2 }); |
| 54 | + expect(content.style.transform).toBe("translate(0px, 0px) scale(2)"); |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
| 58 | + describe("When zooming with callback activation", () => { |
| 59 | + it("should change translate with successful activation", async () => { |
| 60 | + const { content, zoom } = renderApp({ |
| 61 | + wheel: { |
| 62 | + activationKeys: (keys) => |
| 63 | + keys.includes("Control") && keys.includes("Shift"), |
| 64 | + }, |
| 65 | + }); |
| 66 | + |
| 67 | + expect(content.style.transform).toBe("translate(0px, 0px) scale(1)"); |
| 68 | + fireEvent.keyDown(document, { key: "Control" }); |
| 69 | + fireEvent.keyDown(document, { key: "Shift" }); |
| 70 | + zoom({ value: 2 }); |
| 71 | + expect(content.style.transform).toBe("translate(0px, 0px) scale(2)"); |
| 72 | + }); |
| 73 | + it("should not change translate with partial activation", async () => { |
| 74 | + const { content, zoom } = renderApp({ |
| 75 | + wheel: { |
| 76 | + activationKeys: (keys) => |
| 77 | + keys.includes("Control") && keys.includes("Shift"), |
| 78 | + }, |
| 79 | + }); |
| 80 | + |
| 81 | + expect(content.style.transform).toBe("translate(0px, 0px) scale(1)"); |
| 82 | + fireEvent.keyDown(document, { key: "Control" }); |
| 83 | + zoom({ value: 2 }); |
| 84 | + expect(content.style.transform).toBe("translate(0px, 0px) scale(1)"); |
| 85 | + }); |
| 86 | + }); |
| 87 | +}); |
0 commit comments