Files
xenia-pos-local/local_backend/tests/test_signage_library.py
T
bonaminandClaude Opus 5.5 aa8ba5d1d4 feat(signage): menus play whole rounds, seconds fields with − / +, widget limit setting, widgets as big as their content (owner review 6)
- 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>
2026-11-21 15:11:48 +02:00

100 lines
7.0 KiB
Python

"""The signage Slides library and what came with it (owner 2026-11-21): slides kept with a name and a
description, added to playlists as copies, shown alone as a screen's default (also behind a
schedule); blank slides (a background and widgets); widgets moved and sized by hand (their own
box); a menu board narrower than the screen, placed left / centre / right."""
from tests.test_live import err, owner_h, pair # noqa: F401 (fixtures)
from tests.test_media import jpeg, media_dir, up # noqa: F401 (fixture + helpers)
from tests.test_signage import playlist, screens, sent, slide # noqa: F401 (fixtures + helpers)
def keep(client, h, **body):
r = client.post("/api/signage/library", headers=h, json={"name": "Logo", "kind": "blank", **body})
assert r.status_code == 201, r.text
return r.json()
def test_the_library_keeps_slides(client, owner_h):
s = keep(client, owner_h, description=" Our logo, big ", orientation="portrait", duration_s=15,
content={"background": {"kind": "colour", "colour": "#102030"}, "widgets": [{"kind": "name", "position": "top-center"}]})
assert s["kind"] == "blank" and s["orientation"] == "portrait" and s["description"] == "Our logo, big" and s["duration_s"] == 15
assert s["content"]["widgets"][0]["size"] == "medium" and s["screens"] == []
r = client.put(f"/api/signage/library/{s['id']}", headers=owner_h, json={"name": "Logo 2", "description": "", "days": [5, 6]})
assert r.json()["name"] == "Logo 2" and r.json()["description"] is None and r.json()["days"] == [5, 6]
assert err(client.put(f"/api/signage/library/{s['id']}", headers=owner_h, json={"kind": "text"})) == "signage.content_invalid"
assert err(client.put(f"/api/signage/library/{s['id']}", headers=owner_h, json={"name": " "})) == "signage.content_invalid"
assert err(client.post("/api/signage/library", headers=owner_h, json={"name": "x"})) == "signage.content_invalid" # no kind
copy = client.post(f"/api/signage/library/{s['id']}/duplicate", headers=owner_h).json()
assert copy["name"] == "Logo 2 (2)" and copy["content"] == r.json()["content"]
listed = client.get("/api/signage/library", headers=owner_h).json()
assert [x["name"] for x in listed["slides"]] == ["Logo 2", "Logo 2 (2)"] and listed["media"] == {}
assert client.delete(f"/api/signage/library/{copy['id']}", headers=owner_h).status_code == 204
assert err(client.get(f"/api/signage/library/{copy['id']}", headers=owner_h)) == "signage.slide_unknown"
def test_a_library_slide_protects_its_pictures(client, owner_h, media_dir):
pic = up(client, owner_h, jpeg(800, 800)).json()
keep(client, owner_h, kind="image", name="Promo", content={"media_id": pic["id"]})
r = client.delete(f"/api/media/{pic['id']}", headers=owner_h)
assert r.status_code == 409, r.text
def test_a_screen_shows_a_library_slide_when_nothing_else_plays(client, owner_h, screens, sent):
s = keep(client, owner_h, content={"widgets": [{"kind": "qr", "position": "bottom-right"}]})
tv = screens[1]
r = client.put(f"/api/signage/screens/{tv['id']}", headers=owner_h, json={"slide_id": s["id"]})
assert r.status_code == 200, r.text
assert r.json()["slide_id"] == s["id"] and r.json()["playlist_id"] is None
assert r.json()["now"] == {"id": f"slide:{s['id']}", "name": "Logo", "scheduled": False, "slide": True}
got = client.get("/api/signage/screen", headers=tv["h"]).json()
pl = got["playlist"]
assert pl["id"] == f"slide:{s['id']}" and [x["id"] for x in pl["slides"]] == [s["id"]]
assert pl["slides"][0]["content"]["widgets"][0]["link"] # the QR's address, as in a playlist
# a change to it reaches that screen only
sent.clear()
client.put(f"/api/signage/library/{s['id']}", headers=owner_h, json={"duration_s": 20})
assert sent == [("signage.changed", [tv["id"]])]
# behind a schedule: the slide is the fallback, under its own key
p = playlist(client, owner_h, "Lunch")
slide(client, owner_h, p["id"], "text", content={"title": "Lunch"})
client.put("/api/signage/schedules", headers=owner_h, json={"lines": [
{"playlist_id": p["id"], "screen_ids": [tv["id"]], "date_from": "2000-01-01", "date_to": "2000-01-02"}]})
got = client.get("/api/signage/screen", headers=tv["h"]).json()
assert got["schedule"]["fallback_playlist_id"] == f"slide:{s['id']}" and f"slide:{s['id']}" in got["playlists"]
assert got["playlist"]["id"] == f"slide:{s['id']}"
# a playlist as the default takes its place (one or the other)
r = client.put(f"/api/signage/screens/{tv['id']}", headers=owner_h, json={"playlist_id": p["id"]})
assert r.json()["playlist_id"] == p["id"] and r.json()["slide_id"] is None
r = client.put(f"/api/signage/screens/{tv['id']}", headers=owner_h, json={"slide_id": s["id"]})
assert r.json()["playlist_id"] is None and r.json()["slide_id"] == s["id"]
# deleting the slide: the screen shows nothing and is told
sent.clear()
client.delete(f"/api/signage/library/{s['id']}", headers=owner_h)
assert ("signage.changed", [tv["id"]]) in sent
assert client.get("/api/signage/screens", headers=owner_h).json()[0]["slide_id"] is None
def test_blank_slides_and_widgets_placed_by_hand(client, owner_h):
p = playlist(client, owner_h)
s = slide(client, owner_h, p["id"], "blank", content={"widgets": [
{"kind": "clock", "position": "custom", "box": {"x": 90, "y": 5, "w": 20, "h": 10}, "align": "right"},
{"kind": "date", "position": "top-left", "size": "custom", "box": {"x": 1, "y": 1, "w": 5, "h": 5}},
{"kind": "text", "text": "Big", "position": "custom", "box": {"x": 99, "y": -50, "w": 30, "h": 20}}]})
clock, date, big = s["content"]["widgets"]
# owner review 6: a box may run off the slide (here past the right edge), a strip of it stays on it
assert clock["size"] == "custom" and clock["box"] == {"x": 90, "y": 5, "w": 20, "h": 10} and clock["align"] == "right"
assert big["box"] == {"x": 95, "y": -15, "w": 30, "h": 20}
assert date["size"] == "medium" and date["box"] is None # a corner: no box, a real size
r = client.put(f"/api/signage/slides/{s['id']}", headers=owner_h, json={"content": {"widgets": [{"kind": "clock", "position": "custom"}]}})
assert err(r) == "signage.content_invalid" # placed by hand needs its box
r = client.put(f"/api/signage/slides/{s['id']}", headers=owner_h, json={"content": {"title": "x"}})
assert err(r) == "signage.content_invalid" # a blank slide has no title
def test_a_menu_board_narrower_than_the_screen(client, owner_h):
p = playlist(client, owner_h)
s = slide(client, owner_h, p["id"], "menu", content={"select": "all", "board_width": 60, "board_align": "center"})
assert s["content"]["board_width"] == 60 and s["content"]["board_align"] == "center"
assert slide(client, owner_h, p["id"], "menu")["content"]["board_width"] == 100
r = client.put(f"/api/signage/slides/{s['id']}", headers=owner_h, json={"content": {"board_width": 20}})
assert err(r) == "signage.content_invalid"