summaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/tests/test_group_tab_fallback.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/tests/test_group_tab_fallback.py')
-rw-r--r--packages/meshbay-hub/tests/test_group_tab_fallback.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/packages/meshbay-hub/tests/test_group_tab_fallback.py b/packages/meshbay-hub/tests/test_group_tab_fallback.py
new file mode 100644
index 0000000..6310b9c
--- /dev/null
+++ b/packages/meshbay-hub/tests/test_group_tab_fallback.py
@@ -0,0 +1,75 @@
+"""
+A group always opens on a tab that exists.
+
+The landing tab comes from a preference and is chosen at mount; which
+applications the group runs comes from the node, several awaits later. When the
+two disagree — Chat disabled here while 'chat' is the default, or a preferred
+app this group does not offer — the page used to render no panel at all, with
+no tab shown active and nothing on screen to explain it.
+
+A string comparison against a list that arrives later is not something reading
+`group-page.js` makes obvious, so this renders the real `GroupPage` against a
+stub node and reads the tab bar back.
+"""
+import json
+import shutil
+import subprocess
+from pathlib import Path
+
+import pytest
+
+HARNESS = Path(__file__).parent / "harness" / "group_tab_probe.py"
+STATIC = Path(__file__).resolve().parents[1] / "src" / "meshbay_hub" / "static"
+
+pytestmark = pytest.mark.skipif(
+ shutil.which("google-chrome") is None or not (STATIC / "group-page.js").exists(),
+ reason="Chrome or the SPA sources are not available")
+
+
+@pytest.fixture(scope="module")
+def cases():
+ run = subprocess.run(["python3", str(HARNESS)], capture_output=True, timeout=180)
+ assert run.returncode == 0, run.stderr.decode()[-2000:]
+ return {c["name"]: c for c in json.loads(run.stdout.decode())}
+
+
+# Asserted by position, not by label: the harness renders in whatever language
+# the browser resolves to.
+
+def test_every_case_lands_somewhere(cases):
+ """The bug, stated once: a tab bar with nothing selected and nothing under
+ it."""
+ for name, case in cases.items():
+ assert case["active"] >= 0, f"{name}: no tab is active"
+ assert case["panelDrawn"], f"{name}: a tab is active but no panel was drawn"
+
+
+def test_the_default_is_the_first_app(cases):
+ """Nothing changes for a group running everything."""
+ case = cases["every app, default chat"]
+ assert case["active"] == 0
+
+
+def test_a_disabled_default_falls_back(cases):
+ """'chat' is the default for everyone, and a group may not run it."""
+ case = cases["chat disabled"]
+ assert case["active"] == 0, "should have fallen back to the group's first app"
+ assert len(case["tabs"]) == 3, "Files, Videos and Settings, with no Chat tab"
+
+
+def test_a_preference_for_an_absent_app_falls_back(cases):
+ """The preference is global; the app list is per group."""
+ assert cases["preferred app absent"]["active"] == 0
+
+
+def test_a_preference_that_names_nothing_falls_back(cases):
+ """A stale or hand-edited preference must not strand anyone either."""
+ assert cases["preference names nothing real"]["active"] == 0
+
+
+def test_a_preference_the_group_offers_is_kept(cases):
+ """The fallback must not become 'always the first app'."""
+ case = cases["preferred app present"]
+ assert case["active"] == 2, (
+ "Videos was enabled and preferred; the reader should have landed on it, "
+ f"not on tab {case['active']}")