|
1 | 1 | import { describe, expect, it } from 'vitest'; |
2 | 2 | import { |
3 | 3 | calculateNativeScrollDelta, |
| 4 | + calculateDisplayNormalizedMouseTarget, |
4 | 5 | calculateScaledMouseTarget, |
5 | 6 | toLibnutKeyboardKey, |
6 | 7 | toLibnutMouseToggle |
@@ -33,6 +34,112 @@ describe('calculateScaledMouseTarget', () => { |
33 | 34 | }); |
34 | 35 | }); |
35 | 36 |
|
| 37 | +describe('calculateDisplayNormalizedMouseTarget', () => { |
| 38 | + it('uses 1080p as the reference display size', () => { |
| 39 | + expect( |
| 40 | + calculateDisplayNormalizedMouseTarget( |
| 41 | + { x: 100, y: 200 }, |
| 42 | + { dx: 128, dy: -64 }, |
| 43 | + { bounds: { x: 0, y: 0, width: 1920, height: 1080 }, scaleFactor: 1 } |
| 44 | + ) |
| 45 | + ).toEqual({ |
| 46 | + x: 228, |
| 47 | + y: 136 |
| 48 | + }); |
| 49 | + }); |
| 50 | + |
| 51 | + it('applies larger native movement on a 4K display at 1x scale', () => { |
| 52 | + expect( |
| 53 | + calculateDisplayNormalizedMouseTarget( |
| 54 | + { x: 100, y: 200 }, |
| 55 | + { dx: 128, dy: 0 }, |
| 56 | + { bounds: { x: 0, y: 0, width: 3840, height: 2160 }, scaleFactor: 1 } |
| 57 | + ) |
| 58 | + ).toEqual({ |
| 59 | + x: 356, |
| 60 | + y: 200 |
| 61 | + }); |
| 62 | + }); |
| 63 | + |
| 64 | + it('combines high-DPI logical deltas with display resolution normalization', () => { |
| 65 | + expect( |
| 66 | + calculateDisplayNormalizedMouseTarget( |
| 67 | + { x: 100, y: 200 }, |
| 68 | + { dx: 64, dy: 0 }, |
| 69 | + { bounds: { x: 0, y: 0, width: 3840, height: 2160 }, scaleFactor: 2 } |
| 70 | + ) |
| 71 | + ).toEqual({ |
| 72 | + x: 356, |
| 73 | + y: 200 |
| 74 | + }); |
| 75 | + }); |
| 76 | + |
| 77 | + it('uses the display short edge for ultrawide displays', () => { |
| 78 | + expect( |
| 79 | + calculateDisplayNormalizedMouseTarget( |
| 80 | + { x: 100, y: 200 }, |
| 81 | + { dx: 128, dy: 0 }, |
| 82 | + { bounds: { x: 0, y: 0, width: 3440, height: 1440 }, scaleFactor: 1 } |
| 83 | + ) |
| 84 | + ).toEqual({ |
| 85 | + x: 271, |
| 86 | + y: 200 |
| 87 | + }); |
| 88 | + }); |
| 89 | + |
| 90 | + it('accounts for fractional scale factors', () => { |
| 91 | + expect( |
| 92 | + calculateDisplayNormalizedMouseTarget( |
| 93 | + { x: 100, y: 200 }, |
| 94 | + { dx: 102, dy: 0 }, |
| 95 | + { bounds: { x: 0, y: 0, width: 2560, height: 1440 }, scaleFactor: 1.25 } |
| 96 | + ) |
| 97 | + ).toEqual({ |
| 98 | + x: 270, |
| 99 | + y: 200 |
| 100 | + }); |
| 101 | + }); |
| 102 | + |
| 103 | + it('handles displays with negative coordinates', () => { |
| 104 | + expect( |
| 105 | + calculateDisplayNormalizedMouseTarget( |
| 106 | + { x: -300, y: 100 }, |
| 107 | + { dx: 128, dy: 64 }, |
| 108 | + { bounds: { x: -3840, y: 0, width: 3840, height: 2160 }, scaleFactor: 1 } |
| 109 | + ) |
| 110 | + ).toEqual({ |
| 111 | + x: -44, |
| 112 | + y: 228 |
| 113 | + }); |
| 114 | + }); |
| 115 | + |
| 116 | + it('falls back to the reference size for invalid bounds', () => { |
| 117 | + expect( |
| 118 | + calculateDisplayNormalizedMouseTarget( |
| 119 | + { x: 10, y: 20 }, |
| 120 | + { dx: 5, dy: 6 }, |
| 121 | + { bounds: { x: 0, y: 0, width: 0, height: 2160 }, scaleFactor: 1 } |
| 122 | + ) |
| 123 | + ).toEqual({ |
| 124 | + x: 15, |
| 125 | + y: 26 |
| 126 | + }); |
| 127 | + }); |
| 128 | + |
| 129 | + it('falls back to scale 1 for invalid scale values', () => { |
| 130 | + expect( |
| 131 | + calculateDisplayNormalizedMouseTarget( |
| 132 | + { x: 10, y: 20 }, |
| 133 | + { dx: 5, dy: 6 }, |
| 134 | + { bounds: { x: 0, y: 0, width: 1920, height: 1080 }, scaleFactor: 0 } |
| 135 | + ) |
| 136 | + ).toEqual({ |
| 137 | + x: 15, |
| 138 | + y: 26 |
| 139 | + }); |
| 140 | + }); |
| 141 | +}); |
| 142 | + |
36 | 143 | describe('calculateNativeScrollDelta', () => { |
37 | 144 | it('scales vertical scroll by the native multiplier', () => { |
38 | 145 | expect(calculateNativeScrollDelta({ dx: 0, dy: 5 })).toEqual({ |
|
0 commit comments