Files
order-notification-automation/tests/mail/history-ui.test.cjs
T

22 lines
3.2 KiB
JavaScript

'use strict';
const {test}=require('node:test'),assert=require('node:assert/strict'),fs=require('node:fs'),os=require('node:os'),path=require('node:path');
const {startTestDashboard,login}=require('../fixtures/dashboard-runtime.cjs');const {loadPlaywright,browserOptions}=require('../../src/platform/browser.cjs');
test('history UI saves IMAP-only credentials locally, explicitly queries sent mail and displays escaped evidence',async t=>{
const dir=fs.mkdtempSync(path.join(os.tmpdir(),'history-ui-'));const runtime=await startTestDashboard({stateDir:dir,mailHistory:true});let browser;
t.after(async()=>{await browser?.close();await runtime.close();fs.rmSync(dir,{recursive:true,force:true});});
let connects=0;
const raw=Buffer.from('From: sender@example.test\r\nTo: orders@example.test\r\nSubject: Test notice\r\nContent-Type: text/plain; charset=utf-8\r\n\r\n<img src="https://tracker.example.test/pixel"> Huizhou evidence');
runtime.mail.imapFactory=()=>({mailbox:{uidValidity:1n},on(){},async connect(){connects++;},async list(){return [{path:'Sent',specialUse:'\\Sent'}];},async getMailboxLock(_path,opts){assert.equal(opts.readOnly,true);return {release(){}};},async search(){return [1];},async fetchOne(uid,q){return q.source?{source:raw}:{uid,size:raw.length,envelope:{subject:'Test notice'}};},async logout(){},close(){}});
browser=await loadPlaywright().chromium.launch(browserOptions());const page=await browser.newPage();const requests=[];page.on('request',r=>requests.push(r.url()));
await page.goto('http://127.0.0.1:'+runtime.server.address().port+'/#mail');await login(page);await page.getByRole('button',{name:'只读查阅已发送邮件',exact:true}).click();
await page.getByRole('button',{name:'添加只读邮箱',exact:true}).click({timeout:5000});
for(const [label,value]of [['邮箱名称','历史核对'],['邮箱地址','orders@example.test'],['IMAP 服务器','imap.example.test'],['IMAP 登录账号','orders@example.test'],['IMAP 授权码','History-123']])await page.getByLabel(label,{exact:true}).fill(value);
await page.getByRole('button',{name:'保存只读邮箱',exact:true}).click();await page.getByText('只读邮箱已保存。',{exact:true}).waitFor();assert.equal(connects,0);
await page.getByRole('button',{name:'连接并列出已发送文件夹',exact:true}).click();await page.getByLabel('已发送文件夹',{exact:true}).selectOption('Sent');
await page.getByRole('button',{name:'查询已发送邮件',exact:true}).click();await page.getByRole('button',{name:'查看邮件',exact:true}).click();
await page.getByText('<img src="https://tracker.example.test/pixel"> Huizhou evidence',{exact:true}).waitFor();
assert.equal(requests.some(r=>r.startsWith('https://tracker.example.test')),false);assert.equal(await page.getByRole('button',{name:/发送测试/}).count(),0);
assert.equal(runtime.mail.store.channels()[0].smtp.hasPassword,false);await page.getByRole('button',{name:'返回邮箱管理',exact:true}).click();await page.getByRole('button',{name:'只读查阅已发送邮件',exact:true}).waitFor();await page.getByRole('button',{name:'只读查阅已发送邮件',exact:true}).click();
await page.setViewportSize({width:390,height:844});assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth),true);
});