- A menu board with pages plays whole rounds (menuMs rounds its seconds up); the editor says how long it really plays under "Seconds on screen", the card and the playlist total use it. - Seconds on screen / per page: shared NumberInput (− / +, may be emptied: an error under the field and Save blocked until filled; 1 s at least, server ge=1). - Performance (Signage -> Message & settings): widgets per slide (signage.max_widgets, 10 recommended, up to 50), checked by the server (signage.too_many_widgets) and the editor. - Text, clock, date, QR, weather, logo placed by hand: the box is exactly the content (its height x text size sets the size, the width follows; handles scale keeping the shape; text size grows the box); a slide's widget may run off the slide while 5 % stays on it. - Slider: the value as close to the slider as the frame's padding; floor and table-colour sliders use the shared Slider. Timeline cards' ring no longer clipped; larger playlist buttons. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
192 lines
14 KiB
Python
192 lines
14 KiB
Python
"""Signage widgets, owner review 2026-11-21: a text of its own, a menu widget (a board's list in the
|
|
widget's place), stacks (parts side by side or one over the other, each with a widget, another
|
|
stack one level deep, or a whole library slide), weather for tomorrow / the day after and in three
|
|
styles; products hidden from a board stay in the editor's list (greyed), never on the TV."""
|
|
from tests.test_live import err, owner_h, pair # noqa: F401 (fixtures)
|
|
from tests.test_signage import playlist, screens, sent, slide # noqa: F401 (fixtures + helpers)
|
|
from tests.test_signage_menu import menu, names # noqa: F401 (fixture + helper)
|
|
|
|
BOX = {"x": 5, "y": 10, "w": 90, "h": 80}
|
|
|
|
|
|
def stack(*cells, direction="row"):
|
|
return {"kind": "stack", "direction": direction, "position": "custom", "box": BOX, "cells": list(cells)}
|
|
|
|
|
|
def keep(client, h, **body):
|
|
r = client.post("/api/signage/library", headers=h, json={"name": "Promo", "kind": "text", **body})
|
|
assert r.status_code == 201, r.text
|
|
return r.json()
|
|
|
|
|
|
def test_text_weather_and_stack_widgets_are_checked(client, owner_h):
|
|
p = playlist(client, owner_h)
|
|
s = slide(client, owner_h, p["id"], "blank", content={"widgets": [
|
|
{"kind": "text", "text": "Happy hour 18-20"},
|
|
{"kind": "weather", "weather_from": 1, "weather_days": 3, "weather_style": "icon"},
|
|
stack({"share": 30, "widget": {"kind": "clock"}}, {"share": 70, "widget": stack({"share": 50}, {"share": 50}, direction="column")}),
|
|
]})
|
|
ws = s["content"]["widgets"]
|
|
assert ws[0]["text"] == "Happy hour 18-20"
|
|
assert ws[1]["weather_from"] == 1 and ws[1]["weather_days"] == 2 and ws[1]["weather_style"] == "icon" # the forecast has 3 days
|
|
assert [c["share"] for c in ws[2]["cells"]] == [30, 70] and ws[2]["cells"][1]["widgets"][0]["direction"] == "column"
|
|
assert ws[0]["cells"] == [] and ws[0]["board"] is None
|
|
url = f"/api/signage/playlists/{p['id']}/slides"
|
|
bad = [
|
|
stack(), # no parts
|
|
stack({"share": 50, "widget": {"kind": "clock"}, "slide_id": 1}), # a widget and a slide
|
|
stack({"share": 50, "widget": stack({"share": 50, "widget": stack({"share": 100})})}), # three stacks deep
|
|
stack(*[{"share": 10}] * 7), # more than 6 parts
|
|
]
|
|
for w in bad:
|
|
assert err(client.post(url, headers=owner_h, json={"kind": "blank", "content": {"widgets": [w]}})) == "signage.content_invalid", w
|
|
assert err(client.post(url, headers=owner_h, json={"kind": "blank", "content": {"widgets": [stack({"share": 100, "slide_id": 999})]}})) == "signage.slide_unknown"
|
|
|
|
|
|
def test_a_stack_shows_a_library_slide_and_a_menu_widget(client, owner_h, screens, sent, menu, db):
|
|
promo = keep(client, owner_h, content={"title": "Fresh fish", "widgets": [{"kind": "qr", "position": "bottom-right"}]})
|
|
p = playlist(client, owner_h, "Split")
|
|
tv = screens[1]
|
|
client.put(f"/api/signage/screens/{tv['id']}", headers=owner_h, json={"playlist_id": p["id"]})
|
|
board = {"kind": "menu", "board": {"category_ids": [menu["cats"]["drinks"]], "exclude_ids": [menu["beer"].id], "columns": 1}}
|
|
s = slide(client, owner_h, p["id"], "blank", content={"widgets": [
|
|
{"kind": "qr", "position": "top-left"},
|
|
stack({"share": 25, "widget": board}, {"share": 75, "slide_id": promo["id"]}),
|
|
]})
|
|
# the screen: extras by widget path (the QR's link, the menu's products, the slide inside the part)
|
|
got = client.get("/api/signage/screen", headers=tv["h"]).json()["playlist"]["slides"][0]
|
|
ex = got["extras"]
|
|
assert ex["0"]["link"] and got["content"]["widgets"][0]["link"] == ex["0"]["link"]
|
|
assert names(ex["1.0.0"]["menu"]) == [] and ex["1.0.0"]["menu"]["count"] == 0 # Beer hidden; Wine: delivery only
|
|
inner = ex["1.1"]["slide"]
|
|
assert inner["id"] == promo["id"] and inner["kind"] == "text" and inner["content"]["title"] == "Fresh fish"
|
|
assert inner["extras"]["0"]["link"] # its own widgets' extras
|
|
# the editor: the hidden product stays in the list, marked
|
|
ed = client.get(f"/api/signage/playlists/{p['id']}", headers=owner_h).json()["slides"][0]["extras"]["1.0.0"]["menu"]
|
|
assert [(i["name"], i.get("hidden", False)) for g in ed["groups"] for i in g["items"]] == [("Beer", True)] and ed["count"] == 0
|
|
# a change to the library slide reaches the screens that show it inside a stack
|
|
sent.clear()
|
|
client.put(f"/api/signage/library/{promo['id']}", headers=owner_h, json={"content": {"title": "Fresh octopus"}})
|
|
assert sent == [("signage.changed", [tv["id"]])]
|
|
assert client.get("/api/signage/screen", headers=tv["h"]).json()["playlist"]["slides"][0]["extras"]["1.1"]["slide"]["content"]["title"] == "Fresh octopus"
|
|
# products change: a slide with a menu widget is told too
|
|
import routers.signage as sg
|
|
sent.clear()
|
|
sg.menu_changed(db)
|
|
assert sent == [("signage.changed", [tv["id"]])]
|
|
# the library slide deleted: the part shows nothing, the screen is told
|
|
sent.clear()
|
|
client.delete(f"/api/signage/library/{promo['id']}", headers=owner_h)
|
|
assert sent == [("signage.changed", [tv["id"]])]
|
|
assert "1.1" not in client.get("/api/signage/screen", headers=tv["h"]).json()["playlist"]["slides"][0]["extras"]
|
|
assert s["content"]["widgets"][1]["cells"][1]["slide_id"] == promo["id"]
|
|
|
|
|
|
def test_the_editor_previews_any_slide(client, owner_h, menu):
|
|
promo = keep(client, owner_h, content={"title": "Inside"})
|
|
r = client.post("/api/signage/preview/slide", headers=owner_h, json={"kind": "blank", "content": {"widgets": [
|
|
stack({"share": 50, "widget": {"kind": "menu", "board": {"product_ids": [menu["steak"].id], "exclude_ids": [menu["steak"].id]}}},
|
|
{"share": 50, "slide_id": promo["id"]})]}})
|
|
assert r.status_code == 200, r.text
|
|
got = r.json()
|
|
assert [i.get("hidden") for g in got["extras"]["0.0.0"]["menu"]["groups"] for i in g["items"]] == [True]
|
|
assert got["extras"]["0.1"]["slide"]["content"]["title"] == "Inside" and got["menu"] is None and got["media"] == {}
|
|
r = client.post("/api/signage/preview/slide", headers=owner_h, json={"kind": "menu", "content": {"select": "all", "exclude_ids": [menu["beer"].id]}})
|
|
m = r.json()["menu"]
|
|
assert "Beer" in [i["name"] for g in m["groups"] for i in g["items"] if i.get("hidden")] and m["count"] == 3
|
|
assert err(client.post("/api/signage/preview/slide", headers=owner_h, json={"kind": "text", "content": {"widgets": [stack()]}})) == "signage.content_invalid"
|
|
|
|
|
|
def test_a_board_has_its_own_names_and_the_look_of_each_part(client, owner_h, menu):
|
|
"""Owner review 3 (2026-11-21): names only for this board (the catalogue keeps its own), the look
|
|
of headings, names, prices and the dots, spacing, photos."""
|
|
content = {"category_ids": [menu["cats"]["drinks"]], "names": {str(menu["beer"].id): " Craft beer "}, "category_names": {str(menu["cats"]["drinks"]): "Bar"},
|
|
"heading_style": {"size": 180, "colour": "#ff0000", "font": "serif", "align": "center", "italic": True},
|
|
"price_style": {"align": "right", "bold": False}, "dot_style": {"style": "dashed", "size": 150},
|
|
"line_height": 1.4, "letter_spacing": 0.05, "photo_size": 150, "photo_shape": "round"}
|
|
r = client.post("/api/signage/preview/slide", headers=owner_h, json={"kind": "menu", "content": content})
|
|
assert r.status_code == 200, r.text
|
|
g = r.json()["menu"]["groups"][0]
|
|
assert g["category"] == {"id": menu["cats"]["drinks"], "name": "Bar", "original": "Drinks"}
|
|
assert g["items"][0]["name"] == "Craft beer" and g["items"][0]["original"] == "Beer"
|
|
p = playlist(client, owner_h)
|
|
s = slide(client, owner_h, p["id"], "menu", content=content)
|
|
c = s["content"]
|
|
assert c["names"] == {str(menu["beer"].id): "Craft beer"} and c["heading_style"]["italic"] and c["item_style"]["bold"]
|
|
assert c["price_style"] == {"size": None, "colour": None, "font": None, "bold": False, "italic": False, "underline": False, "align": "right"}
|
|
url = f"/api/signage/playlists/{p['id']}/slides"
|
|
for bad in ({"names": {"x": "a"}}, {"heading_style": {"size": 20}}, {"dot_style": {"style": "wavy"}}, {"line_height": 9}, {"photo_shape": "star"}):
|
|
assert err(client.post(url, headers=owner_h, json={"kind": "menu", "content": bad})) == "signage.content_invalid", bad
|
|
|
|
|
|
def test_a_part_holds_several_widgets_and_colours_can_be_see_through(client, owner_h, menu):
|
|
"""Owner review 4 (2026-11-21): a stack's part holds several widgets (each with its own extras,
|
|
by path "stack.part.place"); a part stored with one `widget` still reads; colours #rrggbbaa; a
|
|
board's badges have their own text colour."""
|
|
p = playlist(client, owner_h)
|
|
s = slide(client, owner_h, p["id"], "blank", content={"background": {"colour": "#11182780"}, "widgets": [
|
|
stack({"share": 40, "widgets": [{"kind": "clock"}, {"kind": "qr"}, {"kind": "menu", "board": {"product_ids": [menu["steak"].id]}}]},
|
|
{"share": 60, "widget": {"kind": "date"}}),
|
|
]})
|
|
cells = s["content"]["widgets"][0]["cells"]
|
|
assert [w["kind"] for w in cells[0]["widgets"]] == ["clock", "qr", "menu"] and [w["kind"] for w in cells[1]["widgets"]] == ["date"]
|
|
assert "widget" not in cells[1] and s["content"]["background"]["colour"] == "#11182780"
|
|
ex = client.get(f"/api/signage/playlists/{p['id']}", headers=owner_h).json()["slides"][0]["extras"]
|
|
assert ex["0.0.1"]["link"] and names(ex["0.0.2"]["menu"]) == [["Grill", ["Steak"]]]
|
|
url = f"/api/signage/playlists/{p['id']}/slides"
|
|
for bad in (stack({"share": 50, "widgets": [{"kind": "clock"}], "slide_id": 1}),
|
|
stack({"share": 50, "widgets": [{"kind": "clock"}] * 7})):
|
|
assert err(client.post(url, headers=owner_h, json={"kind": "blank", "content": {"widgets": [bad]}})) == "signage.content_invalid", bad
|
|
m = slide(client, owner_h, p["id"], "menu", content={"accent_colour": "#1e3a8a", "badge_text_colour": "#fde68aCC"})["content"]
|
|
assert m["badge_text_colour"] == "#fde68aCC" and m["accent_colour"] == "#1e3a8a"
|
|
for bad in ({"badge_text_colour": "#fff"}, {"text_colour": "#12345"}):
|
|
assert err(client.post(url, headers=owner_h, json={"kind": "menu", "content": bad})) == "signage.content_invalid", bad
|
|
|
|
|
|
def test_the_venues_badges_and_a_widgets_own_look(client, owner_h, menu, screens):
|
|
"""Owner review 5 (2026-11-21): the venue's badges (names, colours, icons) edited in one place and
|
|
sent with the venue; a product with several badges; a widget's own look; a board's list placed
|
|
up or down."""
|
|
got = client.get("/api/signage/badges", headers=owner_h).json()
|
|
assert [b["key"] for b in got["badges"]][:3] == ["new", "chef", "offer"] and "flame" in got["icons"]
|
|
mine = got["badges"][:2] + [{"key": "gluten-free", "names": {"el": "Χωρίς γλουτένη", "en": "Gluten free"}, "colour": "#0ea5e9", "text_colour": "#ffffff", "icon": "wheat-off"}]
|
|
r = client.put("/api/signage/badges", headers=owner_h, json={"badges": mine})
|
|
assert r.status_code == 200, r.text and [b["key"] for b in r.json()["badges"]] == ["new", "chef", "gluten-free"]
|
|
for bad in ([{"key": "x", "names": {}}], [{"key": "x", "names": {"en": "X"}, "icon": "unicorn"}],
|
|
[{"key": "x", "names": {"en": "X"}}, {"key": "x", "names": {"en": "Y"}}]):
|
|
assert err(client.put("/api/signage/badges", headers=owner_h, json={"badges": bad})) == "signage.content_invalid", bad
|
|
assert client.get("/api/signage/venue", headers=owner_h).json()["badges"][2]["icon"] == "wheat-off"
|
|
p = playlist(client, owner_h)
|
|
sid = str(menu["steak"].id)
|
|
s = slide(client, owner_h, p["id"], "menu", content={"product_ids": [menu["steak"].id], "badges": {sid: ["chef", "gluten-free"]},
|
|
"board_valign": "middle", "badge_colour": "#000000", "widgets": [
|
|
{"kind": "qr", "qr_colour": "#1e3a8a", "qr_background": "#fde68a", "colour": "#ff0000", "bold": False, "italic": True, "font": "serif", "text_size": 150,
|
|
"background_colour": "#00000080"},
|
|
stack({"share": 100, "widgets": [{"kind": "clock", "vertical": "bottom", "align": "right"},
|
|
{"kind": "date", "position": "custom", "box": {"x": 10, "y": 10, "w": 50, "h": 40}}]})]})
|
|
c = s["content"]
|
|
assert c["badges"] == {sid: ["chef", "gluten-free"]} and c["board_valign"] == "middle" and c["badge_colour"] == "#000000"
|
|
q = c["widgets"][0]
|
|
assert (q["qr_colour"], q["qr_background"], q["bold"], q["italic"], q["text_size"], q["font"]) == ("#1e3a8a", "#fde68a", False, True, 150, "serif")
|
|
part = c["widgets"][1]["cells"][0]["widgets"]
|
|
assert part[0]["vertical"] == "bottom" and part[1]["box"] == {"x": 10, "y": 10, "w": 50, "h": 40}
|
|
url = f"/api/signage/playlists/{p['id']}/slides"
|
|
for bad in ({"badges": {sid: ["a", "b", "c", "d", "e"]}}, {"board_valign": "centre"}, {"widgets": [{"kind": "clock", "text_size": 400}]}):
|
|
assert err(client.post(url, headers=owner_h, json={"kind": "menu", "content": bad})) == "signage.content_invalid", bad
|
|
|
|
|
|
def test_how_many_widgets_a_slide_may_hold_is_the_venues(client, owner_h):
|
|
"""Owner review 6 (2026-11-21): 10 widgets a slide (recommended), more when the venue allows them
|
|
(Signage → Message & settings → Performance), never over 50; a menu with pages may now turn them
|
|
every second."""
|
|
assert client.get("/api/signage/performance", headers=owner_h).json() == {"max_widgets": 10, "recommended": 10, "cap": 50}
|
|
p = playlist(client, owner_h)
|
|
url = f"/api/signage/playlists/{p['id']}/slides"
|
|
eleven = [{"kind": "clock"}] * 11
|
|
assert err(client.post(url, headers=owner_h, json={"kind": "blank", "content": {"widgets": eleven}})) == "signage.too_many_widgets"
|
|
assert client.put("/api/signage/performance", headers=owner_h, json={"max_widgets": 12}).json()["max_widgets"] == 12
|
|
assert client.post(url, headers=owner_h, json={"kind": "blank", "content": {"widgets": eleven}}).status_code == 201
|
|
assert err(client.put("/api/signage/performance", headers=owner_h, json={"max_widgets": 51})) is not None
|
|
s = slide(client, owner_h, p["id"], "menu", content={"page_seconds": 1}, duration_s=1)
|
|
assert s["content"]["page_seconds"] == 1 and s["duration_s"] == 1
|