64 lines
3.6 KiB
Python
64 lines
3.6 KiB
Python
"""Browser UI smoke test with mocked fetch; Chromium policies block navigation."""
|
|
import json
|
|
from pathlib import Path
|
|
from playwright.sync_api import sync_playwright
|
|
|
|
ROOT = Path(__file__).resolve().parents[1] / 'app' / 'static'
|
|
html = (ROOT / 'index.html').read_text()
|
|
html = html.replace('<link rel="stylesheet" href="/static/style.css">', '')
|
|
html = html.replace('<script src="/static/app.js" defer></script>', '')
|
|
css = (ROOT / 'style.css').read_text()
|
|
js = (ROOT / 'app.js').read_text()
|
|
|
|
with sync_playwright() as p:
|
|
browser = p.chromium.launch(executable_path='/usr/bin/chromium',
|
|
args=['--no-sandbox', '--disable-dev-shm-usage'])
|
|
page = browser.new_page(viewport={'width': 1250, 'height': 950})
|
|
errors = []
|
|
page.on('pageerror', lambda error: errors.append(str(error)))
|
|
page.set_content(html)
|
|
page.add_style_tag(content=css)
|
|
page.evaluate(r'''() => {
|
|
window.__submitted = [];
|
|
window.fetch = async (url, opts = {}) => {
|
|
const u = String(url);
|
|
const m = opts.method || 'GET';
|
|
let value = {ok:true};
|
|
if (u === '/api/system') value = {free:100000000000, total:200000000000};
|
|
else if (u === '/api/jobs' && m === 'GET') value = [];
|
|
else if (u === '/api/archive/session' && m === 'GET') value = {authenticated:window.__loggedIn === true,email:window.__loggedIn ? 'demo@example.org' : ''};
|
|
else if (u === '/api/archive/session' && m === 'POST') {window.__loggedIn=true;value={authenticated:true,email:'demo@example.org'};}
|
|
else if (u === '/api/magnet/inspect' && m === 'POST') value = {preview_id:'a'.repeat(32),status:'loading'};
|
|
else if (u.startsWith('/api/magnet/inspect/') && m === 'GET') value = {status:'ready',name:'Sample',suggested:[2],files:[
|
|
{index:1,name:'Sample/Game.iso',size:7210000000,padding:false},
|
|
{index:2,name:'Sample/Manual.pdf',size:15313,padding:false},
|
|
{index:3,name:'Sample/.pad',size:700,padding:true}
|
|
]};
|
|
else if (u === '/api/magnet/jobs' && m === 'POST') {window.__submitted.push(JSON.parse(opts.body));value={ok:true};}
|
|
return new Response(JSON.stringify(value), {status:200,headers:{'Content-Type':'application/json'}});
|
|
};
|
|
}''')
|
|
page.add_script_tag(content=js)
|
|
page.locator('button[data-tab="archive"]').click()
|
|
assert page.locator('#archiveEmail').is_visible()
|
|
page.locator('#archiveEmail').fill('demo@example.org')
|
|
page.locator('#archivePassword').fill('dummy-password')
|
|
page.locator('#archiveLoginForm button[type=submit]').click()
|
|
page.locator('#archiveLogout').wait_for(state='visible')
|
|
page.screenshot(path='/mnt/data/x360-archive-auth-preview.png', full_page=True)
|
|
page.locator('button[data-tab="links"]').click()
|
|
page.locator('#urls').fill('magnet:?xt=urn:btih:c98fbaa2a36ee48e3d9423be02cdbefd9281bc7d&so=1')
|
|
page.locator('#linksForm [type=submit]').click()
|
|
page.locator('#magnetResults').wait_for(state='visible')
|
|
assert page.locator('#magnetFiles input[type="checkbox"]').count() == 3
|
|
assert page.locator('#magnetFiles input[type="checkbox"]').nth(1).is_checked()
|
|
page.screenshot(path='/mnt/data/x360-magnet-select-preview.png', full_page=True)
|
|
page.locator('#magnetFiles input[type="checkbox"]').nth(0).check()
|
|
page.locator('#magnetAdd').click()
|
|
page.locator('#magnetDialog').wait_for(state='hidden')
|
|
assert page.evaluate('window.__submitted') == [
|
|
{'preview_id':'a'*32,'files':[2,1],'title':'','format':'xex'}]
|
|
assert errors == [], errors
|
|
browser.close()
|
|
print('UI smoke PASS: Archive login form, torrent modal, file selection, submit')
|