The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { |
| 2 | BoxGeometry, |
| 3 | Group, |
| 4 | Mesh, |
| 5 | MeshBasicMaterial, |
| 6 | PerspectiveCamera, |
| 7 | PlaneGeometry, |
| 8 | Texture, |
| 9 | } from "three"; |
| 10 | import { expect, it, vi } from "vite-plus/test"; |
| 11 | import { createImportedPhoneScene, disposeDeviceModel } from "./modelScene.ts"; |
| 12 | import { phoneDisplayLayout } from "./phoneScene.ts"; |
| 13 | |
| 14 | function asset() { |
| 15 | const root = new Group(); |
| 16 | const body = new Mesh(new BoxGeometry(1.15, 2.3, 0.1), new MeshBasicMaterial()); |
| 17 | body.position.z = -0.02; |
| 18 | const screen = new Mesh(new PlaneGeometry(1, 2.2), new MeshBasicMaterial()); |
| 19 | screen.geometry.translate(0, 0, 0.043); |
| 20 | screen.name = "device-screen"; |
| 21 | root.add(body, screen); |
| 22 | return { root, screen, body }; |
| 23 | } |
| 24 | |
| 25 | it("rejects touches from the rear and preserves borrowed textures when releasing imported resources", () => { |
| 26 | const { root, screen, body } = asset(); |
| 27 | const texture = new Texture(); |
| 28 | const borrowed = vi.spyOn(texture, "dispose"); |
| 29 | const ownedTexture = new Texture(); |
| 30 | const owned = vi.spyOn(ownedTexture, "dispose"); |
| 31 | body.material.map = ownedTexture; |
| 32 | const geometry = vi.spyOn(body.geometry, "dispose"); |
| 33 | const phone = createImportedPhoneScene(root, texture, phoneDisplayLayout(null, 1206, 2622)); |
| 34 | const camera = new PerspectiveCamera(32, 1, 0.1, 30); |
| 35 | camera.position.z = 6; |
| 36 | phone.root.rotation.y = Math.PI; |
| 37 | expect(phone.screenPoint(0.5, 0.5, camera)).toBeNull(); |
| 38 | phone.dispose(); |
| 39 | expect(borrowed).not.toHaveBeenCalled(); |
| 40 | expect(geometry).not.toHaveBeenCalled(); |
| 41 | expect(screen.material.map).toBeNull(); |
| 42 | disposeDeviceModel(root); |
| 43 | expect(owned).toHaveBeenCalledOnce(); |
| 44 | expect(geometry).toHaveBeenCalledOnce(); |
| 45 | expect(borrowed).not.toHaveBeenCalled(); |
| 46 | texture.dispose(); |
| 47 | }); |
| 48 | |
| 49 | it("rejects missing and incorrectly normalized displays before changing their materials", () => { |
| 50 | const { root, screen } = asset(); |
| 51 | const original = screen.material; |
| 52 | const texture = new Texture(); |
| 53 | screen.geometry.scale(1, 2, 1); |
| 54 | expect(() => |
| 55 | createImportedPhoneScene(root, texture, phoneDisplayLayout(null, 1206, 2622)), |
| 56 | ).toThrow("not normalized"); |
| 57 | expect(screen.material).toBe(original); |
| 58 | screen.geometry.scale(1, 0.5, 1); |
| 59 | root.rotation.y = Math.PI; |
| 60 | expect(() => |
| 61 | createImportedPhoneScene(root, texture, phoneDisplayLayout(null, 1206, 2622)), |
| 62 | ).toThrow("not normalized"); |
| 63 | expect(screen.material).toBe(original); |
| 64 | screen.name = "wrong-screen"; |
| 65 | expect(() => |
| 66 | createImportedPhoneScene(root, texture, phoneDisplayLayout(null, 1206, 2622)), |
| 67 | ).toThrow("one device-screen"); |
| 68 | disposeDeviceModel(root); |
| 69 | texture.dispose(); |
| 70 | }); |