// 设置 → 生图服务:渠道 / 模型 的增删(2026-11-10 新增) // // 为什么加:SettingsModal 里 37 个 CRUD setter 共 223 行,是全仓最大的"无直接测试"状态簇 // (此前只有 1 条 e2e 覆盖「厂商类型」,增删渠道/模型完全没测)。 // 这组用例是任何后续拆分(例如抽 useSettingsDraft)的**前置安全网**: // 先把行为钉住,再谈搬家。 // // 选择器依据实际 DOM(2026-11-10 探针确认): // · 渠道卡片 .iwb-provider-card;删除渠道 = 文案「删除服务」 // · 模型行 .iwb-modelrow;删除模型 = 行内垃圾桶按钮 title「删除模型」(aria-label 带模型名) // · 添加模型 = 模型输入框所在行里的按钮(输入框 placeholder「手动添加模型名」) const { test, expect } = require('./_pw-coverage') const baseURL = process.env.IWB_BASE_URL || 'http://127.0.0.1:8787' test.use({ baseURL, viewport: { width: 1600, height: 1100 } }) const CFG = { providers: [{ id: 'p-crud', name: 'CRUD 渠道', baseUrl: 'https://crud.example/v1', keys: [{ id: 'k-1', name: 'K', value: 'sk-test' }], models: [{ id: 'm-1', name: 'crud-model-1' }], }], canvas: {}, } async function openSettings (page) { const nav = page.locator('.iwb-nav-item[title="设置"]') if (await nav.count() > 0) { await nav.first().click() } else { const cands = [ page.locator('.iwb-home-side-item', { hasText: '设置' }), page.locator('.iwb-home-menu-item', { hasText: '设置' }), page.locator('[title="服务与 Key 设置"]'), ] for (const c of cands) if (await c.count() > 0) { await c.first().click(); break } } // 设置默认打开「通用」标签(2026-11-25 用户裁定)→ 生图服务的用例需显式切过去 await page.locator('.iwb-set-nav-item', { hasText: '生图服务' }).first().click() await expect(page.locator('.iwb-prov-chip').first()).toBeVisible({ timeout: 10000 }) } const readCfg = (page) => page.evaluate(() => { const raw = localStorage.getItem('iwb_web_cfg') return raw ? JSON.parse(raw) : {} }) test.beforeEach(async ({ page }) => { await page.addInitScript((cfg) => { localStorage.clear() localStorage.setItem('iwb_web_cfg', JSON.stringify(cfg)) }, CFG) await page.goto('/', { waitUntil: 'domcontentloaded' }) }) test('① 渠道可新增与删除,且改动会写入配置', async ({ page }) => { const errors = [] page.on('pageerror', (e) => errors.push(String((e && e.message) || e))) await openSettings(page) const cards = page.locator('.iwb-provider-card') const chips = page.locator('.iwb-prov-chip') await expect(cards).toHaveCount(1, { timeout: 8000 }) await expect(chips).toHaveCount(1, { timeout: 8000 }) await page.locator('button', { hasText: '+ 添加服务商' }).first().click() await expect(chips).toHaveCount(2, { timeout: 8000 }) // 单栏设计:同时只渲染一份详情(新服务自动选中) await expect(cards).toHaveCount(1, { timeout: 8000 }) await expect(page.locator('.iwb-prov-name')).toHaveValue('新服务') // 删当前(新加的)服务商;不删种子渠道 await page.locator('.iwb-provider-card button', { hasText: '删除服务' }).first().click() await expect(chips).toHaveCount(1, { timeout: 8000 }) await expect(page.locator('.iwb-prov-name')).toHaveValue('CRUD 渠道') await page.locator('button', { hasText: '保存配置' }).first().click() await expect.poll(async () => ((await readCfg(page)).providers || []).length, { timeout: 10000 }).toBe(1) const cfg = await readCfg(page) expect((cfg.providers || [])[0].name, '种子渠道应保留').toBe('CRUD 渠道') expect(errors, '不应有页面异常').toEqual([]) }) test('② 模型可新增与删除,且改动会写入配置', async ({ page }) => { const errors = [] page.on('pageerror', (e) => errors.push(String((e && e.message) || e))) await openSettings(page) const card = page.locator('.iwb-provider-card').first() const rows = card.locator('.iwb-modelrow') await expect(rows).toHaveCount(1, { timeout: 8000 }) // 注意顺序:点「保存配置」会关闭弹窗 ⇒ 增删都要在保存**之前**做完(2026-11-10 踩到) const input = card.locator('input[placeholder="手动添加模型名"]').first() // 用 xpath 取「输入框所在行」的按钮 —— 比 filter({has: card.locator(...)}) 稳: // 后者把 card 作用域嵌进 has 里,第二次使用时解析不到(2026-11-10 踩到超时) const addBtn = card.locator('input[placeholder="手动添加模型名"]').first() .locator('xpath=..').locator('button').first() // 新增 → 2 行 await input.fill('crud-model-2') await addBtn.click() await expect(rows).toHaveCount(2, { timeout: 8000 }) // 删除刚加的 → 回到 1 行 // 2026-11-25(三改):垃圾桶常驻,但**点一次只进入确认态**,第二次才真删(没有节点引用时不弹对话框)。 // 第二次点击必须按类名取:进入确认态后 title / aria-label 都会变,按文案取会失配。 const lastDel = rows.last().locator('button.iwb-model-del') await lastDel.click() await expect(lastDel).toHaveText('确认删除', { timeout: 4000 }) await expect(rows).toHaveCount(2, { timeout: 4000 }) await lastDel.click() await expect(rows).toHaveCount(1, { timeout: 8000 }) // 再加一次并保存 → 配置里应含新模型(同时验证"删了再加"不会把列表搞坏) await input.fill('crud-model-3') await addBtn.click() await expect(rows).toHaveCount(2, { timeout: 8000 }) await page.locator('button', { hasText: '保存配置' }).first().click() await expect.poll(async () => { const p = ((await readCfg(page)).providers || [])[0] || {} return (p.models || []).map((m) => m.name).sort().join(',') }, { timeout: 10000 }).toBe('crud-model-1,crud-model-3') expect(errors, '不应有页面异常').toEqual([]) })