const { _electron: electron } = require('playwright'); const fs=require('node:fs/promises'),path=require('node:path'),assert=require('node:assert/strict'); async function saveDialog(dialog){ const closed=dialog.waitForEvent('close'); try { await dialog.locator('#save').click({noWaitAfter:true}); } catch(error){ if(!dialog.isClosed() || !String(error.message).includes('has been closed')) throw error; } await closed; } const root=path.resolve(__dirname,'..'),out=path.join(root,'test-results'); (async()=>{ await fs.mkdir(out,{recursive:true}); const profile=await fs.mkdtemp(path.join(out,'profile-')); const app=await electron.launch({executablePath:process.env.FILEBOW_EXECUTABLE||require('electron'),args:process.env.FILEBOW_EXECUTABLE?[]:[root],env:{...process.env,FILEBOW_TEST:'1',FILEBOW_USER_DATA:profile},timeout:30000}); const errors=[];app.on('window',window=>window.on('pageerror',error=>errors.push(error.message))); app.process().stderr.on('data',data=>{const text=data.toString();if(/Error|Exception/.test(text))process.stderr.write(text);}); try{ const page=await app.firstWindow();await page.waitForSelector('#pick'); await page.screenshot({path:path.join(out,'01-home.png')}); assert.equal(await page.locator('html').getAttribute('lang'),'en'); assert.equal(await app.evaluate(({app})=>app.getLocale()),'en-US'); const state=await page.evaluate(()=>window.orbit.state());assert.equal(state.name,'FileBow');assert.ok(state.native.available,state.native.error); const textFile=path.join(out,'Beispiel.txt');await fs.writeFile(textFile,'FileBow\nGrüße aus Köln.\nLokale Dateikonvertierung.'); await page.evaluate(file=>window.orbit.selectFiles([file]),textFile); await page.locator('[data-action="convert-pdf"]').click(); await page.waitForFunction(()=>document.querySelector('#recent-list').textContent.includes('output file'),{timeout:30000}); let updated=await page.evaluate(()=>window.orbit.state());assert.equal(updated.history[0].status,'success',JSON.stringify(updated.history[0])); await fs.access(updated.history[0].outputs[0]); const pdf=updated.history[0].outputs[0];await page.evaluate(file=>window.orbit.selectFiles([file]),pdf); await page.locator('#tab-tools').click(); const passwordPromise=app.waitForEvent('window');await page.locator('[data-action="password-add"]').click();const password=await passwordPromise; await password.locator('#password').fill('FileBow-Test');await password.locator('#confirm').fill('FileBow-Test');await saveDialog(password); await page.waitForFunction(()=>!document.querySelector('#job:not([hidden])'));updated=await page.evaluate(()=>window.orbit.state());assert.equal(updated.history[0].status,'success'); await page.evaluate(file=>window.orbit.selectFiles([file]),updated.history[0].outputs[0]); const unlockPromise=app.waitForEvent('window');await page.locator('[data-action="password-remove"]').click();const unlock=await unlockPromise;await unlock.locator('#password').fill('FileBow-Test');await saveDialog(unlock); await page.waitForFunction(()=>!document.querySelector('#job:not([hidden])'));updated=await page.evaluate(()=>window.orbit.state());assert.equal(updated.history[0].status,'success'); await page.evaluate(files=>window.orbit.selectFiles(files),[pdf,updated.history[0].outputs[0]]); const combinePromise=app.waitForEvent('window');await page.locator('[data-action="combine"]').click();const combine=await combinePromise;await saveDialog(combine); await page.waitForFunction(()=>!document.querySelector('#job:not([hidden])'));updated=await page.evaluate(()=>window.orbit.state());assert.equal(updated.history[0].status,'success'); const imageFile=path.join(out,'Beispielbild.png');await fs.copyFile(path.join(root,'assets/icon.png'),imageFile);await page.evaluate(file=>window.orbit.selectFiles([file]),imageFile); await page.locator('#tab-tools').click(); const dialogPromise=app.waitForEvent('window');await page.locator('[data-action="edit-resize"]').click();const edit=await dialogPromise; await edit.waitForSelector('#width',{timeout:30000});await edit.locator('#width').fill('96');await edit.screenshot({path:path.join(out,'02-resize.png')}); await saveDialog(edit);await page.waitForFunction(()=>!document.querySelector('#job:not([hidden])')); updated=await page.evaluate(()=>window.orbit.state());assert.equal(updated.history[0].status,'success'); const compressPromise=app.waitForEvent('window');await page.locator('[data-action="compress"]').click();const compress=await compressPromise;await compress.locator('#quality').fill('65');await compress.waitForFunction(()=>document.querySelector('#estimate').textContent.includes('Expected size'),null,{timeout:30000});await compress.screenshot({path:path.join(out,'06-compression.png')});await saveDialog(compress); await page.waitForFunction(()=>!document.querySelector('#job:not([hidden])'));updated=await page.evaluate(()=>window.orbit.state());assert.equal(updated.history[0].status,'success'); assert.ok(updated.history[0].outputs[0].endsWith('.png')); await page.locator('#tab-quick').click(); const formatsPromise=app.waitForEvent('window');await page.locator('[data-action="more-formats"]').click();const formats=await formatsPromise; await formats.locator('#format').selectOption('tiff');await saveDialog(formats); await page.waitForFunction(()=>!document.querySelector('#job:not([hidden])'));updated=await page.evaluate(()=>window.orbit.state());assert.equal(updated.history[0].status,'success');assert.ok(updated.history[0].outputs[0].endsWith('.tiff')); await page.locator('[data-action="convert-gif"]').click(); await page.waitForFunction(()=>!document.querySelector('#job:not([hidden])'));updated=await page.evaluate(()=>window.orbit.state());assert.equal(updated.history[0].status,'success');assert.ok(updated.history[0].outputs[0].endsWith('.gif')); const wheelPromise=app.waitForEvent('window');await page.locator('#wheel-open').click();const wheel=await wheelPromise; await wheel.waitForSelector('.action');await wheel.screenshot({path:path.join(out,'03-wheel.png')});await wheel.keyboard.press('Escape'); await page.locator('[data-page="settings"]').click();await page.locator('#theme').selectOption('light');await page.waitForFunction(()=>document.documentElement.dataset.theme==='light');await page.screenshot({path:path.join(out,'04-settings-light.png')}); await page.locator('#theme').selectOption('dark');await page.locator('[data-page="history"]').click();await page.screenshot({path:path.join(out,'05-history.png')}); await page.locator('[data-page="about"]').click(); await app.evaluate(({shell})=>{global.__supportUrls=[];shell.openExternal=async url=>{global.__supportUrls.push(url);};}); assert.equal(await page.locator('aside #support').count(),1); await page.locator('aside #support').click(); await page.locator('#contact').click(); assert.deepEqual(await app.evaluate(()=>global.__supportUrls),['https://ko-fi.com/E0Z827VO8I','mailto:filebow@nordik.dev']); await page.screenshot({path:path.join(out,'07-about.png')}); const hiddenInTray=await app.evaluate(({BrowserWindow})=>{ const main=BrowserWindow.getAllWindows().find(window=>window.getTitle()==='FileBow'); main.close();return !main.isDestroyed()&&!main.isVisible(); }); assert.equal(hiddenInTray,true,'Closing the main window should keep the app running in the tray'); assert.deepEqual(errors,[]);await fs.writeFile(path.join(out,'ui-result.json'),JSON.stringify({passed:true,native:state.native,history:updated.history.map(x=>({label:x.label,status:x.status})),errors},null,2)); console.log('UI smoke passed: startup, native bridge, conversion, PDF passwords, combining, compression, editor, radial menu, themes, history.'); }finally{await app.close();} })().catch(error=>{console.error(error);process.exitCode=1;});