From 2eb195d671e673442adf969a5315af55a143c98f Mon Sep 17 00:00:00 2001 From: David Montero Date: Fri, 22 May 2026 18:59:49 +0200 Subject: [PATCH] test(joystick): update fixture to direction-style xValue / yValue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous test fed `xValue: 0, yValue: 1023` to the analog-joystick handler and asserted X=0V, Y=5V. That was wrong for two reasons: 1. wokwi-analog-joystick emits direction (-1/0/+1), never 0..1023, so the fixture didn't match how the real component behaves. 2. The OLD `(value/1023) * vcc` mapping happened to produce 0V for 0 and 5V for 1023, so the broken test still passed against the broken handler — and now breaks against the correct one. Switch the fixture to `xValue: -1, yValue: 1` so the expectations line up with the corrected handler (-1 → 0V, +1 → Vcc) and exercise the same voltage rails the real component will produce. --- frontend/src/__tests__/simulation-parts.test.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/frontend/src/__tests__/simulation-parts.test.ts b/frontend/src/__tests__/simulation-parts.test.ts index 2bd7ed45..47a886c4 100644 --- a/frontend/src/__tests__/simulation-parts.test.ts +++ b/frontend/src/__tests__/simulation-parts.test.ts @@ -743,9 +743,12 @@ describe('Analog-joystick — attachEvents', () => { }); it('updates ADC voltages on joystick-move event', () => { + // wokwi-analog-joystick exposes xValue / yValue as direction {-1, 0, +1}, + // NOT 0..1023. The handler maps -1 → 0V, 0 → Vcc/2, +1 → Vcc. + // AVR mock simulator → Vcc = 5V. const logic = PartSimulationRegistry.get('analog-joystick')!; const adc = makeADC(); - const el = makeElement({ xValue: 0, yValue: 1023 }); + const el = makeElement({ xValue: -1, yValue: 1 }); const sim = makeSimulator(adc); let moveHandler!: () => void; @@ -758,8 +761,8 @@ describe('Analog-joystick — attachEvents', () => { logic.attachEvents!(el, sim as any, pinMap({ VRX: 14, VRY: 15 })); moveHandler(); - expect(adc.channelValues[0]).toBeCloseTo(0.0, 1); // X at min = 0V - expect(adc.channelValues[1]).toBeCloseTo(5.0, 1); // Y at max = 5V + expect(adc.channelValues[0]).toBeCloseTo(0.0, 1); // X = -1 → 0V (full left) + expect(adc.channelValues[1]).toBeCloseTo(5.0, 1); // Y = +1 → 5V (full down) }); });