Files
uconsole_asw_game/tests/test_commander_station_keys_web.py
T
Claude 332f897756 Operating rules: Ctrl+Enter only fires, close boxes, lamp notes, APP-6 own symbols, German key names
B1: D/A/Z/R/Shift+R at Weapons and D on OPZ page 3 choose the weapon,
Ctrl+Enter fires it; the helicopter drops its torpedo on Ctrl+Enter only.
B3: close boxes on F7, language model settings, F8, F9, F11 and the
debrief; one x style for the browser's dialog close buttons.
B4: hover notes for the helicopter's rescue and acoustic lamps, sonar
contact freshness, engine master lamp and damage-control lamps; browser
lamp strips with notes on bridge, CIC, radio room and damage control.
B5: APP-6 frames by dimension (friend circle/dome/bowl, hostile and
neutral halves) and the own frigate as its friendly surface symbol.
B6 (part): German key names Umschalt, Strg, Eingabe, Ruecktaste.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 15:16:01 +00:00

71 lines
3.6 KiB
Python

"""Browser stations take the uConsole's keys and show them as key caps.
Dominik (2026-10-05): the browser should be operated like the uConsole, with
every key visible on its control, empty values shown quietly and the chart's
country names in the page's language, once per country.
"""
import json
from commander_web import run_module_probe
def test_station_keys_press_the_matching_control(tmp_path):
probe = r"""
import { S } from "./js/state/store.js";
import { $ } from "./js/core/base.js";
import { init, keyLabel, markStationKeys } from "./js/input/station-keys.js";
import { metrics } from "./js/views/dom.js";
import { countryName } from "./js/core/format.js";
const out = {};
const show = (element) => { for (let item = element; item; item = item.parentElement) item.hidden = false; };
S.language = "de";
S.catalog = {"commander.web.country_denmark": "Dänemark", "commander.web.station_none": "Keine Daten veröffentlicht.",
"commander.web.station_course": "Kurs"};
S.v2State = {role: "bridge"};
S.session = {station: "bridge"};
show($("operations")); show($("bridge-course")); show($("role-map-zoom-in"));
init();
out.cap_course = $("bridge-course-submit").dataset.keycap;
out.cap_zoom = $("role-map-zoom-in").dataset.keycap;
// Only the held station's keys carry caps.
out.cap_radar_bridge = $("opz-radar-surface").closest("label").dataset.keycap ?? null;
markStationKeys("opz");
// A checkbox shows its key on its enclosing label, never on the box itself.
out.cap_radar = $("opz-radar-surface").closest("label").dataset.keycap;
out.cap_on_box = $("opz-radar-surface").dataset.keycap ?? null;
out.cap_course_opz = $("bridge-course-submit").dataset.keycap ?? null;
markStationKeys("bridge");
out.label_fire = keyLabel("Ctrl+Enter", "de");
out.label_page = keyLabel("PageDown", "en");
document.body.dispatchEvent(new KeyboardEvent("keydown", {key: "c", bubbles: true}));
out.course_focused = document.activeElement === $("bridge-course");
// A key typed into a field stays in the field.
$("bridge-course").dispatchEvent(new KeyboardEvent("keydown", {key: "v", bubbles: true}));
out.speed_after_typing = document.activeElement === $("bridge-speed");
$("bridge-course").blur();
let zoomed = 0;
$("role-map-zoom-in").addEventListener("click", () => zoomed++);
document.body.dispatchEvent(new KeyboardEvent("keydown", {key: "e", bubbles: true}));
out.zoomed = zoomed;
// Another station's key does nothing here.
document.body.dispatchEvent(new KeyboardEvent("keydown", {key: "D", bubbles: true}));
out.depth_focused = document.activeElement === $("uboot-depth");
const dl = document.createElement("dl");
metrics(dl, [["station_course", "Keine Daten veröffentlicht."]]);
out.empty_text = dl.querySelector("dd").textContent;
out.empty_flag = dl.querySelector("dd").dataset.empty;
metrics(dl, [["station_course", "300 °"]]);
out.value_text = dl.querySelector("dd").textContent;
out.value_flag = dl.querySelector("dd").dataset.empty ?? null;
out.country = countryName("Denmark");
out.region = countryName("Britannia");
document.documentElement.dataset.result = JSON.stringify(out);
"""
root = run_module_probe(tmp_path, probe)
assert "data-result" in root, root.get("data-failure")
assert json.loads(root["data-result"]) == {
"cap_course": "C", "cap_zoom": "E", "cap_radar": "R", "cap_on_box": None, "cap_radar_bridge": None, "cap_course_opz": None, "label_fire": "Strg+Eingabe", "label_page": "PgDn",
"course_focused": True, "speed_after_typing": False, "zoomed": 1, "depth_focused": False,
"empty_text": "—", "empty_flag": "true", "value_text": "300 °", "value_flag": None,
"country": "Dänemark", "region": "Britannia"}