本仓 2026-08-12 从 ssw main (192.168.1.18:13300/ssw/ssw-mvp) 的 dacli/ subpath 抽取,作为独立仓托管到 gitea:3000/ssw/dacli.git。 - 工作树为 ssw main dacli subpath 最新版 (110 commit, 08-12) - 历史未带 ssw main 整体历史(避免大仓污染) - 此为新仓基线 commit,未来以本仓历史为主
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
/**
|
|
* _helpers/modal.ts — 模态框 helpers
|
|
*
|
|
* 用法:
|
|
* await waitFormModalReady(page) // 等打开
|
|
* await fillByLabel(...)
|
|
* await saveModal(page) // 触发保存
|
|
* await waitModalClose(page) // 等自动关闭
|
|
* // 或:
|
|
* const errs = await getErrors(page)
|
|
* if (errs.length > 0) throw new Error(errs.join(', '))
|
|
*/
|
|
|
|
import type { Page } from '@playwright/test'
|
|
import { SEL, formItemByLabel } from './selectors'
|
|
|
|
/** 等 modal 打开 + form 字段渲染 */
|
|
export async function waitOpen(page: Page, timeout = 10_000) {
|
|
await page.waitForSelector(SEL.MODAL, { timeout })
|
|
await page.waitForSelector(`${SEL.MODAL} ${SEL.FORM_ITEM}`, {
|
|
timeout,
|
|
})
|
|
await page.waitForTimeout(200)
|
|
}
|
|
|
|
/** 等 modal 关闭 */
|
|
export async function waitClose(page: Page, timeout = 15_000) {
|
|
await page.waitForSelector(SEL.MODAL, {
|
|
state: 'hidden',
|
|
timeout,
|
|
})
|
|
}
|
|
|
|
/** 拿校验错误文字列表 */
|
|
export async function getErrors(page: Page): Promise<string[]> {
|
|
const errs = page.locator(SEL.FORM_ITEM_ERROR)
|
|
return await errs.allTextContents()
|
|
}
|
|
|
|
/** modal 是否可见 */
|
|
export async function isOpen(page: Page): Promise<boolean> {
|
|
return (await page.locator(SEL.MODAL).count()) > 0
|
|
}
|
|
|
|
/** 拿 modal 标题 (e.g. "新增", "编辑", "提示") */
|
|
export async function getTitle(page: Page): Promise<string> {
|
|
const title = page.locator('.ant-modal-title').first()
|
|
if ((await title.count()) === 0) return ''
|
|
return ((await title.textContent()) ?? '').trim()
|
|
}
|