1488 lines
69 KiB
Python
1488 lines
69 KiB
Python
"""
|
||
Tests für die Onboarding Review Sub-Phases (Phase 3-4).
|
||
|
||
Prüft:
|
||
- render_review_room_step: Rendering der Raum-Liste
|
||
- render_review_room_edit: Rendering der Edit-Ansicht
|
||
- render_review_room_keywords_edit: Rendering der Keyword-Edit-Ansicht
|
||
- render_review_room_theme_edit: Rendering der Theme-Edit-Ansicht
|
||
- render_review_room_catch_all_toggle: Rendering des Catch-All-Dialogs
|
||
- render_review_room_remove: Rendering des Remove-Dialogs
|
||
- render_review_room_add_new: Rendering der Add-New-Ansicht
|
||
- dispatch_review_button: Button-Dispatch
|
||
- build_review_state: State-Dict-Bau
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import json
|
||
import tempfile
|
||
from pathlib import Path
|
||
|
||
import pytest
|
||
|
||
import sys
|
||
sys.path.insert(0, str(Path(__file__).resolve().parents[3]))
|
||
|
||
from plugin.archivar.room_map import RoomMap
|
||
from plugin.archivar.onboarding_review import (
|
||
render_review_room_step,
|
||
render_review_room_edit,
|
||
render_review_room_keywords_edit,
|
||
render_review_room_theme_edit,
|
||
render_review_room_catch_all_toggle,
|
||
render_review_room_remove,
|
||
render_review_room_add_new,
|
||
dispatch_review_button,
|
||
build_review_state,
|
||
REVIEW_ROOM_EDIT,
|
||
REVIEW_ROOM_KW_ADD,
|
||
REVIEW_ROOM_KW_REMOVE,
|
||
REVIEW_ROOM_THEME_SAVE,
|
||
REVIEW_ROOM_CATCHALL_SET,
|
||
REVIEW_ROOM_REMOVE_CONFIRM,
|
||
REVIEW_ROOM_BACK,
|
||
REVIEW_ROOM_ADD_NEW,
|
||
REVIEW_ROOM_SKIP,
|
||
SUB_PHASE_EDIT,
|
||
SUB_PHASE_KEYWORDS_EDIT,
|
||
SUB_PHASE_THEME_EDIT,
|
||
SUB_PHASE_CATCHALL_TOGGLE,
|
||
SUB_PHASE_REMOVE,
|
||
SUB_PHASE_ADD_NEW,
|
||
)
|
||
|
||
|
||
# ── Helpers ────────────────────────────────────────────────────────────────
|
||
|
||
|
||
def _make_map_json(rooms: list[dict] | None = None, excluded: list[str] | None = None) -> str:
|
||
data: dict = {
|
||
"version": 1,
|
||
"rooms": {},
|
||
"excluded_rooms": excluded or [],
|
||
"fact_store_path": "/tmp/test_docs",
|
||
}
|
||
for room in (rooms or []):
|
||
room_data = {
|
||
"name": room["name"],
|
||
"theme": room.get("theme", ""),
|
||
"catch_all": room.get("catch_all", False),
|
||
}
|
||
if "keywords_100" in room or "keywords_context" in room:
|
||
room_data["keywords_100"] = room.get("keywords_100", [])
|
||
room_data["keywords_context"] = room.get("keywords_context", [])
|
||
else:
|
||
room_data["keywords"] = room.get("keywords", [])
|
||
data["rooms"][room["room_id"]] = room_data
|
||
return json.dumps(data)
|
||
|
||
|
||
def _tmp_map(content: str) -> Path:
|
||
tmp = tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False, encoding="utf-8")
|
||
tmp.write(content)
|
||
tmp.close()
|
||
return Path(tmp.name)
|
||
|
||
|
||
def _load_room_map(rooms: list[dict], excluded: list[str] | None = None) -> RoomMap:
|
||
json_str = _make_map_json(rooms=rooms, excluded=excluded)
|
||
path = _tmp_map(json_str)
|
||
try:
|
||
return RoomMap.load(path)
|
||
finally:
|
||
path.unlink(missing_ok=True)
|
||
|
||
|
||
def _mock_build_buttons(labels, prefix="", style="default"):
|
||
"""Mock für _build_custom_buttons."""
|
||
buttons = []
|
||
for label in labels:
|
||
buttons.append({
|
||
"text": label,
|
||
"msg": f"{prefix}::{label}" if prefix else label,
|
||
"style": style,
|
||
})
|
||
return buttons
|
||
|
||
|
||
# ── build_review_state ─────────────────────────────────────────────────────
|
||
|
||
|
||
class TestBuildReviewState:
|
||
"""build_review_state() — State-Dict-Bau."""
|
||
|
||
def test_builds_basic_state(self):
|
||
state = build_review_state(phase="review_room", operator_room_id="dm123")
|
||
assert state["phase"] == "review_room"
|
||
assert state["operator_room_id"] == "dm123"
|
||
assert state["sub_phase"] is None
|
||
assert state["target_room_id"] is None
|
||
assert state["edit_kind"] is None
|
||
assert state["pending_text_input"] is False
|
||
|
||
def test_builds_sub_phase_state(self):
|
||
state = build_review_state(
|
||
phase="review_room",
|
||
operator_room_id="dm123",
|
||
sub_phase="keywords_edit",
|
||
target_room_id="r1",
|
||
edit_kind="keywords_100",
|
||
pending_text_input=True,
|
||
)
|
||
assert state["sub_phase"] == "keywords_edit"
|
||
assert state["target_room_id"] == "r1"
|
||
assert state["edit_kind"] == "keywords_100"
|
||
assert state["pending_text_input"] is True
|
||
|
||
|
||
# ── render_review_room_step ─────────────────────────────────────────────────
|
||
|
||
|
||
class TestRenderReviewRoomStep:
|
||
"""render_review_room_step() — Schritt 1 Top-Level."""
|
||
|
||
def test_renders_room_list(self):
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "Entwicklung", "keywords_100": ["code", "bug"], "keywords_context": ["git"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "Betrieb", "keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
text, attachments = render_review_room_step(rm, "dm123", _mock_build_buttons)
|
||
assert "Schritt 1 von 4" in text
|
||
assert "#Dev" in text
|
||
assert "#Ops" in text
|
||
assert "Catch-All" in text
|
||
assert "code" in text
|
||
assert "bug" in text
|
||
assert len(attachments) == 2 # 1 nummeriert + 1 special (Neuer/Skip)
|
||
assert len(attachments[0]["actions"]) >= 2 # 2 rooms in erster Reihe
|
||
|
||
def test_renders_empty_room_list(self):
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"], "catch_all": True},
|
||
])
|
||
text, attachments = render_review_room_step(rm, "dm123", _mock_build_buttons)
|
||
assert "keine Räume eingerichtet" not in text.lower() or "#Dev" in text
|
||
|
||
def test_excludes_excluded_rooms(self):
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops", "keywords": ["server"], "catch_all": True},
|
||
], excluded=["r1"])
|
||
text, attachments = render_review_room_step(rm, "dm123", _mock_build_buttons)
|
||
assert "#Dev" not in text
|
||
assert "#Ops" in text
|
||
|
||
|
||
# ── render_review_room_edit ─────────────────────────────────────────────────
|
||
|
||
|
||
class TestRenderReviewRoomEdit:
|
||
"""render_review_room_edit() — Edit-Ansicht."""
|
||
|
||
def test_renders_edit_view(self):
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "Entwicklung", "keywords_100": ["code", "bug"], "keywords_context": ["git"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "Betrieb", "keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
text, attachments = render_review_room_edit(rm, "r1", _mock_build_buttons)
|
||
assert "#Dev" in text
|
||
assert "Entwicklung" in text
|
||
assert "code" in text
|
||
assert "1️⃣ Kw100" in str(attachments)
|
||
assert "3️⃣ Theme" in str(attachments)
|
||
assert "4️⃣ Catch" in str(attachments)
|
||
assert "5️⃣ Lösch" in str(attachments)
|
||
assert "Zurück" in str(attachments)
|
||
|
||
def test_handles_nonexistent_room(self):
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"], "catch_all": True},
|
||
])
|
||
text, attachments = render_review_room_edit(rm, "r_nonexistent", _mock_build_buttons)
|
||
assert "nicht gefunden" in text
|
||
|
||
|
||
# ── render_review_room_keywords_edit ────────────────────────────────────────
|
||
|
||
|
||
class TestRenderReviewRoomKeywordsEdit:
|
||
"""render_review_room_keywords_edit() — Keyword-Edit-Ansicht."""
|
||
|
||
def test_renders_keywords_list(self):
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords_100": ["code", "bug", "test"], "keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops", "keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
text, attachments = render_review_room_keywords_edit(rm, "r1", _mock_build_buttons)
|
||
assert "Kw100 bearbeiten" in text
|
||
assert "code" in text
|
||
assert "bug" in text
|
||
assert "test" in text
|
||
# Pro Keyword ein X-Button
|
||
assert "Zurück" in str(attachments)
|
||
|
||
def test_renders_empty_keywords(self):
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords_100": [], "keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops", "keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
text, attachments = render_review_room_keywords_edit(rm, "r1", _mock_build_buttons)
|
||
assert "keine" in text.lower()
|
||
|
||
def test_warns_on_many_keywords(self):
|
||
"""R5: Warnung bei >30 Keywords."""
|
||
many_kw = [f"kw{i}" for i in range(35)]
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords_100": many_kw, "keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops", "keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
text, attachments = render_review_room_keywords_edit(rm, "r1", _mock_build_buttons)
|
||
assert "verlangsamen" in text.lower()
|
||
|
||
|
||
# ── render_review_room_theme_edit ───────────────────────────────────────────
|
||
|
||
|
||
class TestRenderReviewRoomThemeEdit:
|
||
"""render_review_room_theme_edit() — Theme-Edit-Ansicht."""
|
||
|
||
def test_renders_theme_edit(self):
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "Altes Theme", "keywords_100": ["code"], "keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops", "keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
text, attachments = render_review_room_theme_edit(rm, "r1", _mock_build_buttons)
|
||
assert "Theme bearbeiten" in text
|
||
assert "Altes Theme" in text
|
||
assert "Zurück" in str(attachments)
|
||
|
||
|
||
# ── render_review_room_catch_all_toggle ─────────────────────────────────────
|
||
|
||
|
||
class TestRenderReviewRoomCatchAllToggle:
|
||
"""render_review_room_catch_all_toggle() — Catch-All-Dialog."""
|
||
|
||
def test_renders_toggle_for_non_catch_all(self):
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops", "keywords": ["server"], "catch_all": True},
|
||
])
|
||
text, attachments = render_review_room_catch_all_toggle(rm, "r1", _mock_build_buttons)
|
||
assert "Catch-All-Raum setzen" in text
|
||
assert "#Ops" in text # aktueller Catch-All
|
||
assert "✅ Setzen" in str(attachments)
|
||
|
||
def test_renders_toggle_for_already_catch_all(self):
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"], "catch_all": True},
|
||
])
|
||
text, attachments = render_review_room_catch_all_toggle(rm, "r1", _mock_build_buttons)
|
||
assert "bereits der Catch-All-Raum" in text
|
||
|
||
|
||
# ── render_review_room_remove ───────────────────────────────────────────────
|
||
|
||
|
||
class TestRenderReviewRoomRemove:
|
||
"""render_review_room_remove() — Remove-Dialog."""
|
||
|
||
def test_renders_remove_dialog(self):
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops", "keywords": ["server"], "catch_all": True},
|
||
])
|
||
text, attachments = render_review_room_remove(rm, "r1", _mock_build_buttons)
|
||
assert "wirklich entfernen" in text
|
||
assert "🗑️ Ja" in str(attachments)
|
||
assert "Abbrechen" in str(attachments)
|
||
|
||
def test_rejects_catch_all_removal(self):
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"], "catch_all": True},
|
||
])
|
||
text, attachments = render_review_room_remove(rm, "r1", _mock_build_buttons)
|
||
assert "Catch-All-Raum" in text
|
||
assert "nicht entfernt werden" in text
|
||
|
||
|
||
# ── render_review_room_add_new ──────────────────────────────────────────────
|
||
|
||
|
||
class TestRenderReviewRoomAddNew:
|
||
"""render_review_room_add_new() — Add-New-Ansicht."""
|
||
|
||
def test_renders_available_rooms(self):
|
||
available = [
|
||
{"id": "new1", "name": "#NewRoom", "type": "c"},
|
||
{"id": "new2", "name": "DM User", "type": "d"},
|
||
]
|
||
text, attachments = render_review_room_add_new(available, _mock_build_buttons)
|
||
assert "Neuer Raum hinzufügen" in text
|
||
assert "#NewRoom" in text
|
||
assert "DM User" in text
|
||
assert "Zurück" in str(attachments)
|
||
|
||
def test_renders_empty_available(self):
|
||
text, attachments = render_review_room_add_new([], _mock_build_buttons)
|
||
assert "Keine weiteren Räume verfügbar" in text
|
||
# P0-4: Zurück-Button muss auch bei leerer Liste gerendert werden
|
||
assert len(attachments) > 0, "Leere Liste muss Zurück-Button rendern"
|
||
assert "Zurück" in str(attachments)
|
||
|
||
|
||
# ── dispatch_review_button ──────────────────────────────────────────────────
|
||
|
||
|
||
class TestDispatchReviewButton:
|
||
"""dispatch_review_button() — Button-Dispatch."""
|
||
|
||
def _make_state(self, **kwargs):
|
||
base = {
|
||
"phase": "review_room",
|
||
"operator_room_id": "dm123",
|
||
"sub_phase": None,
|
||
"target_room_id": None,
|
||
"edit_kind": None,
|
||
"pending_text_input": False,
|
||
}
|
||
base.update(kwargs)
|
||
return base
|
||
|
||
def _make_archivar_mock(self, room_map):
|
||
"""Mock-Archivar mit room_map und room_index=None."""
|
||
class MockArchivar:
|
||
_room_map = room_map
|
||
_room_index = None
|
||
return MockArchivar()
|
||
|
||
def test_dispatch_edit_button(self):
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords_100": ["code"], "keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops", "keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
state = self._make_state()
|
||
archivar = self._make_archivar_mock(rm)
|
||
payload = f"{REVIEW_ROOM_EDIT}::r1::edit"
|
||
handled, text, attachments = dispatch_review_button(
|
||
payload, state, rm, archivar, _mock_build_buttons, None
|
||
)
|
||
assert handled is True
|
||
assert state["sub_phase"] == SUB_PHASE_EDIT
|
||
assert state["target_room_id"] == "r1"
|
||
assert "#Dev" in text
|
||
|
||
def test_dispatch_kw_add_button(self):
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords_100": ["code"], "keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops", "keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
state = self._make_state()
|
||
archivar = self._make_archivar_mock(rm)
|
||
payload = f"{REVIEW_ROOM_KW_ADD}::r1"
|
||
handled, text, attachments = dispatch_review_button(
|
||
payload, state, rm, archivar, _mock_build_buttons, None
|
||
)
|
||
assert handled is True
|
||
assert state["sub_phase"] == SUB_PHASE_KEYWORDS_EDIT
|
||
assert state["pending_text_input"] is True
|
||
|
||
def test_dispatch_kw_remove_button(self, monkeypatch):
|
||
"""Keyword wird via Dispatch entfernt."""
|
||
import tempfile, os
|
||
tmpdir = tempfile.mkdtemp()
|
||
tmp_map = os.path.join(tmpdir, "room-map.json")
|
||
monkeypatch.setenv("ARCHIVAR_ROOM_MAP_PATH", tmp_map)
|
||
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords_100": ["code", "bug"], "keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops", "keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
state = self._make_state()
|
||
archivar = self._make_archivar_mock(rm)
|
||
payload = f"{REVIEW_ROOM_KW_REMOVE}::r1::bug"
|
||
handled, text, attachments = dispatch_review_button(
|
||
payload, state, rm, archivar, _mock_build_buttons, None
|
||
)
|
||
assert handled is True
|
||
assert "bug" not in rm.get_room_by_id("r1").keywords_100
|
||
|
||
def test_dispatch_theme_save_button(self):
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords_100": ["code"], "keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops", "keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
state = self._make_state()
|
||
archivar = self._make_archivar_mock(rm)
|
||
payload = f"{REVIEW_ROOM_THEME_SAVE}::r1"
|
||
handled, text, attachments = dispatch_review_button(
|
||
payload, state, rm, archivar, _mock_build_buttons, None
|
||
)
|
||
assert handled is True
|
||
assert state["sub_phase"] == SUB_PHASE_THEME_EDIT
|
||
assert state["pending_text_input"] is True
|
||
|
||
def test_back_button_not_intercepted_by_text_input(self):
|
||
"""P0: Bei pending_text_input=True wird Button-Klick als Button dispatch, NICHT als Keyword-Freitext."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords_100": ["code"], "keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops", "keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
# Simuliere: User ist in keywords_edit Sub-Phase, pending_text_input=True
|
||
state = self._make_state(
|
||
sub_phase=SUB_PHASE_KEYWORDS_EDIT,
|
||
target_room_id="r1",
|
||
edit_kind="keywords_100",
|
||
pending_text_input=True,
|
||
)
|
||
archivar = self._make_archivar_mock(rm)
|
||
# Klick auf "↩️ Zurück" sendet REVIEW_ROOM_EDIT::r1::edit
|
||
payload = f"{REVIEW_ROOM_EDIT}::r1::edit"
|
||
handled, text, attachments = dispatch_review_button(
|
||
payload, state, rm, archivar, _mock_build_buttons, None
|
||
)
|
||
# Soll als Button behandelt werden, NICHT als Keyword
|
||
assert handled is True
|
||
# State muss auf edit Sub-Phase zurückgesetzt sein
|
||
assert state["sub_phase"] == SUB_PHASE_EDIT
|
||
assert state["pending_text_input"] is False
|
||
# Keywords unverändert (kein "REVIEW_ROOM_EDIT::r1::edit" als Keyword)
|
||
assert rm.get_room_by_id("r1").keywords_100 == ["code"]
|
||
|
||
def test_dispatch_catch_all_toggle(self):
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops", "keywords": ["server"], "catch_all": True},
|
||
])
|
||
state = self._make_state()
|
||
archivar = self._make_archivar_mock(rm)
|
||
payload = f"{REVIEW_ROOM_CATCHALL_SET}::r1"
|
||
handled, text, attachments = dispatch_review_button(
|
||
payload, state, rm, archivar, _mock_build_buttons, None
|
||
)
|
||
assert handled is True
|
||
assert state["sub_phase"] == SUB_PHASE_CATCHALL_TOGGLE
|
||
|
||
def test_dispatch_catch_all_confirm(self, monkeypatch):
|
||
"""Catch-All-Wechsel via Dispatch."""
|
||
import tempfile, os
|
||
tmpdir = tempfile.mkdtemp()
|
||
tmp_map = os.path.join(tmpdir, "room-map.json")
|
||
monkeypatch.setenv("ARCHIVAR_ROOM_MAP_PATH", tmp_map)
|
||
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops", "keywords": ["server"], "catch_all": True},
|
||
])
|
||
state = self._make_state()
|
||
archivar = self._make_archivar_mock(rm)
|
||
payload = f"{REVIEW_ROOM_CATCHALL_SET}::r1::confirm"
|
||
handled, text, attachments = dispatch_review_button(
|
||
payload, state, rm, archivar, _mock_build_buttons, None
|
||
)
|
||
assert handled is True
|
||
assert rm.get_room_by_id("r1").catch_all is True
|
||
assert rm.get_room_by_id("r2").catch_all is False
|
||
|
||
def test_dispatch_remove_confirm(self, monkeypatch):
|
||
"""Raum-Entfernung via Dispatch."""
|
||
import tempfile, os
|
||
tmpdir = tempfile.mkdtemp()
|
||
tmp_map = os.path.join(tmpdir, "room-map.json")
|
||
monkeypatch.setenv("ARCHIVAR_ROOM_MAP_PATH", tmp_map)
|
||
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops", "keywords": ["server"], "catch_all": True},
|
||
])
|
||
state = self._make_state()
|
||
archivar = self._make_archivar_mock(rm)
|
||
payload = f"{REVIEW_ROOM_REMOVE_CONFIRM}::r1::confirm"
|
||
handled, text, attachments = dispatch_review_button(
|
||
payload, state, rm, archivar, _mock_build_buttons, None
|
||
)
|
||
assert handled is True
|
||
assert "r1" in rm.excluded_room_ids
|
||
|
||
def test_dispatch_back_button(self):
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops", "keywords": ["server"], "catch_all": True},
|
||
])
|
||
state = self._make_state(sub_phase="edit", target_room_id="r1")
|
||
archivar = self._make_archivar_mock(rm)
|
||
handled, text, attachments = dispatch_review_button(
|
||
REVIEW_ROOM_BACK, state, rm, archivar, _mock_build_buttons, None
|
||
)
|
||
assert handled is True
|
||
assert state["sub_phase"] is None
|
||
assert state["target_room_id"] is None
|
||
|
||
def test_dispatch_skip_returns_false(self):
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"], "catch_all": True},
|
||
])
|
||
state = self._make_state()
|
||
archivar = self._make_archivar_mock(rm)
|
||
handled, text, attachments = dispatch_review_button(
|
||
REVIEW_ROOM_SKIP, state, rm, archivar, _mock_build_buttons, None
|
||
)
|
||
assert handled is False # Adapter leitet weiter
|
||
|
||
def test_dispatch_unknown_returns_false(self):
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"], "catch_all": True},
|
||
])
|
||
state = self._make_state()
|
||
archivar = self._make_archivar_mock(rm)
|
||
handled, text, attachments = dispatch_review_button(
|
||
"UNKNOWN_PREFIX::something", state, rm, archivar, _mock_build_buttons, None
|
||
)
|
||
assert handled is False
|
||
|
||
# ── O2: REVIEW_ROOM_ADD_NEW Dispatch ────────────────────────────────
|
||
|
||
def test_dispatch_add_new_no_room_id(self):
|
||
"""O2: REVIEW_ROOM_ADD_NEW ohne room_id → setzt sub_phase=add_new."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"], "catch_all": True},
|
||
])
|
||
state = self._make_state()
|
||
archivar = self._make_archivar_mock(rm)
|
||
handled, text, attachments = dispatch_review_button(
|
||
REVIEW_ROOM_ADD_NEW, state, rm, archivar, _mock_build_buttons, None
|
||
)
|
||
assert handled is True
|
||
assert state["sub_phase"] == SUB_PHASE_ADD_NEW
|
||
assert state["edit_kind"] == "add"
|
||
# Adapter macht REST-Call + Rendering → dispatch liefert leeren text
|
||
assert text == ""
|
||
|
||
def test_dispatch_add_new_with_room_id_and_name(self, monkeypatch):
|
||
"""O2: REVIEW_ROOM_ADD_NEW::<rid> mit available_rooms → nutzt echten Namen."""
|
||
import tempfile, os
|
||
tmpdir = tempfile.mkdtemp()
|
||
tmp_map = os.path.join(tmpdir, "room-map.json")
|
||
monkeypatch.setenv("ARCHIVAR_ROOM_MAP_PATH", tmp_map)
|
||
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"], "catch_all": True},
|
||
])
|
||
state = self._make_state(available_rooms=[
|
||
{"id": "new_room", "name": "#Marketing", "type": "c"},
|
||
])
|
||
archivar = self._make_archivar_mock(rm)
|
||
payload = f"{REVIEW_ROOM_ADD_NEW}::new_room"
|
||
handled, text, attachments = dispatch_review_button(
|
||
payload, state, rm, archivar, _mock_build_buttons, None
|
||
)
|
||
assert handled is True
|
||
assert state["sub_phase"] is None # Zurück zur Hauptliste
|
||
assert "#Marketing" in text # Echter Name in Bestätigung
|
||
assert "new_room" in rm.rooms # Raum wurde hinzugefügt
|
||
assert rm.get_room_by_id("new_room").name == "#Marketing"
|
||
|
||
def test_dispatch_add_new_with_room_id_fallback_name(self, monkeypatch):
|
||
"""O2: REVIEW_ROOM_ADD_NEW::<rid> ohne available_rooms → Fallback auf ID."""
|
||
import tempfile, os
|
||
tmpdir = tempfile.mkdtemp()
|
||
tmp_map = os.path.join(tmpdir, "room-map.json")
|
||
monkeypatch.setenv("ARCHIVAR_ROOM_MAP_PATH", tmp_map)
|
||
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"], "catch_all": True},
|
||
])
|
||
state = self._make_state() # Kein available_rooms
|
||
archivar = self._make_archivar_mock(rm)
|
||
payload = f"{REVIEW_ROOM_ADD_NEW}::new_room"
|
||
handled, text, attachments = dispatch_review_button(
|
||
payload, state, rm, archivar, _mock_build_buttons, None
|
||
)
|
||
assert handled is True
|
||
assert "new_room" in rm.rooms # Raum wurde hinzugefügt
|
||
assert rm.get_room_by_id("new_room").name == "new_room" # Fallback: ID als Name
|
||
|
||
def test_dispatch_add_new_multiple_rooms(self, monkeypatch):
|
||
"""O2: REVIEW_ROOM_ADD_NEW mit mehreren Räumen in available_rooms."""
|
||
import tempfile, os
|
||
tmpdir = tempfile.mkdtemp()
|
||
tmp_map = os.path.join(tmpdir, "room-map.json")
|
||
monkeypatch.setenv("ARCHIVAR_ROOM_MAP_PATH", tmp_map)
|
||
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"], "catch_all": True},
|
||
])
|
||
state = self._make_state(available_rooms=[
|
||
{"id": "room_a", "name": "#Alpha", "type": "c"},
|
||
{"id": "room_b", "name": "#Beta", "type": "c"},
|
||
{"id": "room_c", "name": "#Gamma", "type": "c"},
|
||
])
|
||
archivar = self._make_archivar_mock(rm)
|
||
# Füge room_b hinzu
|
||
payload = f"{REVIEW_ROOM_ADD_NEW}::room_b"
|
||
handled, text, attachments = dispatch_review_button(
|
||
payload, state, rm, archivar, _mock_build_buttons, None
|
||
)
|
||
assert handled is True
|
||
assert "room_b" in rm.rooms
|
||
assert rm.get_room_by_id("room_b").name == "#Beta"
|
||
assert "#Beta" in text
|
||
|
||
|
||
# ── UX-7: Button-Label-Kürzung Tests ────────────────────────────────────────
|
||
|
||
|
||
class TestButtonLabelsShort:
|
||
"""UX-7: Alle Button-Labels sind <=13 Zeichen (ohne Prefix)."""
|
||
|
||
def _extract_labels(self, attachments):
|
||
"""Extrahiert alle Button-Label-Texte aus Attachments."""
|
||
labels = []
|
||
for att in attachments:
|
||
for action in att.get("actions", []):
|
||
labels.append(action.get("text", ""))
|
||
return labels
|
||
|
||
def test_room_edit_buttons_short(self):
|
||
"""Raum-Detail Buttons sind kurz."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "Entwicklung",
|
||
"keywords_100": ["code", "bug"], "keywords_context": ["git"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "Betrieb",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_edit(rm, "r1", _mock_build_buttons)
|
||
labels = self._extract_labels(attachments)
|
||
for label in labels:
|
||
assert len(label) <= 13, f"Label zu lang: '{label}' ({len(label)} Zeichen)"
|
||
|
||
def test_keyword_x_buttons_short(self):
|
||
"""Keyword-X-Buttons sind kurz (max 8 Zeichen Keyword)."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["dokumentation", "lan", "code"], "keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_keywords_edit(rm, "r1", _mock_build_buttons)
|
||
labels = self._extract_labels(attachments)
|
||
for label in labels:
|
||
assert len(label) <= 13, f"Label zu lang: '{label}' ({len(label)} Zeichen)"
|
||
|
||
def test_top_level_buttons_short(self):
|
||
"""Top-Level Buttons (Neuer, Skip) sind kurz."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_step(rm, "dm123", _mock_build_buttons)
|
||
labels = self._extract_labels(attachments)
|
||
for label in labels:
|
||
assert len(label) <= 13, f"Label zu lang: '{label}' ({len(label)} Zeichen)"
|
||
|
||
def test_catchall_buttons_short(self):
|
||
"""Catch-All Toggle Buttons sind kurz."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords": ["server"], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_catch_all_toggle(rm, "r1", _mock_build_buttons)
|
||
labels = self._extract_labels(attachments)
|
||
for label in labels:
|
||
assert len(label) <= 13, f"Label zu lang: '{label}' ({len(label)} Zeichen)"
|
||
|
||
def test_remove_buttons_short(self):
|
||
"""Remove Buttons sind kurz."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords": ["server"], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_remove(rm, "r1", _mock_build_buttons)
|
||
labels = self._extract_labels(attachments)
|
||
for label in labels:
|
||
assert len(label) <= 13, f"Label zu lang: '{label}' ({len(label)} Zeichen)"
|
||
|
||
def test_add_new_buttons_short(self):
|
||
"""Add-New Buttons (Neuer Raum) sind kurz."""
|
||
available = [
|
||
{"id": "new1", "name": "#Marketing", "type": "c"},
|
||
{"id": "new2", "name": "DM User", "type": "d"},
|
||
]
|
||
_, attachments = render_review_room_add_new(available, _mock_build_buttons)
|
||
labels = self._extract_labels(attachments)
|
||
for label in labels:
|
||
assert len(label) <= 13, f"Label zu lang: '{label}' ({len(label)} Zeichen)"
|
||
|
||
def test_long_room_name_button_short(self):
|
||
"""Regression-Guard: Langer Raumname (20+ Zeichen) → Button-Label <=13 Zeichen."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#SehrLangerRaumnameMitVielenZeichen",
|
||
"theme": "dev", "keywords_100": ["code"], "keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_step(rm, "dm123", _mock_build_buttons)
|
||
labels = self._extract_labels(attachments)
|
||
for label in labels:
|
||
assert len(label) <= 13, f"Label zu lang: '{label}' ({len(label)} Zeichen)"
|
||
|
||
|
||
class TestKeywordEditHasBackButton:
|
||
"""UX-7: Keyword-Bearbeitung hat Zurück-Button."""
|
||
|
||
def test_keyword_edit_has_back_button(self):
|
||
"""render_review_room_keywords_edit enthält '↩️ Zurück' Button."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code", "bug"], "keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_keywords_edit(rm, "r1", _mock_build_buttons)
|
||
labels = [a.get("text", "") for att in attachments for a in att.get("actions", [])]
|
||
assert "↩️ Zurück" in labels, f"Kein Zurück-Button in: {labels}"
|
||
|
||
def test_keyword_edit_text_mentions_back(self):
|
||
"""Keyword-Edit Text erwähnt 'Zurück'."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code"], "keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
text, _ = render_review_room_keywords_edit(rm, "r1", _mock_build_buttons)
|
||
assert "Zurück" in text, f"Text erwähnt Zurück nicht: {text[:200]}"
|
||
|
||
|
||
class TestAllSubphasesHaveBack:
|
||
"""UX-7: Alle Sub-Phasen haben Zurück-Button."""
|
||
|
||
def _has_back_button(self, attachments):
|
||
"""Prüft ob Attachments einen '↩️ Zurück' oder '↩️ Abbrechen' Button enthalten."""
|
||
for att in attachments:
|
||
for action in att.get("actions", []):
|
||
text = action.get("text", "")
|
||
if "Zurück" in text or "Abbrechen" in text:
|
||
return True
|
||
return False
|
||
|
||
def test_edit_subphase_has_back(self):
|
||
"""review_room_edit hat Zurück-Button."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code"], "keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_edit(rm, "r1", _mock_build_buttons)
|
||
assert self._has_back_button(attachments), "edit sub-phase fehlt Zurück-Button"
|
||
|
||
def test_keywords_edit_subphase_has_back(self):
|
||
"""review_room_keywords_edit hat Zurück-Button."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code"], "keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_keywords_edit(rm, "r1", _mock_build_buttons)
|
||
assert self._has_back_button(attachments), "keywords_edit sub-phase fehlt Zurück-Button"
|
||
|
||
def test_theme_edit_subphase_has_back(self):
|
||
"""review_room_theme_edit hat Zurück-Button."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "Altes Theme",
|
||
"keywords_100": ["code"], "keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_theme_edit(rm, "r1", _mock_build_buttons)
|
||
assert self._has_back_button(attachments), "theme_edit sub-phase fehlt Zurück-Button"
|
||
|
||
def test_catchall_toggle_subphase_has_back(self):
|
||
"""review_room_catch_all_toggle hat Zurück-Button."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords": ["server"], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_catch_all_toggle(rm, "r1", _mock_build_buttons)
|
||
assert self._has_back_button(attachments), "catch_all_toggle sub-phase fehlt Zurück-Button"
|
||
|
||
def test_remove_subphase_has_back(self):
|
||
"""review_room_remove hat Abbrechen-Button."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords": ["server"], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_remove(rm, "r1", _mock_build_buttons)
|
||
assert self._has_back_button(attachments), "remove sub-phase fehlt Abbrechen-Button"
|
||
|
||
def test_add_new_subphase_has_back(self):
|
||
"""review_room_add_new hat Zurück-Button."""
|
||
available = [{"id": "new1", "name": "#NewRoom", "type": "c"}]
|
||
_, attachments = render_review_room_add_new(available, _mock_build_buttons)
|
||
assert self._has_back_button(attachments), "add_new sub-phase fehlt Zurück-Button"
|
||
|
||
|
||
# ── KwKontext Tests (P0: Vollständige Implementierung) ────────────────────
|
||
|
||
|
||
class TestAddKeywordContext:
|
||
"""RoomMap.add_keyword_context() — Keyword zu keywords_context hinzufügen."""
|
||
|
||
def test_add_keyword_context_adds_to_list(self):
|
||
"""Keyword wird zu keywords_context hinzugefügt."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code"], "keywords_context": ["git"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
result = rm.add_keyword_context("r1", "docker")
|
||
assert result is True
|
||
assert "docker" in rm.get_room_by_id("r1").keywords_context
|
||
|
||
def test_add_keyword_context_normalizes_lowercase(self):
|
||
"""Keyword wird lowercase normalisiert."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code"], "keywords_context": ["git"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
result = rm.add_keyword_context("r1", "DOCKER")
|
||
assert result is True
|
||
assert "docker" in rm.get_room_by_id("r1").keywords_context
|
||
|
||
def test_add_keyword_context_rejects_too_short(self):
|
||
"""Keyword mit <2 Zeichen wird abgelehnt."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code"], "keywords_context": ["git"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
result = rm.add_keyword_context("r1", "X")
|
||
assert result is False
|
||
assert "x" not in rm.get_room_by_id("r1").keywords_context
|
||
|
||
def test_add_keyword_context_rejects_too_long(self):
|
||
"""Keyword mit >30 Zeichen wird abgelehnt."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code"], "keywords_context": ["git"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
result = rm.add_keyword_context("r1", "a" * 31)
|
||
assert result is False
|
||
|
||
def test_add_keyword_context_rejects_duplicate(self):
|
||
"""Doppeltes Keyword wird abgelehnt."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code"], "keywords_context": ["git", "docker"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
result = rm.add_keyword_context("r1", "docker")
|
||
assert result is False
|
||
|
||
def test_add_keyword_context_rejects_nonexistent_room(self):
|
||
"""Nicht-existente room_id gibt False zurück."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code"], "keywords_context": ["git"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
result = rm.add_keyword_context("r_nonexistent", "test")
|
||
assert result is False
|
||
|
||
|
||
class TestRemoveKeywordContext:
|
||
"""RoomMap.remove_keyword_context() — Keyword aus keywords_context entfernen."""
|
||
|
||
def test_remove_keyword_context_removes_from_list(self):
|
||
"""Keyword wird aus keywords_context entfernt."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code"], "keywords_context": ["git", "docker"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
result = rm.remove_keyword_context("r1", "docker")
|
||
assert result is True
|
||
assert "docker" not in rm.get_room_by_id("r1").keywords_context
|
||
assert "git" in rm.get_room_by_id("r1").keywords_context
|
||
|
||
def test_remove_keyword_context_returns_false_if_not_present(self):
|
||
"""Nicht vorhandenes Keyword gibt False zurück."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code"], "keywords_context": ["git"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
result = rm.remove_keyword_context("r1", "nonexistent")
|
||
assert result is False
|
||
|
||
def test_remove_keyword_context_returns_false_for_nonexistent_room(self):
|
||
"""Nicht-existente room_id gibt False zurück."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code"], "keywords_context": ["git"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
result = rm.remove_keyword_context("r_nonexistent", "test")
|
||
assert result is False
|
||
|
||
|
||
class TestKeywordsContextSubphaseRenders:
|
||
"""UI zeigt Kontext-Keywords + X-Buttons + Textfeld."""
|
||
|
||
def test_renders_context_keywords_list(self):
|
||
"""render_review_room_keywords_edit mit edit_kind=keywords_context."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code"], "keywords_context": ["git", "docker", "ci"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
text, attachments = render_review_room_keywords_edit(
|
||
rm, "r1", _mock_build_buttons, edit_kind="keywords_context",
|
||
)
|
||
assert "KwKontext bearbeiten" in text
|
||
assert "git" in text
|
||
assert "docker" in text
|
||
assert "ci" in text
|
||
assert "Zurück" in str(attachments)
|
||
|
||
def test_renders_empty_context_keywords(self):
|
||
"""Leere Kontext-Keywords zeigen '(keine)'."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code"], "keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
text, attachments = render_review_room_keywords_edit(
|
||
rm, "r1", _mock_build_buttons, edit_kind="keywords_context",
|
||
)
|
||
assert "keine" in text.lower()
|
||
|
||
def test_context_keywords_has_back_button(self):
|
||
"""Kontext-Keywords Sub-Phase hat Zurück-Button."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code"], "keywords_context": ["git"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_keywords_edit(
|
||
rm, "r1", _mock_build_buttons, edit_kind="keywords_context",
|
||
)
|
||
labels = [a.get("text", "") for att in attachments for a in att.get("actions", [])]
|
||
assert "↩️ Zurück" in labels
|
||
|
||
|
||
class TestKeywordsContextDispatch:
|
||
"""Button-Klick routed korrekt für keywords_context."""
|
||
|
||
def _make_state(self, **kwargs):
|
||
base = {
|
||
"phase": "review_room",
|
||
"operator_room_id": "dm123",
|
||
"sub_phase": None,
|
||
"target_room_id": None,
|
||
"edit_kind": None,
|
||
"pending_text_input": False,
|
||
}
|
||
base.update(kwargs)
|
||
return base
|
||
|
||
def _make_archivar_mock(self, room_map):
|
||
class MockArchivar:
|
||
_room_map = room_map
|
||
_room_index = None
|
||
return MockArchivar()
|
||
|
||
def test_dispatch_kw_context_edit_button(self):
|
||
"""REVIEW_ROOM_EDIT::rid::keywords_context öffnet KwKontext Sub-Phase."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code"], "keywords_context": ["git"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
state = self._make_state()
|
||
archivar = self._make_archivar_mock(rm)
|
||
payload = f"{REVIEW_ROOM_EDIT}::r1::keywords_context"
|
||
handled, text, attachments = dispatch_review_button(
|
||
payload, state, rm, archivar, _mock_build_buttons, None
|
||
)
|
||
assert handled is True
|
||
assert state["sub_phase"] == SUB_PHASE_KEYWORDS_EDIT
|
||
assert state["edit_kind"] == "keywords_context"
|
||
assert state["pending_text_input"] is True
|
||
assert "KwKontext bearbeiten" in text
|
||
|
||
def test_dispatch_kw_context_remove_button(self, monkeypatch):
|
||
"""REVIEW_ROOM_KW_REMOVE entfernt Kontext-Keyword wenn edit_kind=keywords_context."""
|
||
import tempfile, os
|
||
tmpdir = tempfile.mkdtemp()
|
||
tmp_map = os.path.join(tmpdir, "room-map.json")
|
||
monkeypatch.setenv("ARCHIVAR_ROOM_MAP_PATH", tmp_map)
|
||
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code"], "keywords_context": ["git", "docker"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
state = self._make_state(edit_kind="keywords_context")
|
||
archivar = self._make_archivar_mock(rm)
|
||
payload = f"{REVIEW_ROOM_KW_REMOVE}::r1::docker"
|
||
handled, text, attachments = dispatch_review_button(
|
||
payload, state, rm, archivar, _mock_build_buttons, None
|
||
)
|
||
assert handled is True
|
||
assert "docker" not in rm.get_room_by_id("r1").keywords_context
|
||
assert "git" in rm.get_room_by_id("r1").keywords_context
|
||
|
||
def test_dispatch_kw_context_remove_nonexistent(self, monkeypatch):
|
||
"""Nicht-vorhandenes Kontext-Keyword gibt Fehlermeldung."""
|
||
import tempfile, os
|
||
tmpdir = tempfile.mkdtemp()
|
||
tmp_map = os.path.join(tmpdir, "room-map.json")
|
||
monkeypatch.setenv("ARCHIVAR_ROOM_MAP_PATH", tmp_map)
|
||
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code"], "keywords_context": ["git"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
state = self._make_state(edit_kind="keywords_context")
|
||
archivar = self._make_archivar_mock(rm)
|
||
payload = f"{REVIEW_ROOM_KW_REMOVE}::r1::nonexistent"
|
||
handled, text, attachments = dispatch_review_button(
|
||
payload, state, rm, archivar, _mock_build_buttons, None
|
||
)
|
||
assert handled is True
|
||
assert "nicht gefunden" in text
|
||
|
||
def test_text_input_keywords_context(self):
|
||
"""Text-Input im KwKontext-Flow ruft add_keyword_context (NICHT add_keyword_100)."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code"], "keywords_context": ["git"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
# Simuliere den Text-Input-Handler: edit_kind=keywords_context
|
||
edit_kind = "keywords_context"
|
||
if edit_kind == "keywords_context":
|
||
result = rm.add_keyword_context("r1", "neues-kw")
|
||
else:
|
||
result = rm.add_keyword_100("r1", "neues-kw")
|
||
assert result is True
|
||
assert "neues-kw" in rm.get_room_by_id("r1").keywords_context
|
||
assert "neues-kw" not in rm.get_room_by_id("r1").keywords_100
|
||
|
||
def test_text_input_keywords_100(self):
|
||
"""Text-Input im Kw100-Flow ruft add_keyword_100 (NICHT add_keyword_context)."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code"], "keywords_context": ["git"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
# Simuliere den Text-Input-Handler: edit_kind=keywords_100 (default)
|
||
edit_kind = "keywords_100"
|
||
if edit_kind == "keywords_context":
|
||
result = rm.add_keyword_context("r1", "neues-kw")
|
||
else:
|
||
result = rm.add_keyword_100("r1", "neues-kw")
|
||
assert result is True
|
||
assert "neues-kw" in rm.get_room_by_id("r1").keywords_100
|
||
assert "neues-kw" not in rm.get_room_by_id("r1").keywords_context
|
||
|
||
|
||
# ═══════════════════════════════════════════════════════════════════════════════
|
||
# UX REFACTOR: 2-Reihen-Button-Pattern Tests (Andreas' Spezifikation)
|
||
# ═══════════════════════════════════════════════════════════════════════════════
|
||
|
||
# Import build_button_attachments — wird erst nach Implementierung existieren
|
||
try:
|
||
from plugin.archivar.onboarding_review import build_button_attachments
|
||
_HAS_BUILD_BUTTON_ATTACHMENTS = True
|
||
except ImportError:
|
||
_HAS_BUILD_BUTTON_ATTACHMENTS = False
|
||
|
||
|
||
class TestBuildButtonAttachments:
|
||
"""build_button_attachments() — zentrale Helper-Funktion."""
|
||
|
||
@pytest.mark.skipif(not _HAS_BUILD_BUTTON_ATTACHMENTS,
|
||
reason="build_button_attachments noch nicht implementiert")
|
||
def test_splits_into_rows_of_max_3(self):
|
||
"""5 nummerierte Buttons → 2 Attachments (3 + 2)."""
|
||
num_buttons = [
|
||
("Kw100", "REVIEW_ROOM_KW_ADD::r1"),
|
||
("KwKtx", "REVIEW_ROOM_EDIT::r1::keywords_context"),
|
||
("Theme", "REVIEW_ROOM_THEME_SAVE::r1"),
|
||
("Catch", "REVIEW_ROOM_CATCHALL_SET::r1"),
|
||
("Lösch", "REVIEW_ROOM_REMOVE_CONFIRM::r1"),
|
||
]
|
||
special_buttons = [("↩️ Zurück", "REVIEW_ROOM_BACK", "default")]
|
||
attachments = build_button_attachments(num_buttons, special_buttons)
|
||
assert len(attachments) == 3 # 3+2 nummeriert + 1 special
|
||
assert len(attachments[0]["actions"]) == 3
|
||
assert len(attachments[1]["actions"]) == 2
|
||
assert len(attachments[2]["actions"]) == 1 # Zurück
|
||
|
||
@pytest.mark.skipif(not _HAS_BUILD_BUTTON_ATTACHMENTS,
|
||
reason="build_button_attachments noch nicht implementiert")
|
||
def test_no_attachment_exceeds_3_actions(self):
|
||
"""Kein Attachment hat >3 actions."""
|
||
num_buttons = [
|
||
(f"Btn{i}", f"PREFIX::btn{i}") for i in range(1, 8)
|
||
]
|
||
special_buttons = [("↩️ Zurück", "REVIEW_ROOM_BACK", "default")]
|
||
attachments = build_button_attachments(num_buttons, special_buttons)
|
||
for att in attachments:
|
||
assert len(att["actions"]) <= 3, \
|
||
f"Attachment hat {len(att['actions'])} actions (>3)"
|
||
|
||
@pytest.mark.skipif(not _HAS_BUILD_BUTTON_ATTACHMENTS,
|
||
reason="build_button_attachments noch nicht implementiert")
|
||
def test_numbers_sequential(self):
|
||
"""Nummerierte Buttons haben fortlaufende Nummern 1️⃣ 2️⃣ 3️⃣..."""
|
||
num_buttons = [
|
||
("A", "PREFIX::a"),
|
||
("B", "PREFIX::b"),
|
||
("C", "PREFIX::c"),
|
||
("D", "PREFIX::d"),
|
||
]
|
||
special_buttons = []
|
||
attachments = build_button_attachments(num_buttons, special_buttons)
|
||
all_labels = []
|
||
for att in attachments:
|
||
for action in att["actions"]:
|
||
all_labels.append(action["text"])
|
||
assert "1️⃣ A" in all_labels
|
||
assert "2️⃣ B" in all_labels
|
||
assert "3️⃣ C" in all_labels
|
||
assert "4️⃣ D" in all_labels
|
||
|
||
@pytest.mark.skipif(not _HAS_BUILD_BUTTON_ATTACHMENTS,
|
||
reason="build_button_attachments noch nicht implementiert")
|
||
def test_special_buttons_no_numbers(self):
|
||
"""Sonderschaltflächen haben KEINE Nummern."""
|
||
num_buttons = [("Test", "PREFIX::test")]
|
||
special_buttons = [
|
||
("↩️ Zurück", "REVIEW_ROOM_BACK", "default"),
|
||
("⏭️ Skip", "REVIEW_ROOM_SKIP", "default"),
|
||
]
|
||
attachments = build_button_attachments(num_buttons, special_buttons)
|
||
special_att = attachments[-1]
|
||
for action in special_att["actions"]:
|
||
label = action["text"]
|
||
for num_emoji in ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣"]:
|
||
assert num_emoji not in label, \
|
||
f"Special button '{label}' hat Nummer {num_emoji}"
|
||
|
||
@pytest.mark.skipif(not _HAS_BUILD_BUTTON_ATTACHMENTS,
|
||
reason="build_button_attachments noch nicht implementiert")
|
||
def test_special_buttons_in_separate_attachment(self):
|
||
"""Sonderschaltflächen sind im letzten Attachment."""
|
||
num_buttons = [
|
||
("A", "PREFIX::a"),
|
||
("B", "PREFIX::b"),
|
||
]
|
||
special_buttons = [("↩️ Zurück", "REVIEW_ROOM_BACK", "default")]
|
||
attachments = build_button_attachments(num_buttons, special_buttons)
|
||
last_att = attachments[-1]
|
||
assert "↩️ Zurück" in [a["text"] for a in last_att["actions"]]
|
||
|
||
@pytest.mark.skipif(not _HAS_BUILD_BUTTON_ATTACHMENTS,
|
||
reason="build_button_attachments noch nicht implementiert")
|
||
def test_only_special_buttons(self):
|
||
"""Nur Sonderschaltflächen → 1 Attachment."""
|
||
num_buttons = []
|
||
special_buttons = [("↩️ Zurück", "REVIEW_ROOM_BACK", "default")]
|
||
attachments = build_button_attachments(num_buttons, special_buttons)
|
||
assert len(attachments) == 1
|
||
assert len(attachments[0]["actions"]) == 1
|
||
|
||
@pytest.mark.skipif(not _HAS_BUILD_BUTTON_ATTACHMENTS,
|
||
reason="build_button_attachments noch nicht implementiert")
|
||
def test_only_numbered_buttons(self):
|
||
"""Nur nummerierte Buttons → korrekte Aufteilung."""
|
||
num_buttons = [
|
||
("A", "PREFIX::a"),
|
||
("B", "PREFIX::b"),
|
||
("C", "PREFIX::c"),
|
||
("D", "PREFIX::d"),
|
||
]
|
||
special_buttons = []
|
||
attachments = build_button_attachments(num_buttons, special_buttons)
|
||
assert len(attachments) == 2 # 3 + 1
|
||
assert len(attachments[0]["actions"]) == 3
|
||
assert len(attachments[1]["actions"]) == 1
|
||
|
||
|
||
class TestButtonRowsMax3:
|
||
"""Regel 2: Kein Attachment hat >3 actions (Integrationstests)."""
|
||
|
||
def _max_actions_per_attachment(self, attachments):
|
||
return max((len(att.get("actions", [])) for att in attachments), default=0)
|
||
|
||
def test_room_edit_max_3_per_row(self):
|
||
"""render_review_room_edit: max 3 actions pro Attachment."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "Entwicklung",
|
||
"keywords_100": ["code", "bug"], "keywords_context": ["git"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "Betrieb",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_edit(rm, "r1", _mock_build_buttons)
|
||
max_actions = self._max_actions_per_attachment(attachments)
|
||
assert max_actions <= 3, f"render_review_room_edit: max {max_actions} actions in einem Attachment"
|
||
|
||
def test_keywords_edit_max_3_per_row(self):
|
||
"""render_review_room_keywords_edit: max 3 actions pro Attachment."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code", "bug", "test", "deploy", "ci", "docker", "git"],
|
||
"keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_keywords_edit(rm, "r1", _mock_build_buttons)
|
||
max_actions = self._max_actions_per_attachment(attachments)
|
||
assert max_actions <= 3, f"render_review_room_keywords_edit: max {max_actions} actions in einem Attachment"
|
||
|
||
def test_catchall_toggle_max_3_per_row(self):
|
||
"""render_review_room_catch_all_toggle: max 3 actions pro Attachment."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords": ["server"], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_catch_all_toggle(rm, "r1", _mock_build_buttons)
|
||
max_actions = self._max_actions_per_attachment(attachments)
|
||
assert max_actions <= 3, f"render_review_room_catch_all_toggle: max {max_actions} actions in einem Attachment"
|
||
|
||
def test_remove_max_3_per_row(self):
|
||
"""render_review_room_remove: max 3 actions pro Attachment."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords": ["server"], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_remove(rm, "r1", _mock_build_buttons)
|
||
max_actions = self._max_actions_per_attachment(attachments)
|
||
assert max_actions <= 3, f"render_review_room_remove: max {max_actions} actions in einem Attachment"
|
||
|
||
def test_room_step_max_3_per_row(self):
|
||
"""render_review_room_step: max 3 actions pro Attachment."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords_100": ["code"], "keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops", "keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
{"room_id": "r3", "name": "#QA", "theme": "qa", "keywords_100": ["test"], "keywords_context": []},
|
||
{"room_id": "r4", "name": "#HR", "theme": "hr", "keywords_100": ["people"], "keywords_context": []},
|
||
])
|
||
_, attachments = render_review_room_step(rm, "dm123", _mock_build_buttons)
|
||
max_actions = self._max_actions_per_attachment(attachments)
|
||
assert max_actions <= 3, f"render_review_room_step: max {max_actions} actions in einem Attachment"
|
||
|
||
def test_add_new_max_3_per_row(self):
|
||
"""render_review_room_add_new: max 3 actions pro Attachment."""
|
||
available = [
|
||
{"id": "new1", "name": "#Alpha", "type": "c"},
|
||
{"id": "new2", "name": "#Beta", "type": "c"},
|
||
{"id": "new3", "name": "#Gamma", "type": "c"},
|
||
{"id": "new4", "name": "#Delta", "type": "c"},
|
||
]
|
||
_, attachments = render_review_room_add_new(available, _mock_build_buttons)
|
||
max_actions = self._max_actions_per_attachment(attachments)
|
||
assert max_actions <= 3, f"render_review_room_add_new: max {max_actions} actions in einem Attachment"
|
||
|
||
|
||
class TestNumbersInText:
|
||
"""Regel 1: Nummern im Nachrichtentext UND auf Schaltflächen."""
|
||
|
||
def test_room_edit_numbers_in_text(self):
|
||
"""render_review_room_edit: Text enthält 1️⃣-5️⃣."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "Entwicklung",
|
||
"keywords_100": ["code", "bug"], "keywords_context": ["git"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "Betrieb",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
text, _ = render_review_room_edit(rm, "r1", _mock_build_buttons)
|
||
assert "1️⃣" in text, "Text enthält nicht 1️⃣"
|
||
assert "2️⃣" in text, "Text enthält nicht 2️⃣"
|
||
assert "3️⃣" in text, "Text enthält nicht 3️⃣"
|
||
assert "4️⃣" in text, "Text enthält nicht 4️⃣"
|
||
assert "5️⃣" in text, "Text enthält nicht 5️⃣"
|
||
|
||
def test_room_edit_numbers_on_buttons(self):
|
||
"""render_review_room_edit: Buttons haben 1️⃣-5️⃣."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "Entwicklung",
|
||
"keywords_100": ["code", "bug"], "keywords_context": ["git"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "Betrieb",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_edit(rm, "r1", _mock_build_buttons)
|
||
all_labels = []
|
||
for att in attachments:
|
||
for action in att.get("actions", []):
|
||
all_labels.append(action.get("text", ""))
|
||
all_text = " ".join(all_labels)
|
||
assert "1️⃣" in all_text, f"Buttons enthalten nicht 1️⃣: {all_labels}"
|
||
assert "2️⃣" in all_text, f"Buttons enthalten nicht 2️⃣: {all_labels}"
|
||
assert "3️⃣" in all_text, f"Buttons enthalten nicht 3️⃣: {all_labels}"
|
||
assert "4️⃣" in all_text, f"Buttons enthalten nicht 4️⃣: {all_labels}"
|
||
assert "5️⃣" in all_text, f"Buttons enthalten nicht 5️⃣: {all_labels}"
|
||
|
||
|
||
class TestSpecialButtonsSeparateRow:
|
||
"""Regel 3: Sonderschaltflächen in separater Reihe."""
|
||
|
||
def _get_special_labels(self, attachments):
|
||
"""Extrahiert Labels aus dem letzten Attachment."""
|
||
if not attachments:
|
||
return []
|
||
return [a.get("text", "") for a in attachments[-1].get("actions", [])]
|
||
|
||
def test_room_edit_back_in_separate_row(self):
|
||
"""render_review_room_edit: ↩️ Zurück in separatem Attachment."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "Entwicklung",
|
||
"keywords_100": ["code", "bug"], "keywords_context": ["git"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "Betrieb",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_edit(rm, "r1", _mock_build_buttons)
|
||
assert len(attachments) >= 2, f"Nur {len(attachments)} Attachments, erwartet >=2"
|
||
special_labels = self._get_special_labels(attachments)
|
||
assert "↩️ Zurück" in special_labels, \
|
||
f"↩️ Zurück nicht in letztem Attachment: {special_labels}"
|
||
|
||
def test_keywords_edit_back_in_separate_row(self):
|
||
"""render_review_room_keywords_edit: ↩️ Zurück in separatem Attachment."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code", "bug", "test", "deploy"],
|
||
"keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_keywords_edit(rm, "r1", _mock_build_buttons)
|
||
assert len(attachments) >= 2, f"Nur {len(attachments)} Attachments, erwartet >=2"
|
||
special_labels = self._get_special_labels(attachments)
|
||
assert "↩️ Zurück" in special_labels, \
|
||
f"↩️ Zurück nicht in letztem Attachment: {special_labels}"
|
||
|
||
def test_catchall_toggle_back_in_separate_row(self):
|
||
"""render_review_room_catch_all_toggle: ↩️ Zurück in separatem Attachment."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords": ["server"], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_catch_all_toggle(rm, "r1", _mock_build_buttons)
|
||
assert len(attachments) >= 2, f"Nur {len(attachments)} Attachments, erwartet >=2"
|
||
special_labels = self._get_special_labels(attachments)
|
||
assert "↩️ Zurück" in special_labels, \
|
||
f"↩️ Zurück nicht in letztem Attachment: {special_labels}"
|
||
|
||
def test_remove_back_in_separate_row(self):
|
||
"""render_review_room_remove: ↩️ Abbrechen in separatem Attachment."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords": ["code"]},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords": ["server"], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_remove(rm, "r1", _mock_build_buttons)
|
||
assert len(attachments) >= 2, f"Nur {len(attachments)} Attachments, erwartet >=2"
|
||
special_labels = self._get_special_labels(attachments)
|
||
assert "↩️ Abbrechen" in special_labels, \
|
||
f"↩️ Abbrechen nicht in letztem Attachment: {special_labels}"
|
||
|
||
def test_room_step_special_in_separate_row(self):
|
||
"""render_review_room_step: ➕ Neuer + ⏭️ Skip in separatem Attachment."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev", "keywords_100": ["code"], "keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops", "keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_step(rm, "dm123", _mock_build_buttons)
|
||
assert len(attachments) >= 2, f"Nur {len(attachments)} Attachments, erwartet >=2"
|
||
special_labels = self._get_special_labels(attachments)
|
||
assert "➕ Neuer" in special_labels or "⏭️ Skip" in special_labels, \
|
||
f"Sonderschaltflächen nicht in letztem Attachment: {special_labels}"
|
||
|
||
def test_add_new_back_in_separate_row(self):
|
||
"""render_review_room_add_new: ↩️ Zurück in separatem Attachment."""
|
||
available = [
|
||
{"id": "new1", "name": "#Alpha", "type": "c"},
|
||
{"id": "new2", "name": "#Beta", "type": "c"},
|
||
]
|
||
_, attachments = render_review_room_add_new(available, _mock_build_buttons)
|
||
assert len(attachments) >= 2, f"Nur {len(attachments)} Attachments, erwartet >=2"
|
||
special_labels = self._get_special_labels(attachments)
|
||
assert "↩️ Zurück" in special_labels, \
|
||
f"↩️ Zurück nicht in letztem Attachment: {special_labels}"
|
||
|
||
|
||
class TestKeywordXButtonsNotNumbered:
|
||
"""Keyword-X-Buttons haben KEINE Nummern (Regel 1 Ausnahme)."""
|
||
|
||
def test_keyword_x_buttons_no_numbers(self):
|
||
"""render_review_room_keywords_edit: X-Buttons ohne Nummern-Emoji."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["code", "bug", "test"],
|
||
"keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_keywords_edit(rm, "r1", _mock_build_buttons)
|
||
x_labels = []
|
||
for att in attachments:
|
||
for action in att.get("actions", []):
|
||
label = action.get("text", "")
|
||
if "❌" in label:
|
||
x_labels.append(label)
|
||
assert len(x_labels) >= 3, f"Erwartet >=3 X-Buttons, gefunden: {x_labels}"
|
||
for label in x_labels:
|
||
for num_emoji in ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟"]:
|
||
assert num_emoji not in label, \
|
||
f"X-Button '{label}' hat Nummer {num_emoji}"
|
||
|
||
def test_keyword_x_buttons_in_3er_blocks(self):
|
||
"""render_review_room_keywords_edit: 7 Keywords → 3+3+1 X-Buttons + Zurück."""
|
||
rm = _load_room_map([
|
||
{"room_id": "r1", "name": "#Dev", "theme": "dev",
|
||
"keywords_100": ["a", "b", "c", "d", "e", "f", "g"],
|
||
"keywords_context": []},
|
||
{"room_id": "r2", "name": "#Ops", "theme": "ops",
|
||
"keywords_100": ["server"], "keywords_context": [], "catch_all": True},
|
||
])
|
||
_, attachments = render_review_room_keywords_edit(rm, "r1", _mock_build_buttons)
|
||
assert len(attachments) >= 3, \
|
||
f"Erwartet >=3 Attachments (3+3+1 X + Zurück), gefunden: {len(attachments)}"
|
||
for att in attachments:
|
||
assert len(att["actions"]) <= 3, \
|
||
f"Attachment hat {len(att['actions'])} actions (>3)"
|