session.spec.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import { test, expect } from "../fixtures"
  2. import {
  3. openSidebar,
  4. openSessionMoreMenu,
  5. clickMenuItem,
  6. confirmDialog,
  7. openSharePopover,
  8. withSession,
  9. } from "../actions"
  10. import { sessionItemSelector, inlineInputSelector } from "../selectors"
  11. const shareDisabled = process.env.OPENCODE_DISABLE_SHARE === "true" || process.env.OPENCODE_DISABLE_SHARE === "1"
  12. test("sidebar session can be renamed", async ({ page, sdk, gotoSession }) => {
  13. const stamp = Date.now()
  14. const originalTitle = `e2e rename test ${stamp}`
  15. const newTitle = `e2e renamed ${stamp}`
  16. await withSession(sdk, originalTitle, async (session) => {
  17. await gotoSession(session.id)
  18. await openSidebar(page)
  19. const menu = await openSessionMoreMenu(page, session.id)
  20. await clickMenuItem(menu, /rename/i)
  21. const input = page.locator(sessionItemSelector(session.id)).locator(inlineInputSelector).first()
  22. await expect(input).toBeVisible()
  23. await input.fill(newTitle)
  24. await input.press("Enter")
  25. await expect(page.locator(sessionItemSelector(session.id)).locator("a").first()).toContainText(newTitle)
  26. })
  27. })
  28. test("sidebar session can be archived", async ({ page, sdk, gotoSession }) => {
  29. const stamp = Date.now()
  30. const title = `e2e archive test ${stamp}`
  31. await withSession(sdk, title, async (session) => {
  32. await gotoSession(session.id)
  33. await openSidebar(page)
  34. const sessionEl = page.locator(sessionItemSelector(session.id))
  35. const menu = await openSessionMoreMenu(page, session.id)
  36. await clickMenuItem(menu, /archive/i)
  37. await expect(sessionEl).not.toBeVisible()
  38. })
  39. })
  40. test("sidebar session can be deleted", async ({ page, sdk, gotoSession }) => {
  41. const stamp = Date.now()
  42. const title = `e2e delete test ${stamp}`
  43. await withSession(sdk, title, async (session) => {
  44. await gotoSession(session.id)
  45. await openSidebar(page)
  46. const sessionEl = page.locator(sessionItemSelector(session.id))
  47. const menu = await openSessionMoreMenu(page, session.id)
  48. await clickMenuItem(menu, /delete/i)
  49. await confirmDialog(page, /delete/i)
  50. await expect(sessionEl).not.toBeVisible()
  51. })
  52. })
  53. test("session can be shared and unshared via header button", async ({ page, sdk, gotoSession }) => {
  54. test.skip(shareDisabled, "Share is disabled in this environment (OPENCODE_DISABLE_SHARE).")
  55. const stamp = Date.now()
  56. const title = `e2e share test ${stamp}`
  57. await withSession(sdk, title, async (session) => {
  58. await gotoSession(session.id)
  59. const { rightSection, popoverBody } = await openSharePopover(page)
  60. await popoverBody.getByRole("button", { name: "Publish" }).first().click()
  61. await expect
  62. .poll(
  63. async () => {
  64. const data = await sdk.session.get({ sessionID: session.id }).then((r) => r.data)
  65. return data?.share?.url || undefined
  66. },
  67. { timeout: 30_000 },
  68. )
  69. .not.toBeUndefined()
  70. const copyButton = rightSection.locator('button[aria-label="Copy link"]').first()
  71. await expect(copyButton).toBeVisible({ timeout: 30_000 })
  72. const sharedPopover = await openSharePopover(page)
  73. const unpublish = sharedPopover.popoverBody.getByRole("button", { name: "Unpublish" }).first()
  74. await expect(unpublish).toBeVisible({ timeout: 30_000 })
  75. await unpublish.click()
  76. await expect
  77. .poll(
  78. async () => {
  79. const data = await sdk.session.get({ sessionID: session.id }).then((r) => r.data)
  80. return data?.share?.url || undefined
  81. },
  82. { timeout: 30_000 },
  83. )
  84. .toBeUndefined()
  85. await expect(copyButton).not.toBeVisible({ timeout: 30_000 })
  86. const unsharedPopover = await openSharePopover(page)
  87. await expect(unsharedPopover.popoverBody.getByRole("button", { name: "Publish" }).first()).toBeVisible({
  88. timeout: 30_000,
  89. })
  90. })
  91. })