settings-providers.spec.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import { test, expect } from "../fixtures"
  2. import { closeDialog, openSettings } from "../actions"
  3. test("custom provider form can be filled and validates input", async ({ page, gotoSession }) => {
  4. await gotoSession()
  5. const settings = await openSettings(page)
  6. await settings.getByRole("tab", { name: "Providers" }).click()
  7. const customProviderSection = settings.locator('[data-component="custom-provider-section"]')
  8. await expect(customProviderSection).toBeVisible()
  9. const connectButton = customProviderSection.getByRole("button", { name: "Connect" })
  10. await connectButton.click()
  11. const providerDialog = page.getByRole("dialog").filter({ has: page.getByText("Custom provider") })
  12. await expect(providerDialog).toBeVisible()
  13. await providerDialog.getByLabel("Provider ID").fill("test-provider")
  14. await providerDialog.getByLabel("Display name").fill("Test Provider")
  15. await providerDialog.getByLabel("Base URL").fill("http://localhost:9999/fake")
  16. await providerDialog.getByLabel("API key").fill("fake-key")
  17. await providerDialog.getByPlaceholder("model-id").first().fill("test-model")
  18. await providerDialog.getByPlaceholder("Display Name").first().fill("Test Model")
  19. await expect(providerDialog.getByRole("textbox", { name: "Provider ID" })).toHaveValue("test-provider")
  20. await expect(providerDialog.getByRole("textbox", { name: "Display name" })).toHaveValue("Test Provider")
  21. await expect(providerDialog.getByRole("textbox", { name: "Base URL" })).toHaveValue("http://localhost:9999/fake")
  22. await expect(providerDialog.getByRole("textbox", { name: "API key" })).toHaveValue("fake-key")
  23. await expect(providerDialog.getByPlaceholder("model-id").first()).toHaveValue("test-model")
  24. await expect(providerDialog.getByPlaceholder("Display Name").first()).toHaveValue("Test Model")
  25. await page.keyboard.press("Escape")
  26. await expect(providerDialog).toHaveCount(0)
  27. await closeDialog(page, settings)
  28. })
  29. test("custom provider form shows validation errors", async ({ page, gotoSession }) => {
  30. await gotoSession()
  31. const settings = await openSettings(page)
  32. await settings.getByRole("tab", { name: "Providers" }).click()
  33. const customProviderSection = settings.locator('[data-component="custom-provider-section"]')
  34. await customProviderSection.getByRole("button", { name: "Connect" }).click()
  35. const providerDialog = page.getByRole("dialog").filter({ has: page.getByText("Custom provider") })
  36. await expect(providerDialog).toBeVisible()
  37. await providerDialog.getByLabel("Provider ID").fill("invalid provider id")
  38. await providerDialog.getByLabel("Base URL").fill("not-a-url")
  39. await providerDialog.getByRole("button", { name: /submit|save/i }).click()
  40. await expect(providerDialog.locator('[data-slot="input-error"]').filter({ hasText: /lowercase/i })).toBeVisible()
  41. await expect(providerDialog.locator('[data-slot="input-error"]').filter({ hasText: /http/i })).toBeVisible()
  42. await page.keyboard.press("Escape")
  43. await expect(providerDialog).toHaveCount(0)
  44. await closeDialog(page, settings)
  45. })
  46. test("custom provider form can add and remove models", async ({ page, gotoSession }) => {
  47. await gotoSession()
  48. const settings = await openSettings(page)
  49. await settings.getByRole("tab", { name: "Providers" }).click()
  50. const customProviderSection = settings.locator('[data-component="custom-provider-section"]')
  51. await customProviderSection.getByRole("button", { name: "Connect" }).click()
  52. const providerDialog = page.getByRole("dialog").filter({ has: page.getByText("Custom provider") })
  53. await expect(providerDialog).toBeVisible()
  54. await providerDialog.getByLabel("Provider ID").fill("multi-model-test")
  55. await providerDialog.getByLabel("Display name").fill("Multi Model Test")
  56. await providerDialog.getByLabel("Base URL").fill("http://localhost:9999/multi")
  57. await providerDialog.getByPlaceholder("model-id").first().fill("model-1")
  58. await providerDialog.getByPlaceholder("Display Name").first().fill("Model 1")
  59. const idInputsBefore = await providerDialog.getByPlaceholder("model-id").count()
  60. await providerDialog.getByRole("button", { name: "Add model" }).click()
  61. const idInputsAfter = await providerDialog.getByPlaceholder("model-id").count()
  62. expect(idInputsAfter).toBe(idInputsBefore + 1)
  63. await providerDialog.getByPlaceholder("model-id").nth(1).fill("model-2")
  64. await providerDialog.getByPlaceholder("Display Name").nth(1).fill("Model 2")
  65. await expect(providerDialog.getByPlaceholder("model-id").nth(1)).toHaveValue("model-2")
  66. await expect(providerDialog.getByPlaceholder("Display Name").nth(1)).toHaveValue("Model 2")
  67. await page.keyboard.press("Escape")
  68. await expect(providerDialog).toHaveCount(0)
  69. await closeDialog(page, settings)
  70. })
  71. test("custom provider form can add and remove headers", async ({ page, gotoSession }) => {
  72. await gotoSession()
  73. const settings = await openSettings(page)
  74. await settings.getByRole("tab", { name: "Providers" }).click()
  75. const customProviderSection = settings.locator('[data-component="custom-provider-section"]')
  76. await customProviderSection.getByRole("button", { name: "Connect" }).click()
  77. const providerDialog = page.getByRole("dialog").filter({ has: page.getByText("Custom provider") })
  78. await expect(providerDialog).toBeVisible()
  79. await providerDialog.getByLabel("Provider ID").fill("header-test")
  80. await providerDialog.getByLabel("Display name").fill("Header Test")
  81. await providerDialog.getByLabel("Base URL").fill("http://localhost:9999/headers")
  82. await providerDialog.getByPlaceholder("model-id").first().fill("model-x")
  83. await providerDialog.getByPlaceholder("Display Name").first().fill("Model X")
  84. const headerInputsBefore = await providerDialog.getByPlaceholder("Header-Name").count()
  85. await providerDialog.getByRole("button", { name: "Add header" }).click()
  86. const headerInputsAfter = await providerDialog.getByPlaceholder("Header-Name").count()
  87. expect(headerInputsAfter).toBe(headerInputsBefore + 1)
  88. await providerDialog.getByPlaceholder("Header-Name").first().fill("Authorization")
  89. await providerDialog.getByPlaceholder("value").first().fill("Bearer token123")
  90. await expect(providerDialog.getByPlaceholder("Header-Name").first()).toHaveValue("Authorization")
  91. await expect(providerDialog.getByPlaceholder("value").first()).toHaveValue("Bearer token123")
  92. await page.keyboard.press("Escape")
  93. await expect(providerDialog).toHaveCount(0)
  94. await closeDialog(page, settings)
  95. })