models-visibility.spec.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { test, expect } from "./fixtures"
  2. import { modKey, promptSelector } from "./utils"
  3. test("hiding a model removes it from the model picker", async ({ page, gotoSession }) => {
  4. await gotoSession()
  5. await page.locator(promptSelector).click()
  6. await page.keyboard.type("/model")
  7. const command = page.locator('[data-slash-id="model.choose"]')
  8. await expect(command).toBeVisible()
  9. await command.hover()
  10. await page.keyboard.press("Enter")
  11. const picker = page.getByRole("dialog")
  12. await expect(picker).toBeVisible()
  13. const target = picker.locator('[data-slot="list-item"]').first()
  14. await expect(target).toBeVisible()
  15. const key = await target.getAttribute("data-key")
  16. if (!key) throw new Error("Failed to resolve model key from list item")
  17. const name = (await target.locator("span").first().innerText()).trim()
  18. if (!name) throw new Error("Failed to resolve model name from list item")
  19. await page.keyboard.press("Escape")
  20. await expect(picker).toHaveCount(0)
  21. const settings = page.getByRole("dialog")
  22. await page.keyboard.press(`${modKey}+Comma`).catch(() => undefined)
  23. const opened = await settings
  24. .waitFor({ state: "visible", timeout: 3000 })
  25. .then(() => true)
  26. .catch(() => false)
  27. if (!opened) {
  28. await page.getByRole("button", { name: "Settings" }).first().click()
  29. await expect(settings).toBeVisible()
  30. }
  31. await settings.getByRole("tab", { name: "Models" }).click()
  32. const search = settings.getByPlaceholder("Search models")
  33. await expect(search).toBeVisible()
  34. await search.fill(name)
  35. const toggle = settings.locator('[data-component="switch"]').filter({ hasText: name }).first()
  36. const input = toggle.locator('[data-slot="switch-input"]')
  37. await expect(toggle).toBeVisible()
  38. await expect(input).toHaveAttribute("aria-checked", "true")
  39. await toggle.locator('[data-slot="switch-control"]').click()
  40. await expect(input).toHaveAttribute("aria-checked", "false")
  41. await page.keyboard.press("Escape")
  42. const closed = await settings
  43. .waitFor({ state: "detached", timeout: 1500 })
  44. .then(() => true)
  45. .catch(() => false)
  46. if (!closed) {
  47. await page.keyboard.press("Escape")
  48. const closedSecond = await settings
  49. .waitFor({ state: "detached", timeout: 1500 })
  50. .then(() => true)
  51. .catch(() => false)
  52. if (!closedSecond) {
  53. await page.locator('[data-component="dialog-overlay"]').click({ position: { x: 5, y: 5 } })
  54. await expect(settings).toHaveCount(0)
  55. }
  56. }
  57. await page.locator(promptSelector).click()
  58. await page.keyboard.type("/model")
  59. await expect(command).toBeVisible()
  60. await command.hover()
  61. await page.keyboard.press("Enter")
  62. const pickerAgain = page.getByRole("dialog")
  63. await expect(pickerAgain).toBeVisible()
  64. await expect(pickerAgain.locator('[data-slot="list-item"]').first()).toBeVisible()
  65. await expect(pickerAgain.locator(`[data-slot="list-item"][data-key="${key}"]`)).toHaveCount(0)
  66. await page.keyboard.press("Escape")
  67. await expect(pickerAgain).toHaveCount(0)
  68. })