- products.translations / categories.translations (Alembic 0033, core/menu_languages.py: el + en,
name / description / quick options by their base name; catalog.translation). Empty = the text
as typed; no machine translation (owner).
- In the manager's product editor ("In English" / "In Greek", quick extras), the category dialog,
and a menu board's Language (signage MenuContent.language).
- Customer screens only: cloud snapshot names / descriptions per language (C-2), the menu tablet's
EL / EN switch the names (localize), signage boards; tickets, KDS, counter, phones keep the base.
- Catalogue bundles carry translations; @xenia/access menuLanguages.js (a backend test compares).
- e2e: manager (the other language saved), menu tablet (EN / EL names), QR table (English on
the menu, the base name on the kitchen's order, Greek page as typed).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
5.6 KiB
Python
85 lines
5.6 KiB
Python
"""The menu in English and Greek (plan step 6.4, owner 2026-11-18): translations of product names,
|
|
descriptions, quick options and category names; a missing one shows the base text. Customer
|
|
screens use them (cloud menu, menu tablet, signage boards); tickets and staff screens don't."""
|
|
from tests.test_live import err, owner_h, pair # noqa: F401 (fixtures)
|
|
from tests.test_menu_tablet import menu, tablet # noqa: F401 (fixtures)
|
|
|
|
EN = {"en": {"name": "Pork souvlaki", "description": "On a skewer", "quick": {"Pita": "Pitta bread"}}}
|
|
|
|
|
|
def test_translations_are_stored_cleaned_and_validated(client, owner_h, menu):
|
|
pid = menu["souvlaki"].id
|
|
r = client.put(f"/api/products/{pid}", headers=owner_h, json={"translations": {"en": {"name": " Pork souvlaki ", "description": ""}}})
|
|
assert r.status_code == 200, r.text
|
|
assert r.json()["translations"] == {"en": {"name": "Pork souvlaki"}} # trimmed, empty dropped
|
|
assert client.put(f"/api/products/{pid}", headers=owner_h, json={"base_price": 4}).json()["translations"]["en"]["name"] == "Pork souvlaki"
|
|
for bad in ({"fr": {"name": "x"}}, {"en": {"colour": "x"}}, {"en": {"quick": ["x"]}}):
|
|
r = client.put(f"/api/products/{pid}", headers=owner_h, json={"translations": bad})
|
|
assert r.status_code == 422 and err(r) == "catalog.translation", bad
|
|
cat = menu["cats"]["grill"]
|
|
r = client.put(f"/api/products/categories/{cat}", headers=owner_h, json={"translations": {"en": {"name": "From the grill"}}})
|
|
assert r.status_code == 200 and r.json()["translations"] == {"en": {"name": "From the grill"}}
|
|
assert client.put(f"/api/products/categories/{cat}", headers=owner_h, json={"translations": {"en": {"title": "x"}}}).status_code == 422
|
|
|
|
|
|
def test_the_tablet_switches_names_and_falls_back_to_the_base(client, owner_h, menu, tablet):
|
|
client.put(f"/api/products/{menu['souvlaki'].id}", headers=owner_h, json={"translations": EN})
|
|
client.put(f"/api/products/categories/{menu['cats']['grill']}", headers=owner_h, json={"translations": {"en": {"name": "Grill (en)"}}})
|
|
data = client.get("/api/menu-tablet/menu", headers=tablet["h"]).json()
|
|
souv = data["products"][str(menu["souvlaki"].id)]
|
|
assert souv["names"] == {"el": "Souvlaki", "en": "Pork souvlaki"} and souv["name"] == "Souvlaki"
|
|
assert souv["descriptions"]["en"] == "On a skewer"
|
|
steak = data["products"][str(menu["steak"].id)]
|
|
assert steak["names"] == {"el": "Steak", "en": "Steak"} # not translated: the base name
|
|
grill = next(c for c in data["categories"] if c["id"] == menu["cats"]["grill"])
|
|
assert grill["names"] == {"el": "Grill", "en": "Grill (en)"}
|
|
|
|
|
|
def test_the_cloud_menu_carries_names_per_language(client, db, owner_h, menu):
|
|
from models.product import ProductQuickOption
|
|
db.add(ProductQuickOption(product_id=menu["souvlaki"].id, name="Pita", price=0.5))
|
|
db.commit()
|
|
client.put(f"/api/products/{menu['souvlaki'].id}", headers=owner_h, json={"translations": EN})
|
|
from services.cloud_sync import menu_snapshot
|
|
snap, _ = menu_snapshot(db)
|
|
grill = next(c for c in snap["categories"] if c["id"] == menu["cats"]["grill"])
|
|
souv = next(p for p in grill["products"] if p["id"] == menu["souvlaki"].id)
|
|
assert souv["names"] == {"el": "Souvlaki", "en": "Pork souvlaki"} and souv["name"] == "Souvlaki"
|
|
assert souv["quick_options"][0]["names"] == {"el": "Pita", "en": "Pitta bread"}
|
|
assert grill["names"] == {"el": "Grill", "en": "Grill"}
|
|
|
|
|
|
def test_a_board_in_english_and_tickets_stay_in_the_base(client, db, owner_h, menu):
|
|
client.put(f"/api/products/{menu['souvlaki'].id}", headers=owner_h, json={"translations": EN})
|
|
from services.signage_menu import resolve
|
|
names = lambda lang: [i["name"] for g in resolve(db, {"select": "all", "language": lang})["groups"] for i in g["items"]] # noqa: E731
|
|
assert "Pork souvlaki" in names("en") and "Souvlaki" not in names("en")
|
|
assert "Souvlaki" in names(None) and "Souvlaki" in names("el")
|
|
# what the staff see (phones, counter): the base name
|
|
assert next(p for p in client.get("/api/products/", headers=owner_h).json() if p["id"] == menu["souvlaki"].id)["name"] == "Souvlaki"
|
|
|
|
|
|
def test_catalogue_bundle_keeps_translations(client, db, owner_h, menu):
|
|
client.put(f"/api/products/{menu['beer'].id}", headers=owner_h, json={"translations": {"en": {"name": "Lager"}}})
|
|
client.put(f"/api/products/categories/{menu['cats']['drinks']}", headers=owner_h, json={"translations": {"en": {"name": "Drinks (en)"}}})
|
|
bundle = client.get("/api/data-transfer/export/catalog", headers=owner_h).json()
|
|
client.put(f"/api/products/{menu['beer'].id}", headers=owner_h, json={"translations": {}})
|
|
client.put(f"/api/products/categories/{menu['cats']['drinks']}", headers=owner_h, json={"translations": {}})
|
|
assert client.post("/api/data-transfer/import/catalog", headers=owner_h, json=bundle).status_code < 300
|
|
db.expire_all()
|
|
from core.menu_languages import of
|
|
from models.product import Category, Product
|
|
assert of(db.get(Product, menu["beer"].id)) == {"en": {"name": "Lager"}}
|
|
assert of(db.get(Category, menu["cats"]["drinks"])) == {"en": {"name": "Drinks (en)"}}
|
|
|
|
|
|
|
|
def test_the_frontend_list_matches_the_backend():
|
|
"""packages/access/src/menuLanguages.js keeps the same languages."""
|
|
import re
|
|
from pathlib import Path
|
|
from core.menu_languages import MENU_LANGUAGES
|
|
js = (Path(__file__).resolve().parents[2] / "packages" / "access" / "src" / "menuLanguages.js").read_text(encoding="utf-8")
|
|
listed = re.search(r"export const MENU_LANGUAGES = \[([^\]]*)\]", js).group(1)
|
|
assert [x.strip().strip("'") for x in listed.split(",") if x.strip()] == list(MENU_LANGUAGES)
|