summaryrefslogtreecommitdiffhomepage
path: root/packages/app/e2e/models/model-picker.spec.ts
blob: 220a0baa1a894c4557464629f5f40972f17d56cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { test, expect } from "../fixtures"
import { promptSelector } from "../selectors"
import { clickListItem } from "../actions"

test("smoke model selection updates prompt footer", async ({ page, gotoSession }) => {
  await gotoSession()

  await page.locator(promptSelector).click()
  await page.keyboard.type("/model")

  const command = page.locator('[data-slash-id="model.choose"]')
  await expect(command).toBeVisible()
  await command.hover()

  await page.keyboard.press("Enter")

  const dialog = page.getByRole("dialog")
  await expect(dialog).toBeVisible()

  const input = dialog.getByRole("textbox").first()

  const selected = dialog.locator('[data-slot="list-item"][data-selected="true"]').first()
  await expect(selected).toBeVisible()

  const other = dialog.locator('[data-slot="list-item"]:not([data-selected="true"])').first()
  const target = (await other.count()) > 0 ? other : selected

  const key = await target.getAttribute("data-key")
  if (!key) throw new Error("Failed to resolve model key from list item")

  const model = key.split(":").slice(1).join(":")

  await input.fill(model)

  await clickListItem(dialog, { key })

  await expect(dialog).toHaveCount(0)

  await page.locator(promptSelector).click()
  await page.keyboard.type("/model")
  await expect(command).toBeVisible()
  await command.hover()
  await page.keyboard.press("Enter")

  const dialogAgain = page.getByRole("dialog")
  await expect(dialogAgain).toBeVisible()
  await expect(dialogAgain.locator(`[data-slot="list-item"][data-key="${key}"][data-selected="true"]`)).toBeVisible()
})