settings-keybinds.spec.ts 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. import { test, expect } from "../fixtures"
  2. import { openSettings, closeDialog, withSession } from "../actions"
  3. import { keybindButtonSelector } from "../selectors"
  4. import { modKey } from "../utils"
  5. test("changing sidebar toggle keybind works", async ({ page, gotoSession }) => {
  6. await gotoSession()
  7. const dialog = await openSettings(page)
  8. await dialog.getByRole("tab", { name: "Shortcuts" }).click()
  9. const keybindButton = dialog.locator(keybindButtonSelector("sidebar.toggle"))
  10. await expect(keybindButton).toBeVisible()
  11. const initialKeybind = await keybindButton.textContent()
  12. expect(initialKeybind).toContain("B")
  13. await keybindButton.click()
  14. await expect(keybindButton).toHaveText(/press/i)
  15. await page.keyboard.press(`${modKey}+Shift+KeyH`)
  16. await page.waitForTimeout(100)
  17. const newKeybind = await keybindButton.textContent()
  18. expect(newKeybind).toContain("H")
  19. const stored = await page.evaluate(() => {
  20. const raw = localStorage.getItem("settings.v3")
  21. return raw ? JSON.parse(raw) : null
  22. })
  23. expect(stored?.keybinds?.["sidebar.toggle"]).toBe("mod+shift+h")
  24. await closeDialog(page, dialog)
  25. const main = page.locator("main")
  26. const initialClasses = (await main.getAttribute("class")) ?? ""
  27. const initiallyClosed = initialClasses.includes("xl:border-l")
  28. await page.keyboard.press(`${modKey}+Shift+H`)
  29. await page.waitForTimeout(100)
  30. const afterToggleClasses = (await main.getAttribute("class")) ?? ""
  31. const afterToggleClosed = afterToggleClasses.includes("xl:border-l")
  32. expect(afterToggleClosed).toBe(!initiallyClosed)
  33. await page.keyboard.press(`${modKey}+Shift+H`)
  34. await page.waitForTimeout(100)
  35. const finalClasses = (await main.getAttribute("class")) ?? ""
  36. const finalClosed = finalClasses.includes("xl:border-l")
  37. expect(finalClosed).toBe(initiallyClosed)
  38. })
  39. test("resetting all keybinds to defaults works", async ({ page, gotoSession }) => {
  40. await page.addInitScript(() => {
  41. localStorage.setItem("settings.v3", JSON.stringify({ keybinds: { "sidebar.toggle": "mod+shift+x" } }))
  42. })
  43. await gotoSession()
  44. const dialog = await openSettings(page)
  45. await dialog.getByRole("tab", { name: "Shortcuts" }).click()
  46. const keybindButton = dialog.locator(keybindButtonSelector("sidebar.toggle"))
  47. await expect(keybindButton).toBeVisible()
  48. const customKeybind = await keybindButton.textContent()
  49. expect(customKeybind).toContain("X")
  50. const resetButton = dialog.getByRole("button", { name: "Reset to defaults" })
  51. await expect(resetButton).toBeVisible()
  52. await expect(resetButton).toBeEnabled()
  53. await resetButton.click()
  54. await page.waitForTimeout(100)
  55. const restoredKeybind = await keybindButton.textContent()
  56. expect(restoredKeybind).toContain("B")
  57. const stored = await page.evaluate(() => {
  58. const raw = localStorage.getItem("settings.v3")
  59. return raw ? JSON.parse(raw) : null
  60. })
  61. expect(stored?.keybinds?.["sidebar.toggle"]).toBeUndefined()
  62. await closeDialog(page, dialog)
  63. })
  64. test("clearing a keybind works", async ({ page, gotoSession }) => {
  65. await gotoSession()
  66. const dialog = await openSettings(page)
  67. await dialog.getByRole("tab", { name: "Shortcuts" }).click()
  68. const keybindButton = dialog.locator(keybindButtonSelector("sidebar.toggle"))
  69. await expect(keybindButton).toBeVisible()
  70. const initialKeybind = await keybindButton.textContent()
  71. expect(initialKeybind).toContain("B")
  72. await keybindButton.click()
  73. await expect(keybindButton).toHaveText(/press/i)
  74. await page.keyboard.press("Delete")
  75. await page.waitForTimeout(100)
  76. const clearedKeybind = await keybindButton.textContent()
  77. expect(clearedKeybind).toMatch(/unassigned|press/i)
  78. const stored = await page.evaluate(() => {
  79. const raw = localStorage.getItem("settings.v3")
  80. return raw ? JSON.parse(raw) : null
  81. })
  82. expect(stored?.keybinds?.["sidebar.toggle"]).toBe("none")
  83. await closeDialog(page, dialog)
  84. await page.keyboard.press(`${modKey}+B`)
  85. await page.waitForTimeout(100)
  86. const stillOnSession = page.url().includes("/session")
  87. expect(stillOnSession).toBe(true)
  88. })
  89. test("changing settings open keybind works", async ({ page, gotoSession }) => {
  90. await gotoSession()
  91. const dialog = await openSettings(page)
  92. await dialog.getByRole("tab", { name: "Shortcuts" }).click()
  93. const keybindButton = dialog.locator(keybindButtonSelector("settings.open"))
  94. await expect(keybindButton).toBeVisible()
  95. const initialKeybind = await keybindButton.textContent()
  96. expect(initialKeybind).toContain(",")
  97. await keybindButton.click()
  98. await expect(keybindButton).toHaveText(/press/i)
  99. await page.keyboard.press(`${modKey}+Slash`)
  100. await page.waitForTimeout(100)
  101. const newKeybind = await keybindButton.textContent()
  102. expect(newKeybind).toContain("/")
  103. const stored = await page.evaluate(() => {
  104. const raw = localStorage.getItem("settings.v3")
  105. return raw ? JSON.parse(raw) : null
  106. })
  107. expect(stored?.keybinds?.["settings.open"]).toBe("mod+/")
  108. await closeDialog(page, dialog)
  109. const settingsDialog = page.getByRole("dialog")
  110. await expect(settingsDialog).toHaveCount(0)
  111. await page.keyboard.press(`${modKey}+Slash`)
  112. await page.waitForTimeout(100)
  113. await expect(settingsDialog).toBeVisible()
  114. await closeDialog(page, settingsDialog)
  115. })
  116. test("changing new session keybind works", async ({ page, sdk, gotoSession }) => {
  117. await withSession(sdk, "test session for keybind", async (session) => {
  118. await gotoSession(session.id)
  119. const initialUrl = page.url()
  120. expect(initialUrl).toContain(`/session/${session.id}`)
  121. const dialog = await openSettings(page)
  122. await dialog.getByRole("tab", { name: "Shortcuts" }).click()
  123. const keybindButton = dialog.locator(keybindButtonSelector("session.new"))
  124. await expect(keybindButton).toBeVisible()
  125. await keybindButton.click()
  126. await expect(keybindButton).toHaveText(/press/i)
  127. await page.keyboard.press(`${modKey}+Shift+KeyN`)
  128. await page.waitForTimeout(100)
  129. const newKeybind = await keybindButton.textContent()
  130. expect(newKeybind).toContain("N")
  131. const stored = await page.evaluate(() => {
  132. const raw = localStorage.getItem("settings.v3")
  133. return raw ? JSON.parse(raw) : null
  134. })
  135. expect(stored?.keybinds?.["session.new"]).toBe("mod+shift+n")
  136. await closeDialog(page, dialog)
  137. await page.keyboard.press(`${modKey}+Shift+N`)
  138. await page.waitForTimeout(200)
  139. const newUrl = page.url()
  140. expect(newUrl).toMatch(/\/session\/?$/)
  141. expect(newUrl).not.toContain(session.id)
  142. })
  143. })
  144. test("changing file open keybind works", async ({ page, gotoSession }) => {
  145. await gotoSession()
  146. const dialog = await openSettings(page)
  147. await dialog.getByRole("tab", { name: "Shortcuts" }).click()
  148. const keybindButton = dialog.locator(keybindButtonSelector("file.open"))
  149. await expect(keybindButton).toBeVisible()
  150. const initialKeybind = await keybindButton.textContent()
  151. expect(initialKeybind).toContain("P")
  152. await keybindButton.click()
  153. await expect(keybindButton).toHaveText(/press/i)
  154. await page.keyboard.press(`${modKey}+Shift+KeyF`)
  155. await page.waitForTimeout(100)
  156. const newKeybind = await keybindButton.textContent()
  157. expect(newKeybind).toContain("F")
  158. const stored = await page.evaluate(() => {
  159. const raw = localStorage.getItem("settings.v3")
  160. return raw ? JSON.parse(raw) : null
  161. })
  162. expect(stored?.keybinds?.["file.open"]).toBe("mod+shift+f")
  163. await closeDialog(page, dialog)
  164. const filePickerDialog = page.getByRole("dialog").filter({ has: page.getByPlaceholder(/search files/i) })
  165. await expect(filePickerDialog).toHaveCount(0)
  166. await page.keyboard.press(`${modKey}+Shift+F`)
  167. await page.waitForTimeout(100)
  168. await expect(filePickerDialog).toBeVisible()
  169. await page.keyboard.press("Escape")
  170. await expect(filePickerDialog).toHaveCount(0)
  171. })
  172. test("changing terminal toggle keybind works", async ({ page, gotoSession }) => {
  173. await gotoSession()
  174. const dialog = await openSettings(page)
  175. await dialog.getByRole("tab", { name: "Shortcuts" }).click()
  176. const keybindButton = dialog.locator(keybindButtonSelector("terminal.toggle"))
  177. await expect(keybindButton).toBeVisible()
  178. await keybindButton.click()
  179. await expect(keybindButton).toHaveText(/press/i)
  180. await page.keyboard.press(`${modKey}+KeyY`)
  181. await page.waitForTimeout(100)
  182. const newKeybind = await keybindButton.textContent()
  183. expect(newKeybind).toContain("Y")
  184. const stored = await page.evaluate(() => {
  185. const raw = localStorage.getItem("settings.v3")
  186. return raw ? JSON.parse(raw) : null
  187. })
  188. expect(stored?.keybinds?.["terminal.toggle"]).toBe("mod+y")
  189. await closeDialog(page, dialog)
  190. await page.keyboard.press(`${modKey}+Y`)
  191. await page.waitForTimeout(100)
  192. const pageStable = await page.evaluate(() => document.readyState === "complete")
  193. expect(pageStable).toBe(true)
  194. })
  195. test("changing command palette keybind works", async ({ page, gotoSession }) => {
  196. await gotoSession()
  197. const dialog = await openSettings(page)
  198. await dialog.getByRole("tab", { name: "Shortcuts" }).click()
  199. const keybindButton = dialog.locator(keybindButtonSelector("command.palette"))
  200. await expect(keybindButton).toBeVisible()
  201. const initialKeybind = await keybindButton.textContent()
  202. expect(initialKeybind).toContain("P")
  203. await keybindButton.click()
  204. await expect(keybindButton).toHaveText(/press/i)
  205. await page.keyboard.press(`${modKey}+Shift+KeyK`)
  206. await page.waitForTimeout(100)
  207. const newKeybind = await keybindButton.textContent()
  208. expect(newKeybind).toContain("K")
  209. const stored = await page.evaluate(() => {
  210. const raw = localStorage.getItem("settings.v3")
  211. return raw ? JSON.parse(raw) : null
  212. })
  213. expect(stored?.keybinds?.["command.palette"]).toBe("mod+shift+k")
  214. await closeDialog(page, dialog)
  215. const palette = page.getByRole("dialog").filter({ has: page.getByRole("textbox").first() })
  216. await expect(palette).toHaveCount(0)
  217. await page.keyboard.press(`${modKey}+Shift+K`)
  218. await page.waitForTimeout(100)
  219. await expect(palette).toBeVisible()
  220. await expect(palette.getByRole("textbox").first()).toBeVisible()
  221. await page.keyboard.press("Escape")
  222. await expect(palette).toHaveCount(0)
  223. })