Files
mediadeck/tests/test_ui_text_button.py
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

41 lines
2.0 KiB
Python

"""Bouton « Clavier » grisé : toucher le bouton doit dire pourquoi (une infobulle est invisible sur une tablette).
Régression visée : sur une installation neuve `features.text_input` est faux, le bouton était seulement grisé et
la raison n'apparaissait que dans son attribut title. Ignoré sans Chromium.
"""
import json
import unittest
from aiohttp.test_utils import TestServer
from uidriver import CHROMIUM, Browser, make_app
STATE = """(() => {
const b = document.getElementById('text-open');
return JSON.stringify({ariaDisabled: b.getAttribute('aria-disabled'), disabled: b.disabled,
opacity: getComputedStyle(b).opacity, dialogOpen: document.getElementById('text-dialog').open});
})()"""
@unittest.skipUnless(CHROMIUM, "Chromium is required")
class TextButtonTest(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()
await self.browser.open(f"http://127.0.0.1:{self.server.port}/?token=player", 1280, 800)
await self.browser.wait_for("document.getElementById('track-title').textContent !== ''")
await self.browser.evaluate("document.querySelector('[data-tab=remote]').click()")
async def test_tapping_the_greyed_button_shows_the_reason_and_opens_nothing(self) -> None:
state = json.loads(await self.browser.evaluate(STATE))
self.assertEqual(state["ariaDisabled"], "true")
self.assertLess(float(state["opacity"]), 0.5) # toujours grisé
await self.browser.evaluate("document.getElementById('text-open').click()")
await self.browser.wait_for("document.querySelector('.toast') && document.querySelector('.toast').textContent.includes('features.text_input')")
self.assertFalse(json.loads(await self.browser.evaluate(STATE))["dialogOpen"])