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