open-file-expand-folder.spec.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import { base64Encode } from "@opencode-ai/core/util/encode"
  2. import { expect, test } from "@playwright/test"
  3. import { mockOpenCodeServer } from "../utils/mock-server"
  4. import { expectSessionTitle } from "../utils/waits"
  5. const directory = "C:/OpenCode/OpenFileExpand"
  6. const projectID = "proj_open_file_expand"
  7. const sessionID = "ses_open_file_expand"
  8. const title = "Open file expand"
  9. const server = `http://${process.env.PLAYWRIGHT_SERVER_HOST ?? "127.0.0.1"}:${process.env.PLAYWRIGHT_SERVER_PORT ?? "4096"}`
  10. test.use({ viewport: { width: 1440, height: 900 } })
  11. test("expands a folder whose path has a trailing Windows separator", async ({ page }) => {
  12. await mockOpenCodeServer(page, {
  13. directory,
  14. project: {
  15. id: projectID,
  16. worktree: directory,
  17. vcs: "git",
  18. name: "open-file-expand",
  19. time: { created: 1700000000000, updated: 1700000000000 },
  20. sandboxes: [],
  21. },
  22. provider: {
  23. all: [
  24. {
  25. id: "opencode",
  26. name: "OpenCode",
  27. models: { test: { id: "test", name: "Test", limit: { context: 200_000 } } },
  28. },
  29. ],
  30. connected: ["opencode"],
  31. default: { providerID: "opencode", modelID: "test" },
  32. },
  33. sessions: [
  34. {
  35. id: sessionID,
  36. slug: sessionID,
  37. projectID,
  38. directory,
  39. title,
  40. version: "dev",
  41. time: { created: 1700000000000, updated: 1700000000000 },
  42. },
  43. ],
  44. vcsDiff: [],
  45. fileList: (path) => {
  46. if (path === "frontend\\" || path === "frontend") {
  47. return [
  48. {
  49. name: "app.ts",
  50. path: "frontend\\app.ts",
  51. absolute: `${directory}/frontend/app.ts`,
  52. type: "file" as const,
  53. ignored: false,
  54. },
  55. ]
  56. }
  57. if (path) return []
  58. return [
  59. {
  60. name: "frontend",
  61. path: "frontend\\",
  62. absolute: `${directory}/frontend`,
  63. type: "directory" as const,
  64. ignored: false,
  65. },
  66. {
  67. name: "README.md",
  68. path: "README.md",
  69. absolute: `${directory}/README.md`,
  70. type: "file" as const,
  71. ignored: false,
  72. },
  73. ]
  74. },
  75. fileContent: (path) => ({ type: "text", content: `contents:${path}` }),
  76. pageMessages: () => ({ items: [] }),
  77. })
  78. await page.addInitScript(
  79. ({ directory, server, sessionID }) => {
  80. localStorage.setItem(
  81. "settings.v3",
  82. JSON.stringify({ general: { newLayoutDesigns: true, shouldDisplayTabsToast: false } }),
  83. )
  84. localStorage.setItem(
  85. "opencode.global.dat:server",
  86. JSON.stringify({
  87. projects: { local: [{ worktree: directory, expanded: true }] },
  88. lastProject: { local: directory },
  89. }),
  90. )
  91. localStorage.setItem(
  92. "opencode.global.dat:layout",
  93. JSON.stringify({ review: { diffStyle: "split", panelOpened: true } }),
  94. )
  95. localStorage.setItem(
  96. "opencode.global.dat:review-panel-v2",
  97. JSON.stringify({ sidebarOpened: true, sidebarWidth: 240, expandMode: "collapse" }),
  98. )
  99. localStorage.setItem(
  100. "opencode.window.browser.dat:tabs",
  101. JSON.stringify([{ type: "session", server, sessionId: sessionID }]),
  102. )
  103. },
  104. { directory, server, sessionID },
  105. )
  106. await page.goto(`/server/${base64Encode(server)}/session/${sessionID}`)
  107. await expectSessionTitle(page, title)
  108. const panel = page.locator("#review-panel")
  109. await panel.getByRole("button", { name: "Open file" }).click()
  110. await expect(panel.getByRole("tab", { name: "Open file" })).toHaveAttribute("data-selected", "")
  111. const sidebar = panel.locator('[data-component="session-review-v2-sidebar-root"]')
  112. await expect(sidebar).toBeVisible()
  113. const frontendRow = panel.locator('[data-slot="file-tree-v2-row"][data-path="frontend"]')
  114. await expect(frontendRow).toBeVisible()
  115. await expect(frontendRow).toHaveAttribute("aria-expanded", "false")
  116. await frontendRow.click()
  117. await expect(frontendRow).toHaveAttribute("aria-expanded", "true")
  118. const appRow = panel.locator('[data-slot="file-tree-v2-row"][data-path="frontend/app.ts"]')
  119. await expect(appRow).toBeVisible()
  120. await appRow.click()
  121. await expect(panel.getByRole("tab", { name: "app.ts" })).toHaveAttribute("data-selected", "")
  122. await expect(panel.getByText("contents:frontend/app.ts", { exact: true })).toBeVisible()
  123. })