"""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