Skip to content

Commit 7596290

Browse files
committed
Fix haptics auto-stop tests to match preference-driven timeout behavior
Tests now explicitly set autoStopTimeoutSecs rather than expecting rebuildMaps() to auto-override it based on device class.
1 parent 04260cb commit 7596290

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/HapticsService.test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ describe("HapticsService", () => {
648648
expect(backend.stop).toHaveBeenCalled();
649649
});
650650

651-
it("uses 5s timeout when intimate devices are present", () => {
651+
it("respects configured timeout for intimate devices", () => {
652652
const buttplug = createMockBackend({
653653
name: "buttplug",
654654
deviceClass: "intimate",
@@ -657,6 +657,7 @@ describe("HapticsService", () => {
657657
],
658658
});
659659
service.registerBackend(buttplug);
660+
service.autoStopTimeoutSecs = 5; // Simulates preference wiring
660661

661662
const stoppedListener = vi.fn();
662663
service.on("stopped", stoppedListener);
@@ -674,7 +675,7 @@ describe("HapticsService", () => {
674675
expect(stoppedListener).toHaveBeenCalledWith("auto_stop");
675676
});
676677

677-
it("uses shorter intimate timeout when mixed classes are active", () => {
678+
it("does not override configured timeout when device classes change", () => {
678679
const gamepad = createMockBackend({
679680
name: "gamepad",
680681
deviceClass: "gaming",
@@ -690,14 +691,22 @@ describe("HapticsService", () => {
690691
],
691692
});
692693

694+
service.autoStopTimeoutSecs = 10; // User-configured preference
693695
service.registerBackend(gamepad);
694696
service.registerBackend(buttplug);
695697

698+
// Timeout should still be 10s, not auto-overridden
699+
expect(service.autoStopTimeoutSecs).toBe(10);
700+
696701
service.actuate([{ actuator: 0, type: "Vibrate", intensity: 0.5 }]);
697702
gamepad.stop.mockClear();
698703
buttplug.stop.mockClear();
699704

700-
// Should fire at 5s (intimate timeout), not 30s
705+
// Should NOT fire at 5s
706+
vi.advanceTimersByTime(5000);
707+
expect(gamepad.stop).not.toHaveBeenCalled();
708+
709+
// Should fire at 10s
701710
vi.advanceTimersByTime(5000);
702711
expect(gamepad.stop).toHaveBeenCalled();
703712
expect(buttplug.stop).toHaveBeenCalled();

0 commit comments

Comments
 (0)