sidebar-session-links.spec.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { test, expect } from "./fixtures"
  2. import { modKey, promptSelector } from "./utils"
  3. type Locator = {
  4. first: () => Locator
  5. getAttribute: (name: string) => Promise<string | null>
  6. scrollIntoViewIfNeeded: () => Promise<void>
  7. click: () => Promise<void>
  8. }
  9. type Page = {
  10. locator: (selector: string) => Locator
  11. keyboard: {
  12. press: (key: string) => Promise<void>
  13. }
  14. }
  15. type Fixtures = {
  16. page: Page
  17. slug: string
  18. sdk: {
  19. session: {
  20. create: (input: { title: string }) => Promise<{ data?: { id?: string } }>
  21. delete: (input: { sessionID: string }) => Promise<unknown>
  22. }
  23. }
  24. gotoSession: (sessionID?: string) => Promise<void>
  25. }
  26. test("sidebar session links navigate to the selected session", async ({ page, slug, sdk, gotoSession }: Fixtures) => {
  27. const stamp = Date.now()
  28. const one = await sdk.session.create({ title: `e2e sidebar nav 1 ${stamp}` }).then((r) => r.data)
  29. const two = await sdk.session.create({ title: `e2e sidebar nav 2 ${stamp}` }).then((r) => r.data)
  30. if (!one?.id) throw new Error("Session create did not return an id")
  31. if (!two?.id) throw new Error("Session create did not return an id")
  32. try {
  33. await gotoSession(one.id)
  34. const main = page.locator("main")
  35. const collapsed = ((await main.getAttribute("class")) ?? "").includes("xl:border-l")
  36. if (collapsed) {
  37. await page.keyboard.press(`${modKey}+B`)
  38. await expect(main).not.toHaveClass(/xl:border-l/)
  39. }
  40. const target = page.locator(`[data-session-id="${two.id}"] a`).first()
  41. await expect(target).toBeVisible()
  42. await target.scrollIntoViewIfNeeded()
  43. await target.click()
  44. await expect(page).toHaveURL(new RegExp(`/${slug}/session/${two.id}(?:\\?|#|$)`))
  45. await expect(page.locator(promptSelector)).toBeVisible()
  46. await expect(page.locator(`[data-session-id="${two.id}"] a`).first()).toHaveClass(/\bactive\b/)
  47. } finally {
  48. await sdk.session.delete({ sessionID: one.id }).catch(() => undefined)
  49. await sdk.session.delete({ sessionID: two.id }).catch(() => undefined)
  50. }
  51. })