diff options
Diffstat (limited to 'packages/meshbay-hub/tests/test_transport_contracts.py')
| -rw-r--r-- | packages/meshbay-hub/tests/test_transport_contracts.py | 58 |
1 files changed, 42 insertions, 16 deletions
diff --git a/packages/meshbay-hub/tests/test_transport_contracts.py b/packages/meshbay-hub/tests/test_transport_contracts.py index 8d975d7..5da8104 100644 --- a/packages/meshbay-hub/tests/test_transport_contracts.py +++ b/packages/meshbay-hub/tests/test_transport_contracts.py @@ -129,6 +129,14 @@ def test_presence_has_three_states_and_a_label_for_each(app): "the dot needs a title and an aria-label, not just a colour") +def _string(source: str, key: str) -> str: + """One locale entry's text, whether it is written on one line or spliced + across several with `+`.""" + start = source.index(f"'{key}':") + len(f"'{key}':") + end = source.index("\n '", start) + return source[start:end] + + def test_a_refusal_from_the_node_counts_as_present(app): """The node answering "no" proves it is up; only silence proves nothing.""" assert "err.reason ? 'online' : 'offline'" in app @@ -136,30 +144,48 @@ def test_a_refusal_from_the_node_counts_as_present(app): # ── The create-group form ───────────────────────────────────────────────────── -def test_choosing_public_settles_the_admission_question(app): - """Public implies open, so the policy selector has nothing left to ask. - - Enforced twice on purpose: the API refuses public+invite with a 422, and the - form never offers the combination. A form that can build a request the server - rejects is a form that produces an error message instead of a group. +def test_the_form_asks_one_question_not_two(app): """ - assert "setVisibility('public'); setJoinPolicy('open');" in app, ( - "picking Public must settle the policy, not leave the previous one") - assert "setVisibility('private'); setJoinPolicy('invite');" in app, ( - "going back to Private must not leave the group open by accident") + Visibility and admission were separate selectors that could only ever be set + together, and the form knew it — picking Public reached over and set the + policy. Two of the four combinations were impossible: the API refused + public+invite with a 422, and private+open is a directory listing nobody can + find, joining being through the node rather than a link. + So there is one selector. "Open" is what makes a group listed, and the + request derives the rest. + """ form = app[app.index("function CreateGroupPage"):] form = form[:form.index("\n}\n")] - selector = form.index("t('create_group.join_policy')") - guard = form.rindex("visibility === 'public'", 0, selector) - assert guard != -1, "the policy selector must sit behind a visibility guard" - assert "create_group.public_is_open" in form[guard:selector], ( - "a public group should say why there is nothing to choose") + + assert "setVisibility(" not in form, "the visibility selector is back" + assert "t('create_group.join_policy')" in form + assert "joinPolicy === 'open' ? 'public' : 'private'" in form, ( + "the request must derive visibility rather than leave it unset") + + +def test_the_form_says_what_each_choice_means_for_finding_the_group(app): + """Dropping the visibility box removes the words "public" and "private" + from the page. If the descriptions do not say it, nothing does — and + somebody publishes a group without meaning to.""" + en = (STATIC / "locales" / "en.js").read_text(encoding="utf-8") + invite = _string(en, "create_group.invite_desc") + open_ = _string(en, "create_group.open_desc") + assert "not listed" in invite.lower() + assert "listed" in open_.lower() and "anyone" in open_.lower() + + +def test_the_strings_the_visibility_box_used_are_gone(app): + """A key nobody reads is a key that rots, and ten locales carry each one.""" + for locale in (STATIC / "locales").glob("*.js"): + text = locale.read_text(encoding="utf-8") + for key in ("create_group.visibility", "create_group.private", + "create_group.public_is_open", "create_group.public_desc"): + assert f"'{key}'" not in text, f"{locale.name} still carries {key}" def test_the_form_starts_on_a_combination_the_api_accepts(app): form = app[app.index("function CreateGroupPage"):] - assert "useState('private')" in form[:form.index("return html")] assert "useState('invite')" in form[:form.index("return html")] |