test(joystick): update fixture to direction-style xValue / yValue
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.
This commit is contained in:
parent
e6fdd54ba3
commit
2eb195d671
|
|
@ -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)
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue