fix(base): auto-logout ignora le letture del solo calibro (#37 punto 2)

L'inattività contava mousemove/mousedown/keypress/touchstart/scroll. Il
numpad fa preventDefault() su ogni cifra/Enter letta dal calibro USB, il che
sopprime anche il keypress successivo: un operatore che lavora solo di
calibro non generava alcuna attività e veniva disconnesso a metà task.
Aggiunto 'keydown' alla lista: scatta comunque, a prescindere dal
preventDefault() di un handler successivo sullo stesso evento.

Test: rendering di una pagina con auto_logout_minutes impostato, verifica
che l'elenco eventi contenga 'keydown'.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-21 22:46:45 +02:00
parent 31fa78bdfd
commit f739f963c7
2 changed files with 32 additions and 1 deletions
+5 -1
View File
@@ -138,7 +138,11 @@
self.showWarning = false; self.showWarning = false;
} }
}; };
['mousemove','mousedown','keypress','touchstart','scroll'].forEach(function(evt) { // 'keydown', not just 'keypress': the numpad calls preventDefault() on every
// digit/Enter it reads from the USB caliper, which also suppresses the
// keypress that would otherwise follow - an operator working only from the
// caliper produced no activity at all and was logged out mid-task (#37.2).
['mousemove','mousedown','keydown','keypress','touchstart','scroll'].forEach(function(evt) {
window.addEventListener(evt, handler, { passive: true }); window.addEventListener(evt, handler, { passive: true });
}); });
}, },
@@ -0,0 +1,27 @@
"""gitea:Adriano/TieMeasureFlow#37 (point 2).
base.html's auto-logout only counted activity through 'mousemove', 'mousedown',
'keypress', 'touchstart', 'scroll'. The numpad (static/js/numpad.js) calls
preventDefault() on every keydown it reads from the USB caliper, which also
suppresses the keypress that would otherwise follow: an operator working
purely from the caliper produced no activity at all in the inactivity timer's
eyes and was logged out mid-task. Adding 'keydown' to the list fixes it -
keydown always fires regardless of what a later handler does with
preventDefault().
"""
ACTIVITY_EVENTS = "['mousemove','mousedown','keydown','keypress','touchstart','scroll']"
def test_inactivity_timer_listens_for_keydown(logged_in_client, mock_api_client, monkeypatch):
with logged_in_client.session_transaction() as sess:
sess["language"] = "it"
sess["auto_logout_minutes"] = 15
monkeypatch.setattr("blueprints.measure.Config.STATION_CODE", "ST-TEST")
mock_api_client.get_station_recipes.return_value = []
resp = logged_in_client.get("/measure/select")
assert resp.status_code == 200
html = resp.get_data(as_text=True)
assert ACTIVITY_EVENTS in html