model-input-layout.ts 1.4 KB

12345678910111213141516171819202122232425
  1. /** Model input types stay below both capacity fields across editor widths. */
  2. import type { Locator, Page } from 'playwright'
  3. import { expect } from 'vitest'
  4. /** Verify the expanded row at the current viewport and a narrow viewport, restoring the caller's size. */
  5. export async function assertModelInputLayout(page: Page, editor: Locator): Promise<void> {
  6. const original = page.viewportSize()
  7. try {
  8. for (const viewport of [original, { width: 760, height: 1000 }]) {
  9. if (viewport !== null) await page.setViewportSize(viewport)
  10. const context = await editor.getByLabel('上下文窗口 1', { exact: true }).boundingBox()
  11. const output = await editor.getByLabel('最大输出 token 数 1', { exact: true }).boundingBox()
  12. const types = await editor.getByRole('group', { name: '输入类型 1' }).boundingBox()
  13. expect(context).not.toBeNull()
  14. expect(output).not.toBeNull()
  15. expect(types).not.toBeNull()
  16. if (context === null || output === null || types === null) throw new Error('Expanded model fields are not visible')
  17. expect(Math.abs(context.y - output.y)).toBeLessThan(1)
  18. expect(types.y).toBeGreaterThanOrEqual(Math.max(context.y + context.height, output.y + output.height))
  19. expect(types.width).toBeGreaterThan(context.width)
  20. }
  21. } finally {
  22. if (original !== null) await page.setViewportSize(original)
  23. }
  24. }