"""Only 0.4.0 UI changes: TV artwork, category cards, Clear, and quick skip cues.""" import argparse, json, time, urllib.parse, urllib.request from contextlib import contextmanager from device import ROOT, adb, screenshot from verify_ui import launch, key, focused, wait, focus, labels, snapshot, text, passed, position def search_title(query, expected): launch(); key(22, 3); focused('Search'); key(23) focused('Movies, shows, episodes, people') adb('shell', 'input', 'text', query) wait(lambda r: expected in labels(r), 'Search fixture '+expected) key(66); focused(expected) def search_check(): search_title('hazbin', 'Hazbin Hotel') key(23); text('Seasons'); key(4); focused('Hazbin Hotel') # Return to the field, then Right at the end reaches Clear. key(19) wait(lambda r: focus(r)=='hazbin', 'Search field above results') key(4) # Close the Android TV keyboard before navigating app buttons. key(22); focused('Clear'); screenshot('040-search-clear') key(23) root=wait(lambda r:'Movies, shows, episodes, people' in labels(r), 'Clear resets results') assert 'Hazbin Hotel' not in labels(root) assert 'Your collection' not in labels(root) and 'Find something worth watching.' not in labels(root) assert all('Voice search' not in n.get('content-desc','') for n in root.iter('node')) assert not any(n.get('text')=='Clear' for n in root.iter('node')) adb('shell', 'input', 'text', 'silo'); text('TV shows'); key(66); focused('Silo') screenshot('040-search-new-query') passed('Clear removes query/results, restores typing, and microphone is absent') def details_check(): search_title('hazbin', 'Hazbin Hotel'); key(23); text('Seasons') screenshot('040-show-artwork') # Initial show entry may have its first season focused already. if 'Season 1' not in focus(snapshot()):key(20) focused('Season 1'); key(23) wait(lambda r:'Hazbin Hotel' in labels(r) and 'Season 1' in labels(r), 'Season details') screenshot('040-season-artwork') root=snapshot() assert any(n.get('content-desc')=='Back' for n in root.iter('node')) # Moving across episode cards retains the fixed header and useful focus. if not any(x in focus(root) for x in ['Dad Beat Dad','Hello Rosie','Overture']):key(20) before=focus(snapshot()); key(22); after=focus(snapshot()) assert before!=after and after, 'Episode selection must move' screenshot('040-season-next-episode') key(4); focused('Season 1') passed('Hazbin show/season art captured; episode movement and Back focus preserved') def categories_check(): for moves, name in [(1, 'Movies'), (2, 'TV Shows')]: launch(); key(22, moves); focused(name); key(20); focused('Discover') key(22, 2); focused('Categories'); key(23) wait(lambda r:focus(r) not in ('','Categories'), 'Category entry') root=snapshot() assert not any(x in labels(root) for x in ['FILM','SERIES']), 'Categories must only label genres' assert not any(x in labels(root) for x in ['The Batman','Hazbin Hotel']), 'Artwork titles must not appear on categories' time.sleep(2); screenshot('040-'+name.lower().replace(' ','-')+'-categories') first=focus(snapshot()); key(22); second=focus(snapshot()) assert first!=second key(20); below=focus(snapshot()); assert below!=second key(19); focused(second); key(21); focused(first) key(23) wait(lambda r:any('titles' in s for s in labels(r)), 'Scoped category results') key(4); focused(first) passed(name+' artwork cards: horizontal/vertical navigation, open and Back restoration') @contextmanager def preserve_movie_progress(): cfg=dict(l.split('=',1) for l in (ROOT/'.env').read_text().splitlines() if '=' in l and not l.startswith('#')) server=cfg['PLEX_SERVER_URL'].strip('"\'').rstrip('/') headers={'X-Plex-Token':cfg['PLEX_TOKEN'].strip('"\''),'Accept':'application/json'} def request(path, params=None): url=server+path+('?' + urllib.parse.urlencode(params) if params else '') with urllib.request.urlopen(urllib.request.Request(url,headers=headers),timeout=30) as response:return response.read() original=json.loads(request('/library/metadata/9776'))['MediaContainer']['Metadata'][0] try:yield finally: adb('shell','am','force-stop','tv.kaleido.app');time.sleep(.4) # testValidation suppresses Plex timeline/scrobble writes. Verify that contract. restored=json.loads(request('/library/metadata/9776'))['MediaContainer']['Metadata'][0] assert restored.get('viewOffset',0)==original.get('viewOffset',0), 'Preserve fixture progress' assert restored.get('viewCount',0)==original.get('viewCount',0), 'Preserve watched state' def skip_check(): with preserve_movie_progress():quick_skip_check() def quick_skip_check(): adb('shell','am','force-stop','tv.kaleido.app'); adb('logcat','-c') adb('shell','am','start','-n','tv.kaleido.app/.MainActivity','--es','testTitleId','9776','--el','testOffset','90000','--ei','testMode','2','--ez','testValidation','true') deadline=time.monotonic()+45 while 'READY item=9776' not in adb('logcat','-d','-s','KaleidoPlayback:I').decode(errors='replace'): assert time.monotonic()