- Update configuration files directly while preserving custom settings - Add versioned backups, restore previews, and managed-field recovery - Detect first-time setup, outdated configuration, and invalid files - Add conflict detection and rollback for multi-file updates - Simplify configuration actions and clarify OAuth mode - Add backend and UI regression coverage
76 lines
5.7 KiB
JavaScript
76 lines
5.7 KiB
JavaScript
// Run Vite on port 1421, then: node tests/agent-history-ui.cjs
|
|
// Set PLAYWRIGHT_MODULE to an installed Playwright module path when needed.
|
|
const {chromium}=require(process.env.PLAYWRIGHT_MODULE || 'playwright');
|
|
const assert=require('node:assert/strict');
|
|
(async()=>{const browser=await chromium.launch({channel:'msedge',headless:true}); const page=await browser.newPage({viewport:{width:1280,height:900}});
|
|
page.setDefaultTimeout(10000); const errors=[];page.on('pageerror',e=>errors.push(String(e)));
|
|
await page.goto('http://localhost:1421/tests/fixtures/agent-history.html?fresh');
|
|
await page.getByRole('button',{name:'一键接入',exact:true}).waitFor();
|
|
await page.waitForFunction(()=>!document.querySelector('.agent-save-actions .primary-button')?.disabled);
|
|
await page.locator('.agent-settings-title strong').filter({hasText:'Codex'}).waitFor();
|
|
await page.getByRole('button',{name:'一键接入',exact:true}).click();
|
|
await page.getByText('配置已更新,历史备份已保存。',{exact:true}).waitFor();
|
|
await page.getByRole('button',{name:'更新配置',exact:true}).click();
|
|
await page.getByText('配置已是最新,无需更新。',{exact:true}).waitFor();
|
|
assert.equal(await page.getByRole('button',{name:'关闭修改',exact:true}).count(),0);
|
|
assert.equal(await page.locator('textarea').count(),0);
|
|
await page.locator('.agent-save-feedback').waitFor({state:'attached'});
|
|
assert.equal(await page.getByText('已保存',{exact:true}).count(),0);
|
|
const help = page.getByRole('button',{name:'如何选择',exact:true});
|
|
await help.click();
|
|
assert.ok(await page.locator('#agent-signin-hint').isVisible());
|
|
assert.equal(await page.locator('#agent-signin-hint dt').count(),2);
|
|
const positions = await page.locator('#agent-signin-hint').evaluate(el => ({top:el.getBoundingClientRect().top,bottom:document.getElementById('agent-connection-method').getBoundingClientRect().bottom}));
|
|
assert.ok(positions.top >= positions.bottom);
|
|
await page.getByRole('button',{name:'收起说明',exact:true}).click();
|
|
assert.ok(await page.locator('#agent-signin-hint').isHidden());
|
|
await page.getByLabel('接入方式',{exact:true}).selectOption('oauth');
|
|
await page.getByText('未保存',{exact:true}).waitFor();
|
|
await page.getByLabel('接入方式',{exact:true}).selectOption('apikey');
|
|
await page.locator('.agent-save-feedback').waitFor({state:'attached'});
|
|
assert.equal(await page.getByText('已保存',{exact:true}).count(),0);
|
|
assert.equal(await page.getByRole('button',{name:'重建配置',exact:true}).isVisible(),true);
|
|
await page.getByRole('button',{name:'重建配置',exact:true}).click();
|
|
await page.getByRole('button',{name:'确认重建配置',exact:true}).waitFor();
|
|
await page.getByRole('button',{name:'取消',exact:true}).click();
|
|
assert.ok(await page.getByRole('button',{name:'清空配置',exact:true}).isVisible());
|
|
|
|
await page.screenshot({path:'misc/agent-history-main.png',fullPage:true});
|
|
await page.getByRole('button',{name:'配置历史',exact:true}).click();
|
|
await page.locator('.agent-history-columns nav button').first().click();
|
|
await page.locator('.agent-history-changes table').waitFor();
|
|
await page.screenshot({path:'misc/agent-history-dialog.png',fullPage:true});
|
|
const before=await page.evaluate(()=>window.fixtureCalls.filter(c=>c.cmd==='update_agent_config').length);
|
|
await page.locator('.agent-history-modal footer .primary-button').click();
|
|
await page.waitForFunction(()=>!document.querySelector('.agent-history-modal'));
|
|
const after=await page.evaluate(()=>window.fixtureCalls.filter(c=>c.cmd==='update_agent_config').length);
|
|
assert.equal(before,after);
|
|
assert.ok(await page.getByRole('button',{name:'更新配置',exact:true}).isEnabled());
|
|
await page.goto('http://localhost:1421/tests/fixtures/agent-history.html?client=claude-code');
|
|
await page.getByText('Claude Opus 5',{exact:true}).first().waitFor();
|
|
assert.equal(await page.locator('textarea').count(),0);
|
|
await page.screenshot({path:'misc/agent-history-claude.png',fullPage:true});
|
|
await page.goto('http://localhost:1421/tests/fixtures/agent-history.html?embedded&fresh');
|
|
await page.getByRole('button',{name:'一键接入',exact:true}).waitFor();
|
|
await page.getByRole('button',{name:'一键接入',exact:true}).click();
|
|
await page.getByText('配置已更新,历史备份已保存。',{exact:true}).waitFor();
|
|
assert.ok(await page.getByRole('button',{name:'更新配置',exact:true}).isEnabled());
|
|
await page.screenshot({path:'misc/agent-history-onboarding.png',fullPage:true});
|
|
await page.setViewportSize({width:540,height:820});
|
|
await page.getByRole('button',{name:'配置历史',exact:true}).click();
|
|
await page.locator('.agent-history-columns nav button').first().click();
|
|
await page.locator('.agent-history-changes table').waitFor();
|
|
await page.screenshot({path:'misc/agent-history-narrow.png',fullPage:true});
|
|
await page.goto('http://localhost:1421/tests/fixtures/agent-history.html?state=needs-update');
|
|
await page.getByRole('button',{name:'修复接入',exact:true}).waitFor();
|
|
assert.equal(await page.getByRole('button',{name:'一键接入',exact:true}).count(),0);
|
|
await page.getByText('当前接入:CPA 配置需要修复',{exact:true}).waitFor();
|
|
await page.goto('http://localhost:1421/tests/fixtures/agent-history.html?state=invalid');
|
|
await page.getByRole('button',{name:'更新配置',exact:true}).waitFor();
|
|
assert.ok(await page.getByRole('button',{name:'更新配置',exact:true}).isDisabled());
|
|
assert.equal(await page.getByRole('button',{name:'一键接入',exact:true}).count(),0);
|
|
assert.ok(await page.getByRole('button',{name:'重建配置',exact:true}).isEnabled());
|
|
assert.deepEqual(errors,[]);
|
|
console.log('PASS: first/repeated/no-op update, fixed button, original Claude form, history preview/restore, read-only refresh, onboarding, narrow layout');
|
|
await browser.close();})().catch(e=>{console.error(e);process.exit(1)});
|