Add Services modal with independent lifecycle controls and persistent autostart

This commit is contained in:
2026-12-01 08:47:22 +00:00
parent 8d38a99748
commit 3aa0006600
10 changed files with 203 additions and 7 deletions

View File

@@ -0,0 +1,36 @@
"""Chromium UI test with mocked API; runtime/HTTP covered separately."""
from pathlib import Path
import os
from playwright.sync_api import sync_playwright
root=Path(__file__).resolve().parents[1]/'websetup'
state=dict(defaultPassword=False,groups={k:[] for k in ['1','2','3','4','5','12','13','17','21','45','200']},text='',revision='a',csrf='b',validation={'errors':[]},devices=[],backups=[],path='/test',services=True)
prefs={'netware':False,'browser':True};revision='1';actions=[];fail=False
status={'mars-nwe-pcap.service':'ActiveState=inactive','mars-pcapd.service':'ActiveState=inactive','browser-admin':'ActiveState=active'}
def fixture(source,path,body):
global revision,prefs
if path=='/api/state':return state
if path=='/api/status':return status
if path=='/api/services':
if body:
assert body['confirm']
if body['op']=='autostart':
assert body['revision']==revision;prefs=body['autostart'];revision='2';actions.append('save')
else:actions.append(body['target']+':'+body['action'])
return {'revision':revision,'autostart':prefs,'status':status,'available':True}
raise AssertionError(path)
with sync_playwright() as p:
b=p.chromium.launch(executable_path=os.environ.get('CHROMIUM_PATH'),args=['--no-sandbox'])
for width in [1280,390]:
page=b.new_page(viewport={'width':width,'height':900});errors=[];page.on('pageerror',lambda e:errors.append(str(e)));page.on('dialog',lambda d:d.accept());page.expose_binding('fixture',fixture)
page.evaluate("window.fetch=async(path,opts)=>({ok:true,status:200,json:()=>window.fixture(path,opts?.body?JSON.parse(opts.body):null)})")
html=(root/'index.html').read_text().replace('<link rel="stylesheet" href="/style.css">','<style>'+(root/'style.css').read_text()+'</style>').replace('<script src="/app.js" defer></script>','');page.set_content(html);page.add_script_tag(content=(root/'app.js').read_text());page.wait_for_function("document.getElementById('configPath').textContent==='/test'")
page.locator('#servicesOpen').click();page.locator('#servicesAuto-netware').set_checked(not prefs['netware']);page.locator('#servicesAuto-browser').set_checked(not prefs['browser']);page.locator('#servicesSave').click();page.wait_for_function("document.getElementById('servicesMessage').textContent.includes('gespeichert')")
for target in ['netware','browser']:
for action in ['start','restart','stop']:
page.locator(f'[data-target="{target}"][data-action="{action}"]').click();page.wait_for_function("!document.getElementById('servicesRefresh').disabled")
assert actions[-1]==target+':'+action
page.locator('#servicesClose').click();page.locator('#servicesOpen').click();page.wait_for_function("!document.getElementById('servicesRefresh').disabled")
assert page.locator('#servicesAuto-netware').is_checked()==prefs['netware'];assert not errors,errors
page.screenshot(path=str(root.parent/f'build/services-{width}.png'));page.close()
b.close()
print('PASS Services Chromium desktop/mobile: save, persistence readback, both service groups and all actions')