|
| 1 | +/* |
| 2 | + * This file is part of Interacto. |
| 3 | + * Interacto is free software: you can redistribute it and/or modify |
| 4 | + * it under the terms of the GNU General Public License as published by |
| 5 | + * the Free Software Foundation, either version 3 of the License, or |
| 6 | + * (at your option) any later version. |
| 7 | + * Interacto is distributed in the hope that it will be useful, |
| 8 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | + * GNU General Public License for more details. |
| 11 | + * You should have received a copy of the GNU General Public License |
| 12 | + * along with Interacto. If not, see <https://www.gnu.org/licenses/>. |
| 13 | + */ |
| 14 | + |
| 15 | +import {GeneralTwoTouchDataImpl} from "../../src/impl/interaction/GeneralTwoTouchDataImpl"; |
| 16 | +import {beforeEach, describe, expect, jest, test} from "@jest/globals"; |
| 17 | +import type {SrcTgtTouchDataImpl} from "../../src/impl/interaction/SrcTgtTouchDataImpl"; |
| 18 | + |
| 19 | +describe("using a touch data", () => { |
| 20 | + let data: GeneralTwoTouchDataImpl; |
| 21 | + |
| 22 | + beforeEach(() => { |
| 23 | + data = new GeneralTwoTouchDataImpl(); |
| 24 | + }); |
| 25 | + |
| 26 | + test("touches three values", () => { |
| 27 | + expect(data.touches).toHaveLength(2); |
| 28 | + }); |
| 29 | + |
| 30 | + test("touches t1", () => { |
| 31 | + expect(data.touches[0]).toBe(data.touch1); |
| 32 | + }); |
| 33 | + |
| 34 | + test("touches t2", () => { |
| 35 | + expect(data.touches[1]).toBe(data.touch2); |
| 36 | + }); |
| 37 | + |
| 38 | + test("flush", () => { |
| 39 | + jest.spyOn(data.touch1 as SrcTgtTouchDataImpl, "flush"); |
| 40 | + jest.spyOn(data.touch2 as SrcTgtTouchDataImpl, "flush"); |
| 41 | + |
| 42 | + data.flush(); |
| 43 | + |
| 44 | + expect((data.touch1 as SrcTgtTouchDataImpl).flush).toHaveBeenCalledTimes(1); |
| 45 | + expect((data.touch2 as SrcTgtTouchDataImpl).flush).toHaveBeenCalledTimes(1); |
| 46 | + }); |
| 47 | + |
| 48 | + describe("with values", () => { |
| 49 | + let div: HTMLDivElement; |
| 50 | + let div2: HTMLDivElement; |
| 51 | + let touch1: Touch; |
| 52 | + let touch2: Touch; |
| 53 | + |
| 54 | + beforeEach(() => { |
| 55 | + div = document.createElement("div"); |
| 56 | + div2 = document.createElement("div"); |
| 57 | + touch1 = {"identifier": 3, "screenX": 15, "screenY": 20, "clientX": 160, |
| 58 | + "clientY": 21, "force": 1, "pageX": 2, "pageY": 4, "radiusX": 10, "radiusY": 23, "rotationAngle": 45, "target": div}; |
| 59 | + touch2 = {"identifier": 2, "screenX": 16, "screenY": 22, "clientX": 150, |
| 60 | + "clientY": 30, "force": 3, "pageX": 1, "pageY": 10, "radiusX": 20, "radiusY": 30, "rotationAngle": -10, "target": div2}; |
| 61 | + |
| 62 | + data.initTouch(touch1, |
| 63 | + {"target": div, "altKey": true, "ctrlKey": true, "metaKey": true, "shiftKey": false, "timeStamp": 11, "currentTarget": div}, |
| 64 | + []); |
| 65 | + }); |
| 66 | + |
| 67 | + test("t1 initialized", () => { |
| 68 | + expect(data.touch1.src.identifier).toBe(3); |
| 69 | + expect(data.touch1.tgt.identifier).toBe(3); |
| 70 | + expect(data.touch1.src.target).toBe(div); |
| 71 | + expect(data.touch1.tgt.target).toBe(div); |
| 72 | + expect(data.touch2.src.target).toBeNull(); |
| 73 | + expect(data.touch2.tgt.target).toBeNull(); |
| 74 | + }); |
| 75 | + |
| 76 | + test("t2 initialized", () => { |
| 77 | + data.initTouch(touch2, |
| 78 | + {"target": div2, "altKey": true, "ctrlKey": true, "metaKey": true, "shiftKey": false, "timeStamp": 11, "currentTarget": div2}, |
| 79 | + []); |
| 80 | + |
| 81 | + expect(data.touch1.src.identifier).toBe(3); |
| 82 | + expect(data.touch1.tgt.identifier).toBe(3); |
| 83 | + expect(data.touch1.src.target).toBe(div); |
| 84 | + expect(data.touch1.tgt.target).toBe(div); |
| 85 | + expect(data.touch2.src.identifier).toBe(2); |
| 86 | + expect(data.touch2.tgt.identifier).toBe(2); |
| 87 | + expect(data.touch2.src.target).toBe(div2); |
| 88 | + expect(data.touch2.tgt.target).toBe(div2); |
| 89 | + }); |
| 90 | + |
| 91 | + test("init does nothing when already init", () => { |
| 92 | + data.initTouch(touch2, |
| 93 | + {"target": div2, "altKey": true, "ctrlKey": true, "metaKey": true, "shiftKey": false, "timeStamp": 11, "currentTarget": div2}, |
| 94 | + []); |
| 95 | + data.initTouch({"identifier": 5, "screenX": 15, "screenY": 20, "clientX": 160, |
| 96 | + "clientY": 21, "force": 1, "pageX": 2, "pageY": 4, "radiusX": 10, "radiusY": 23, "rotationAngle": 45, "target": div2}, |
| 97 | + {"target": div2, "altKey": true, "ctrlKey": true, "metaKey": true, "shiftKey": false, "timeStamp": 11, "currentTarget": div2}, |
| 98 | + []); |
| 99 | + |
| 100 | + expect(data.touch1.src.identifier).toBe(3); |
| 101 | + expect(data.touch1.tgt.identifier).toBe(3); |
| 102 | + expect(data.touch2.src.identifier).toBe(2); |
| 103 | + expect(data.touch2.tgt.identifier).toBe(2); |
| 104 | + }); |
| 105 | + |
| 106 | + test("t1 copy", () => { |
| 107 | + data.copyTouch({"identifier": 3, "screenX": 150, "screenY": 20, "clientX": 160, |
| 108 | + "clientY": 21, "force": 1, "pageX": 2, "pageY": 4, "radiusX": 10, "radiusY": 23, "rotationAngle": 45, "target": div2}, |
| 109 | + {"target": div2, "altKey": true, "ctrlKey": true, "metaKey": true, "shiftKey": false, "timeStamp": 11, "currentTarget": div2}, |
| 110 | + []); |
| 111 | + |
| 112 | + expect(data.touch1.src.identifier).toBe(3); |
| 113 | + expect(data.touch1.tgt.identifier).toBe(3); |
| 114 | + expect(data.touch1.src.screenX).toBe(15); |
| 115 | + expect(data.touch1.tgt.screenX).toBe(150); |
| 116 | + expect(data.touch2.src.target).toBeNull(); |
| 117 | + expect(data.touch2.tgt.target).toBeNull(); |
| 118 | + }); |
| 119 | + |
| 120 | + describe("with both touches", () => { |
| 121 | + beforeEach(() => { |
| 122 | + data.initTouch(touch2, |
| 123 | + {"target": div2, "altKey": true, "ctrlKey": true, "metaKey": true, "shiftKey": false, "timeStamp": 11, "currentTarget": div2}, |
| 124 | + []); |
| 125 | + }); |
| 126 | + |
| 127 | + test("t2 copy", () => { |
| 128 | + data.copyTouch({"identifier": 2, "screenX": 1, "screenY": 200, "clientX": 160, |
| 129 | + "clientY": 21, "force": 1, "pageX": 2, "pageY": 4, "radiusX": 10, "radiusY": 23, "rotationAngle": 45, "target": div2}, |
| 130 | + {"target": div2, "altKey": true, "ctrlKey": true, "metaKey": true, "shiftKey": false, "timeStamp": 11, "currentTarget": div2}, |
| 131 | + []); |
| 132 | + |
| 133 | + expect(data.touch1.src.identifier).toBe(3); |
| 134 | + expect(data.touch1.tgt.identifier).toBe(3); |
| 135 | + expect(data.touch2.src.screenY).toBe(22); |
| 136 | + expect(data.touch2.tgt.screenY).toBe(200); |
| 137 | + }); |
| 138 | + |
| 139 | + test("t2 copy bad ID does nothing", () => { |
| 140 | + data.copyTouch({"identifier": 20, "screenX": 1, "screenY": 200, "clientX": 160, |
| 141 | + "clientY": 21, "force": 1, "pageX": 2, "pageY": 4, "radiusX": 10, "radiusY": 23, "rotationAngle": 45, "target": div2}, |
| 142 | + {"target": div2, "altKey": true, "ctrlKey": true, "metaKey": true, "shiftKey": false, "timeStamp": 11, "currentTarget": div2}, |
| 143 | + []); |
| 144 | + |
| 145 | + expect(data.touch1.src.screenY).toBe(20); |
| 146 | + expect(data.touch1.tgt.screenY).toBe(20); |
| 147 | + expect(data.touch2.src.screenY).toBe(22); |
| 148 | + expect(data.touch2.tgt.screenY).toBe(22); |
| 149 | + }); |
| 150 | + |
| 151 | + test("diff clientX", () => { |
| 152 | + data.copyTouch({"identifier": 2, "screenX": 1, "screenY": 200, "clientX": 170, |
| 153 | + "clientY": 21, "force": 1, "pageX": 2, "pageY": 4, "radiusX": 10, "radiusY": 23, "rotationAngle": 45, "target": div2}, |
| 154 | + {"target": div2, "altKey": true, "ctrlKey": true, "metaKey": true, "shiftKey": false, "timeStamp": 11, "currentTarget": div2}, |
| 155 | + []); |
| 156 | + data.copyTouch({"identifier": 3, "screenX": 1, "screenY": 200, "clientX": 200, |
| 157 | + "clientY": 21, "force": 1, "pageX": 2, "pageY": 4, "radiusX": 10, "radiusY": 23, "rotationAngle": 45, "target": div2}, |
| 158 | + {"target": div2, "altKey": true, "ctrlKey": true, "metaKey": true, "shiftKey": false, "timeStamp": 11, "currentTarget": div2}, |
| 159 | + []); |
| 160 | + expect(data.diffClientX).toBe(30); |
| 161 | + }); |
| 162 | + |
| 163 | + test("diff clientY", () => { |
| 164 | + data.copyTouch({"identifier": 2, "screenX": 1, "screenY": 200, "clientX": 170, |
| 165 | + "clientY": 31, "force": 1, "pageX": 2, "pageY": 4, "radiusX": 10, "radiusY": 23, "rotationAngle": 45, "target": div2}, |
| 166 | + {"target": div2, "altKey": true, "ctrlKey": true, "metaKey": true, "shiftKey": false, "timeStamp": 11, "currentTarget": div2}, |
| 167 | + []); |
| 168 | + data.copyTouch({"identifier": 3, "screenX": 1, "screenY": 200, "clientX": 200, |
| 169 | + "clientY": 50, "force": 1, "pageX": 2, "pageY": 4, "radiusX": 10, "radiusY": 23, "rotationAngle": 45, "target": div2}, |
| 170 | + {"target": div2, "altKey": true, "ctrlKey": true, "metaKey": true, "shiftKey": false, "timeStamp": 11, "currentTarget": div2}, |
| 171 | + []); |
| 172 | + expect(data.diffClientY).toBe(15); |
| 173 | + }); |
| 174 | + |
| 175 | + test("diff pageX", () => { |
| 176 | + data.copyTouch({"identifier": 2, "screenX": 1, "screenY": 200, "clientX": 170, |
| 177 | + "clientY": 31, "force": 1, "pageX": 10, "pageY": 4, "radiusX": 10, "radiusY": 23, "rotationAngle": 45, "target": div2}, |
| 178 | + {"target": div2, "altKey": true, "ctrlKey": true, "metaKey": true, "shiftKey": false, "timeStamp": 11, "currentTarget": div2}, |
| 179 | + []); |
| 180 | + data.copyTouch({"identifier": 3, "screenX": 1, "screenY": 200, "clientX": 200, |
| 181 | + "clientY": 50, "force": 1, "pageX": 11, "pageY": 4, "radiusX": 10, "radiusY": 23, "rotationAngle": 45, "target": div2}, |
| 182 | + {"target": div2, "altKey": true, "ctrlKey": true, "metaKey": true, "shiftKey": false, "timeStamp": 11, "currentTarget": div2}, |
| 183 | + []); |
| 184 | + expect(data.diffPageX).toBe(9); |
| 185 | + }); |
| 186 | + |
| 187 | + test("diff pageY", () => { |
| 188 | + data.copyTouch({"identifier": 2, "screenX": 1, "screenY": 200, "clientX": 170, |
| 189 | + "clientY": 31, "force": 1, "pageX": 2, "pageY": 10, "radiusX": 10, "radiusY": 23, "rotationAngle": 45, "target": div2}, |
| 190 | + {"target": div2, "altKey": true, "ctrlKey": true, "metaKey": true, "shiftKey": false, "timeStamp": 11, "currentTarget": div2}, |
| 191 | + []); |
| 192 | + data.copyTouch({"identifier": 3, "screenX": 1, "screenY": 200, "clientX": 200, |
| 193 | + "clientY": 50, "force": 1, "pageX": 2, "pageY": 20, "radiusX": 10, "radiusY": 23, "rotationAngle": 45, "target": div2}, |
| 194 | + {"target": div2, "altKey": true, "ctrlKey": true, "metaKey": true, "shiftKey": false, "timeStamp": 11, "currentTarget": div2}, |
| 195 | + []); |
| 196 | + expect(data.diffPageY).toBe(8); |
| 197 | + }); |
| 198 | + |
| 199 | + test("diff screenX", () => { |
| 200 | + data.copyTouch({"identifier": 2, "screenX": 20, "screenY": 30, "clientX": 170, |
| 201 | + "clientY": 31, "force": 1, "pageX": 2, "pageY": 4, "radiusX": 10, "radiusY": 23, "rotationAngle": 45, "target": div2}, |
| 202 | + {"target": div2, "altKey": true, "ctrlKey": true, "metaKey": true, "shiftKey": false, "timeStamp": 11, "currentTarget": div2}, |
| 203 | + []); |
| 204 | + data.copyTouch({"identifier": 3, "screenX": 21, "screenY": 40, "clientX": 200, |
| 205 | + "clientY": 50, "force": 1, "pageX": 2, "pageY": 4, "radiusX": 10, "radiusY": 23, "rotationAngle": 45, "target": div2}, |
| 206 | + {"target": div2, "altKey": true, "ctrlKey": true, "metaKey": true, "shiftKey": false, "timeStamp": 11, "currentTarget": div2}, |
| 207 | + []); |
| 208 | + expect(data.diffScreenX).toBe(5); |
| 209 | + }); |
| 210 | + |
| 211 | + test("diff screenY", () => { |
| 212 | + data.copyTouch({"identifier": 2, "screenX": 1, "screenY": 30, "clientX": 170, |
| 213 | + "clientY": 31, "force": 1, "pageX": 2, "pageY": 4, "radiusX": 10, "radiusY": 23, "rotationAngle": 45, "target": div2}, |
| 214 | + {"target": div2, "altKey": true, "ctrlKey": true, "metaKey": true, "shiftKey": false, "timeStamp": 11, "currentTarget": div2}, |
| 215 | + []); |
| 216 | + data.copyTouch({"identifier": 3, "screenX": 1, "screenY": 40, "clientX": 200, |
| 217 | + "clientY": 50, "force": 1, "pageX": 2, "pageY": 4, "radiusX": 10, "radiusY": 23, "rotationAngle": 45, "target": div2}, |
| 218 | + {"target": div2, "altKey": true, "ctrlKey": true, "metaKey": true, "shiftKey": false, "timeStamp": 11, "currentTarget": div2}, |
| 219 | + []); |
| 220 | + expect(data.diffScreenY).toBe(14); |
| 221 | + }); |
| 222 | + }); |
| 223 | + }); |
| 224 | + |
| 225 | +}); |
0 commit comments