29 lines
3.5 KiB
JavaScript
29 lines
3.5 KiB
JavaScript
const {chromium}=require('playwright');const fs=require('fs'),path=require('path'),assert=require('assert');
|
|
const root=path.join(__dirname,'../pigway_frame_flow/web');
|
|
(async()=>{const b=await chromium.launch({headless:true,executablePath:'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'});try{for(const width of [1440,768,390])for(const lang of ['zh','en']){
|
|
const p=await b.newPage({viewport:{width,height:900}});let errors=[];p.on('pageerror',e=>errors.push(e.message));let saved;
|
|
await p.addInitScript(lang=>localStorage.setItem('ff-language',lang),lang);
|
|
await p.route('**/*',async r=>{const u=new URL(r.request().url());if(u.pathname.startsWith('/api/')){
|
|
if(['PUT','POST'].includes(r.request().method())){saved=r.request().postDataJSON();return r.fulfill({json:{}})}
|
|
if(['/api/v1/jobs','/api/v1/assets','/api/v1/devices/living-room/images'].includes(u.pathname))return r.fulfill({json:[]});
|
|
if(u.pathname==='/api/v1/photo-sources')return r.fulfill({json:[]});
|
|
if(u.pathname==='/api/v1/integrations/synology-photos')return r.fulfill({json:{configured:true,connected:true}});
|
|
if(u.pathname.endsWith('/people'))return r.fulfill({json:[{id:1,name:'Test Person',count:5}]});
|
|
return r.fulfill({status:401,json:{error:{code:'UNAUTHORIZED',message:'Sign in required'}}});}
|
|
const f=u.pathname==='/'?'index.html':u.pathname.replace(/^\/ui\//,'');return r.fulfill({body:fs.readFileSync(path.join(root,f)),contentType:f.endsWith('.js')?'application/javascript':f.endsWith('.css')?'text/css':'text/html'});});
|
|
await p.goto('http://frame.test/');await p.locator('#login-form').waitFor();
|
|
await p.evaluate(async()=>{state.templates=[{id:'daily-dashboard',name:'Dashboard',defaults:{}}];await jobEditor();});
|
|
for(const unit of ['hours','minutes']){
|
|
await p.locator('#job-schedule').selectOption(unit);await p.locator('#schedule-value').fill('2');
|
|
assert.equal(await p.locator('#schedule-value').getAttribute('type'),'number');
|
|
assert(await p.locator('#schedule-hint').innerText());
|
|
}
|
|
assert(!await p.evaluate(()=>document.documentElement.scrollWidth>innerWidth));
|
|
await p.locator('#job-name').fill('Test interval');
|
|
await p.locator('#job-form button[type=submit]').click();await p.waitForTimeout(100);
|
|
assert(saved);assert.deepEqual(saved.schedule,{type:'interval',interval_minutes:2});
|
|
await p.evaluate(async()=>{await jobEditor({id:'existing',name:'Existing',schedule:{type:'interval',interval_minutes:120},source:{type:'template',template:'daily-dashboard',data:{}},enabled:false,display_duration:0,restore_previous:false,priority:50});});
|
|
assert.equal(await p.locator('#job-schedule').inputValue(),'hours');assert.equal(await p.locator('#schedule-value').inputValue(),'2');
|
|
await p.evaluate(()=>{state.devices=[{id:'living-room',name:'我的相框'}];});assert.equal(await p.evaluate(()=>deviceDisplayName(state.devices[0])),'我的相框');assert.equal(await p.evaluate(()=>deviceDisplayName({id:'living-room',name:'living-room'})),lang==='zh'?'客厅':'Living room');await p.locator('#modal-cancel').click();await p.evaluate(async()=>{const previous=api;api=async()=>[{id:'fixture',name:'Family',device_id:'living-room',schedule:{type:'interval',interval_minutes:120},enabled:false}];try{await views.automation(state.epoch);}finally{api=previous;}});assert.equal(await p.locator('tbody td small').first().innerText(),'我的相框');assert.equal(errors.length,0,errors.join('\n'));console.log('PASS',width,lang);await p.close();
|
|
}}finally{await b.close()}})().catch(e=>{console.error(e);process.exit(1)});
|