Files
mars_nwe_pcab/tests/test_driver_ui.cjs

26 lines
2.6 KiB
JavaScript

// Optional UI test: npm install --prefix build/ui playwright; playwright install chromium
const {chromium}=require('../build/ui/node_modules/playwright');
const fs=require('fs'),path=require('path'),assert=require('assert');
(async()=>{
const browser=await chromium.launch({args:['--no-sandbox']});
const page=await browser.newPage();const errors=[];page.on('pageerror',e=>errors.push(e.message));
let platforms=[],activated=false;
const state={defaultPassword:false,groups:Object.fromEntries(['1','2','3','4','5','12','13','17','21','45','200'].map(x=>[x,[]])),text:'',revision:'test',csrf:'test',validation:{errors:[]},devices:[],backups:[],path:'/test',services:true};
await page.route('**/*',async route=>{const u=new URL(route.request().url()).pathname;let body;
if(u==='/api/state')body=state;
else if(u==='/api/status')body={'mars-nwe-pcap.service':'ActiveState=inactive','mars-pcapd.service':'ActiveState=inactive'};
else if(u==='/api/drivers')body={platforms,map:activated?'MAP ROOT T:=SYS:PUBLIC/DRIVERS/TEST':''};
else if(u==='/api/drivers/activate'){const data=route.request().postDataJSON();assert.equal(data.confirm,true);assert.deepEqual(data.platforms,['WIN95','WINXP']);platforms=data.platforms;activated=true;body={ok:true};}
else if(u==='/api/gateway')body={config:{enabled:false,network:'0x101',gateway:'10.250.0.1',dns:'1.1.1.1',uplink:'',clients:[]},revision:'r',status:'Disabled'};
else {const file=path.join(__dirname,'../websetup',u==='/'?'index.html':u.slice(1));return route.fulfill({body:fs.readFileSync(file),contentType:u.endsWith('.js')?'text/javascript':u.endsWith('.css')?'text/css':'text/html'});}
return route.fulfill({json:body});});
await page.goto('http://127.0.0.1:18889/');
await page.locator('#gatewayOpen').click();await page.locator('#gwWinClients').click();
await page.waitForFunction(()=>document.querySelector('#driverStatus').textContent.includes('Noch keine'));
assert.equal(await page.locator('a[href^="/drivers/"]:visible').count(),0);
await page.locator('[name=driverOS][value=WIN95]').check();await page.locator('[name=driverOS][value=WINXP]').check();
await page.locator('#activateDrivers').click();await page.waitForFunction(()=>document.querySelector('#driverStatus').textContent.startsWith('MAP ROOT'));
assert.equal(await page.locator('a[href^="/drivers/"]:visible').count(),2);assert(activated);assert.deepEqual(errors,[]);
await page.screenshot({path:path.join(__dirname,'../build/driver-modal.png'),fullPage:true});await browser.close();console.log('PASS Chromium: OS selection, activation, filtered downloads, MAP instruction, modal');
})().catch(e=>{console.error(e);process.exit(1)});