Files
mediadeck/tests/test_ui_layout.py
T
Denis Defolie df2c9b8933 Add make test-ui: Chromium flows against the real isolated server
New tests/test_ui_flows.py drives headless Chromium through the Media tab
(folders, breadcrumbs, filters, search, opening a hostile file name),
launchers (real launches of a command, a .desktop and a web launcher, live
grid updates) and the /admin page (edit, add, reorder, delete, file
openers used when opening a file). Any uncaught JavaScript exception fails
the test. Four UI mutations were checked to fail their test.

The driver now launches Chromium without any D-Bus session (a first
attempt let it activate real services on the test bus) and records
JavaScript exceptions. wait_for retries while the page is loading, which
fixes a race in test_ui_text_button; the older UI tests register their
cleanups before setup can fail, so a failed setup no longer leaks a
Chromium process.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 16:42:52 +01:00

74 lines
3.7 KiB
Python

"""Mise en page de l'onglet Lecture dans un vrai Chromium : rien d'essentiel ne doit être coupé, quelle que soit la taille.
Régression visée : les commandes du lecteur (précédent / lecture / suivant) et la barre de volume sortaient de la zone
visible quand la fenêtre était basse (tablette avec barre de navigateur, téléphone). Ignoré sans Chromium.
"""
import json
import unittest
from aiohttp.test_utils import TestServer
from uidriver import CHROMIUM, Browser, make_app
# (largeur, hauteur) en pixels CSS : tablettes avec ou sans barre de navigateur, portrait, téléphones
SIZES = [(960, 420), (960, 480), (960, 600), (1280, 640), (1280, 800), (800, 1280), (1024, 1366), (600, 960),
(412, 915), (412, 800), (390, 844), (360, 780), (360, 640)]
# Un élément est « visible » s'il est entièrement dans le rectangle qui le contient
VISIBLE = """(() => {
const inside = (el, box) => { const r = el.getBoundingClientRect(); return r.height > 0 && r.top >= box.top - 1 && r.bottom <= box.bottom + 1; };
const byId = (id) => document.getElementById(id);
const zone = document.querySelector('#panel-player .now-playing').getBoundingClientRect();
const panels = document.querySelector('.panels').getBoundingClientRect();
const result = {};
for (const id of ['btn-prev', 'btn-play', 'btn-next', 'seek']) result[id] = inside(byId(id), zone);
result['volume-bar'] = inside(document.querySelector('.volume-bar'), panels);
result['master-volume'] = inside(byId('master-volume'), panels);
return JSON.stringify(result);
})()"""
LAST_CARD = """(() => {
const zone = document.querySelector('#panel-player .empty');
const box = zone.getBoundingClientRect();
const title = document.getElementById('last-title').getBoundingClientRect();
const art = document.querySelector('.last-art').getBoundingClientRect();
return JSON.stringify({title: title.top >= box.top - 1 && title.bottom <= box.bottom + 1, art: art.top >= box.top - 1});
})()"""
@unittest.skipUnless(CHROMIUM, "Chromium is required")
class PlayerLayoutTest(unittest.IsolatedAsyncioTestCase):
async def asyncSetUp(self) -> None:
self.server = TestServer(make_app())
await self.server.start_server()
self.addAsyncCleanup(self.server.close) # enregistrés ici : asyncTearDown n'est pas appelé si asyncSetUp échoue
self.browser = Browser()
self.addAsyncCleanup(self.browser.close)
await self.browser.start()
def url(self, scenario: str) -> str:
return f"http://127.0.0.1:{self.server.port}/?token={scenario}"
async def test_player_controls_and_volume_stay_visible(self) -> None:
failures = []
for width, height in SIZES:
await self.browser.open(self.url("player"), width, height)
await self.browser.wait_for("document.getElementById('track-title') && document.getElementById('track-title').textContent !== ''")
visible = json.loads(await self.browser.evaluate(VISIBLE))
failures += [f"{width}x{height}: {name} coupé" for name, ok in visible.items() if not ok]
self.assertEqual(failures, [])
async def test_last_opened_card_is_not_cut_off(self) -> None:
failures = []
for width, height in SIZES:
await self.browser.open(self.url("last"), width, height)
await self.browser.wait_for("document.getElementById('last-title') && document.getElementById('last-title').textContent !== ''")
visible = json.loads(await self.browser.evaluate(LAST_CARD))
failures += [f"{width}x{height}: {name} coupé" for name, ok in visible.items() if not ok]
self.assertEqual(failures, [])
if __name__ == "__main__":
unittest.main()