settings-models.spec.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { test, expect } from "../fixtures"
  2. import { promptSelector } from "../selectors"
  3. import { closeDialog, openSettings } from "../actions"
  4. test("hiding a model removes it from the model picker", async ({ page, gotoSession }) => {
  5. await gotoSession()
  6. await page.locator(promptSelector).click()
  7. await page.keyboard.type("/model")
  8. const command = page.locator('[data-slash-id="model.choose"]')
  9. await expect(command).toBeVisible()
  10. await command.hover()
  11. await page.keyboard.press("Enter")
  12. const picker = page.getByRole("dialog")
  13. await expect(picker).toBeVisible()
  14. const target = picker.locator('[data-slot="list-item"]').first()
  15. await expect(target).toBeVisible()
  16. const key = await target.getAttribute("data-key")
  17. if (!key) throw new Error("Failed to resolve model key from list item")
  18. const name = (await target.locator("span").first().innerText()).trim()
  19. if (!name) throw new Error("Failed to resolve model name from list item")
  20. await page.keyboard.press("Escape")
  21. await expect(picker).toHaveCount(0)
  22. const settings = await openSettings(page)
  23. await settings.getByRole("tab", { name: "Models" }).click()
  24. const search = settings.getByPlaceholder("Search models")
  25. await expect(search).toBeVisible()
  26. await search.fill(name)
  27. const toggle = settings.locator('[data-component="switch"]').filter({ hasText: name }).first()
  28. const input = toggle.locator('[data-slot="switch-input"]')
  29. await expect(toggle).toBeVisible()
  30. await expect(input).toHaveAttribute("aria-checked", "true")
  31. await toggle.locator('[data-slot="switch-control"]').click()
  32. await expect(input).toHaveAttribute("aria-checked", "false")
  33. await closeDialog(page, settings)
  34. await page.locator(promptSelector).click()
  35. await page.keyboard.type("/model")
  36. await expect(command).toBeVisible()
  37. await command.hover()
  38. await page.keyboard.press("Enter")
  39. const pickerAgain = page.getByRole("dialog")
  40. await expect(pickerAgain).toBeVisible()
  41. await expect(pickerAgain.locator('[data-slot="list-item"]').first()).toBeVisible()
  42. await expect(pickerAgain.locator(`[data-slot="list-item"][data-key="${key}"]`)).toHaveCount(0)
  43. await page.keyboard.press("Escape")
  44. await expect(pickerAgain).toHaveCount(0)
  45. })
  46. test("showing a hidden model restores it to the model picker", async ({ page, gotoSession }) => {
  47. await gotoSession()
  48. await page.locator(promptSelector).click()
  49. await page.keyboard.type("/model")
  50. const command = page.locator('[data-slash-id="model.choose"]')
  51. await expect(command).toBeVisible()
  52. await command.hover()
  53. await page.keyboard.press("Enter")
  54. const picker = page.getByRole("dialog")
  55. await expect(picker).toBeVisible()
  56. const target = picker.locator('[data-slot="list-item"]').first()
  57. await expect(target).toBeVisible()
  58. const key = await target.getAttribute("data-key")
  59. if (!key) throw new Error("Failed to resolve model key from list item")
  60. const name = (await target.locator("span").first().innerText()).trim()
  61. if (!name) throw new Error("Failed to resolve model name from list item")
  62. await page.keyboard.press("Escape")
  63. await expect(picker).toHaveCount(0)
  64. const settings = await openSettings(page)
  65. await settings.getByRole("tab", { name: "Models" }).click()
  66. const search = settings.getByPlaceholder("Search models")
  67. await expect(search).toBeVisible()
  68. await search.fill(name)
  69. const toggle = settings.locator('[data-component="switch"]').filter({ hasText: name }).first()
  70. const input = toggle.locator('[data-slot="switch-input"]')
  71. await expect(toggle).toBeVisible()
  72. await expect(input).toHaveAttribute("aria-checked", "true")
  73. await toggle.locator('[data-slot="switch-control"]').click()
  74. await expect(input).toHaveAttribute("aria-checked", "false")
  75. await toggle.locator('[data-slot="switch-control"]').click()
  76. await expect(input).toHaveAttribute("aria-checked", "true")
  77. await closeDialog(page, settings)
  78. await page.locator(promptSelector).click()
  79. await page.keyboard.type("/model")
  80. await expect(command).toBeVisible()
  81. await command.hover()
  82. await page.keyboard.press("Enter")
  83. const pickerAgain = page.getByRole("dialog")
  84. await expect(pickerAgain).toBeVisible()
  85. await expect(pickerAgain.locator(`[data-slot="list-item"][data-key="${key}"]`)).toBeVisible()
  86. await page.keyboard.press("Escape")
  87. await expect(pickerAgain).toHaveCount(0)
  88. })