7 lines
2.8 KiB
JavaScript
7 lines
2.8 KiB
JavaScript
'use strict';
|
|
const retryHistory=(store,id)=>store.db.prepare('SELECT id,payload FROM retry_audit WHERE item_id=? ORDER BY rowid').all(id).map(row=>store.decode(row.id,row.payload));
|
|
const {test}=require('node:test');const assert=require('node:assert/strict');const fs=require('node:fs/promises');const os=require('node:os');const path=require('node:path');const {Store}=require('../../src/modules/dashboard/store.cjs');const {NotificationStore}=require('../../src/modules/notifications/store.cjs');const {NotificationService}=require('../../src/modules/notifications/service.cjs');const {createDashboard}=require('../../src/app/dashboard.cjs');const {loadPlaywright,browserOptions}=require('../../src/platform/browser.cjs');
|
|
test('retired notification route redirects while real historical items remain read-only',{timeout:60000},async t=>{
|
|
const dir=await fs.mkdtemp(path.join(os.tmpdir(),'notice-ui-')),store=new Store(path.join(dir,'users'));store.bootstrap('admin','Test-password-123');const notificationStore=new NotificationStore(path.join(dir,'notifications')),notifications=new NotificationService({store:notificationStore,mail:{},settings:()=>store.settings()}),server=createDashboard({store,notifications,outputDir:dir});const item=notifications.ingest({id:'OLD1',industry:'宽带',brief:'原始简要说明\n第二行',subject:'隔离历史通知'});await new Promise(r=>server.listen(0,'127.0.0.1',r));const browser=await loadPlaywright().chromium.launch(browserOptions());t.after(async()=>{await browser.close();await notifications.stop();server.closeAllConnections();await new Promise(r=>server.close(r));notificationStore.close();await fs.rm(dir,{recursive:true,force:true});});const page=await browser.newPage({viewport:{width:390,height:844}});page.setDefaultTimeout(6000);const writes=[];page.on('request',r=>{if(r.method()==='POST'&&r.url().includes('/notifications'))writes.push(r.url());});await page.goto('http://127.0.0.1:'+server.address().port+'/#notifications');await page.getByLabel('账号',{exact:true}).fill('admin');await page.getByLabel('密码',{exact:true}).fill('Test-password-123');await page.getByRole('button',{name:'登录',exact:true}).click();await page.getByRole('heading',{name:'分类通知规则',exact:true}).waitFor();assert.equal(await page.locator('#notification-settings').count(),0);await page.evaluate(()=>location.hash='records');await page.getByRole('button',{name:'查看旧通知历史(只读)',exact:true}).click();await page.locator('#legacy-notification-history pre').getByText('原始简要说明\n第二行',{exact:true}).waitFor();assert.equal(await page.locator('#legacy-notification-history form').count(),0);assert.equal(notificationStore.items().length,1);assert.deepEqual(writes,[]);assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth),true);
|
|
});
|