model-input-layout.ts 1.6 KB

12345678910111213141516171819202122232425262728293031
  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. /**
  5. * Verify the expanded row at the current viewport and a narrow viewport.
  6. * @param page - page with an explicit viewport, restored even when an assertion fails.
  7. * @param editor - expanded model editor containing the capacity and input-type fields.
  8. * @returns after checking both widths and restoring the caller's size.
  9. */
  10. export async function assertModelInputLayout(page: Page, editor: Locator): Promise<void> {
  11. const original = page.viewportSize()
  12. if (original === null) throw new Error('Model input layout checks require an explicit viewport')
  13. try {
  14. for (const viewport of [original, { width: 760, height: 1000 }]) {
  15. await page.setViewportSize(viewport)
  16. const context = await editor.getByLabel('上下文窗口 1', { exact: true }).boundingBox()
  17. const output = await editor.getByLabel('最大输出 token 数 1', { exact: true }).boundingBox()
  18. const types = await editor.getByRole('group', { name: '输入类型 1' }).boundingBox()
  19. expect(context).not.toBeNull()
  20. expect(output).not.toBeNull()
  21. expect(types).not.toBeNull()
  22. if (context === null || output === null || types === null) throw new Error('Expanded model fields are not visible')
  23. expect(Math.abs(context.y - output.y)).toBeLessThan(1)
  24. expect(types.y).toBeGreaterThanOrEqual(Math.max(context.y + context.height, output.y + output.height))
  25. expect(types.width).toBeGreaterThan(context.width)
  26. }
  27. } finally {
  28. await page.setViewportSize(original)
  29. }
  30. }