From f739f963c79c06b87e688e1b6dacd0f12de9d0eb Mon Sep 17 00:00:00 2001 From: AdrianoDev Date: Mon, 21 Sep 2026 22:46:45 +0200 Subject: [PATCH] fix(base): auto-logout ignora le letture del solo calibro (#37 punto 2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/frontend/flask_app/templates/base.html | 6 ++++- .../tests/test_base_inactivity_keydown.py | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/frontend/flask_app/tests/test_base_inactivity_keydown.py diff --git a/src/frontend/flask_app/templates/base.html b/src/frontend/flask_app/templates/base.html index 5177d96..abe9db4 100644 --- a/src/frontend/flask_app/templates/base.html +++ b/src/frontend/flask_app/templates/base.html @@ -138,7 +138,11 @@ 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 }); }); }, diff --git a/src/frontend/flask_app/tests/test_base_inactivity_keydown.py b/src/frontend/flask_app/tests/test_base_inactivity_keydown.py new file mode 100644 index 0000000..e8e873c --- /dev/null +++ b/src/frontend/flask_app/tests/test_base_inactivity_keydown.py @@ -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