Files
xenia-pos-local/local_backend/tests/test_signage_library.py
T
bonaminandClaude Opus 5.5 cd8218689c feat(signage): widget settings regrouped (main / Text and colours / More), alignment that lines up multi-line widgets, multi-line texts, gallery title, logos larger than the slide; calibration past the recognised resolution and shown the first time
Owner review 2026-11-23 of every widget:
- A widget card is its main settings (the row and what needs room under it: pictures, a gallery's
  pictures or folder, weather details and place, a countdown's start and end, reviews' stars and
  author, a scrolling text's speed, a shape's colours and border, QR caption), then "Text and
  colours" (new LookFields.jsx: text colour, plate, font, style, size, weight, highlight, shadow,
  QR colours; a logo's / gallery's border), then More settings (opacity, rotation, animation, fit,
  typing, blink, QR logo; shadow / border only where there is no Text and colours).
- Date format / separator and clock 12/24 / separator are main settings.
- Alignment only where it lines something up; the TV now aligns the lines of a text, the hours
  (centre: days and times meet in the middle), contact rows, Wi-Fi (code left / right / above),
  the weather's column / card / list / hourly, reviews (stars too), a countdown, a QR caption.
- Text and message: a 2-line textarea in its own row; Enter makes new lines (the TV sizes by the
  longest line and the number of lines).
- Gallery: a title above or below the pictures (title_position).
- A widget's box may reach 400 % of the slide (a logo zoomed in past the slide's edges saved again).
- "Auto" stays "Auto" in Greek; scrolling text Left / Right; reviews' stars choice no longer clipped;
  countdown "When it ends" hint as an info tip (fields level).

Calibration: an edge may go past the recognised window (down to -2000 px); the dialog's rows are
centred, "Each click moves" sits above its choice, the window size is labelled "Recognised
resolution" with what it means; the TV asks for its screen answer on every calibrate event and
while calibrating (the outline shows the first time), the dialog sends "on" again after 1.5 s.
NumberInput takes a leading minus when min < 0. E2E: waits for the Add-a-slide dialog to go.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 05:40:04 +02:00

110 lines
7.9 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
# owner 2026-11-23: a picture made larger than the slide (cut off at its edges); a gallery's title below
r = client.put(f"/api/signage/slides/{s['id']}", headers=owner_h, json={"content": {"widgets": [
{"kind": "logo", "position": "custom", "box": {"x": -60, "y": -40, "w": 220, "h": 180}},
{"kind": "gallery", "text": "Our dishes", "title_position": "below", "position": "top-left"}]}})
logo, gallery = r.json()["content"]["widgets"]
assert logo["box"] == {"x": -60, "y": -40, "w": 220, "h": 180}
assert gallery["text"] == "Our dishes" and gallery["title_position"] == "below"
r = client.put(f"/api/signage/slides/{s['id']}", headers=owner_h, json={"content": {"widgets": [
{"kind": "logo", "position": "custom", "box": {"x": 0, "y": 0, "w": 401, "h": 10}}]}})
assert err(r) == "signage.content_invalid" # at most four times the slide
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"