settings.spec.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. import { test, expect, settingsKey } from "../fixtures"
  2. import { closeDialog, openSettings } from "../actions"
  3. import {
  4. settingsColorSchemeSelector,
  5. settingsFontSelector,
  6. settingsLanguageSelectSelector,
  7. settingsNotificationsAgentSelector,
  8. settingsNotificationsErrorsSelector,
  9. settingsNotificationsPermissionsSelector,
  10. settingsReleaseNotesSelector,
  11. settingsSoundsAgentSelector,
  12. settingsSoundsAgentEnabledSelector,
  13. settingsSoundsErrorsSelector,
  14. settingsSoundsPermissionsSelector,
  15. settingsThemeSelector,
  16. settingsUpdatesStartupSelector,
  17. } from "../selectors"
  18. test("smoke settings dialog opens, switches tabs, closes", async ({ page, gotoSession }) => {
  19. await gotoSession()
  20. const dialog = await openSettings(page)
  21. await dialog.getByRole("tab", { name: "Shortcuts" }).click()
  22. await expect(dialog.getByRole("button", { name: "Reset to defaults" })).toBeVisible()
  23. await expect(dialog.getByPlaceholder("Search shortcuts")).toBeVisible()
  24. await closeDialog(page, dialog)
  25. })
  26. test("changing language updates settings labels", async ({ page, gotoSession }) => {
  27. await page.addInitScript(() => {
  28. localStorage.setItem("opencode.global.dat:language", JSON.stringify({ locale: "en" }))
  29. })
  30. await gotoSession()
  31. const dialog = await openSettings(page)
  32. const heading = dialog.getByRole("heading", { level: 2 })
  33. await expect(heading).toHaveText("General")
  34. const select = dialog.locator(settingsLanguageSelectSelector)
  35. await expect(select).toBeVisible()
  36. await select.locator('[data-slot="select-select-trigger"]').click()
  37. await page.locator('[data-slot="select-select-item"]').filter({ hasText: "Deutsch" }).click()
  38. await expect(heading).toHaveText("Allgemein")
  39. await select.locator('[data-slot="select-select-trigger"]').click()
  40. await page.locator('[data-slot="select-select-item"]').filter({ hasText: "English" }).click()
  41. await expect(heading).toHaveText("General")
  42. })
  43. test("changing color scheme persists in localStorage", async ({ page, gotoSession }) => {
  44. await gotoSession()
  45. const dialog = await openSettings(page)
  46. const select = dialog.locator(settingsColorSchemeSelector)
  47. await expect(select).toBeVisible()
  48. await select.locator('[data-slot="select-select-trigger"]').click()
  49. await page.locator('[data-slot="select-select-item"]').filter({ hasText: "Dark" }).click()
  50. const colorScheme = await page.evaluate(() => {
  51. return document.documentElement.getAttribute("data-color-scheme")
  52. })
  53. expect(colorScheme).toBe("dark")
  54. await select.locator('[data-slot="select-select-trigger"]').click()
  55. await page.locator('[data-slot="select-select-item"]').filter({ hasText: "Light" }).click()
  56. const lightColorScheme = await page.evaluate(() => {
  57. return document.documentElement.getAttribute("data-color-scheme")
  58. })
  59. expect(lightColorScheme).toBe("light")
  60. })
  61. test("changing theme persists in localStorage", async ({ page, gotoSession }) => {
  62. await gotoSession()
  63. const dialog = await openSettings(page)
  64. const select = dialog.locator(settingsThemeSelector)
  65. await expect(select).toBeVisible()
  66. await select.locator('[data-slot="select-select-trigger"]').click()
  67. const items = page.locator('[data-slot="select-select-item"]')
  68. const count = await items.count()
  69. expect(count).toBeGreaterThan(1)
  70. const firstTheme = await items.nth(1).locator('[data-slot="select-select-item-label"]').textContent()
  71. expect(firstTheme).toBeTruthy()
  72. await items.nth(1).click()
  73. await page.keyboard.press("Escape")
  74. const storedThemeId = await page.evaluate(() => {
  75. return localStorage.getItem("opencode-theme-id")
  76. })
  77. expect(storedThemeId).not.toBeNull()
  78. expect(storedThemeId).not.toBe("oc-1")
  79. const dataTheme = await page.evaluate(() => {
  80. return document.documentElement.getAttribute("data-theme")
  81. })
  82. expect(dataTheme).toBe(storedThemeId)
  83. })
  84. test("changing font persists in localStorage and updates CSS variable", async ({ page, gotoSession }) => {
  85. await gotoSession()
  86. const dialog = await openSettings(page)
  87. const select = dialog.locator(settingsFontSelector)
  88. await expect(select).toBeVisible()
  89. const initialFontFamily = await page.evaluate(() => {
  90. return getComputedStyle(document.documentElement).getPropertyValue("--font-family-mono")
  91. })
  92. expect(initialFontFamily).toContain("IBM Plex Mono")
  93. await select.locator('[data-slot="select-select-trigger"]').click()
  94. const items = page.locator('[data-slot="select-select-item"]')
  95. await items.nth(2).click()
  96. await page.waitForTimeout(100)
  97. const stored = await page.evaluate((key) => {
  98. const raw = localStorage.getItem(key)
  99. return raw ? JSON.parse(raw) : null
  100. }, settingsKey)
  101. expect(stored?.appearance?.font).not.toBe("ibm-plex-mono")
  102. const newFontFamily = await page.evaluate(() => {
  103. return getComputedStyle(document.documentElement).getPropertyValue("--font-family-mono")
  104. })
  105. expect(newFontFamily).not.toBe(initialFontFamily)
  106. })
  107. test("color scheme and font rehydrate after reload", async ({ page, gotoSession }) => {
  108. await gotoSession()
  109. const dialog = await openSettings(page)
  110. const colorSchemeSelect = dialog.locator(settingsColorSchemeSelector)
  111. await expect(colorSchemeSelect).toBeVisible()
  112. await colorSchemeSelect.locator('[data-slot="select-select-trigger"]').click()
  113. await page.locator('[data-slot="select-select-item"]').filter({ hasText: "Dark" }).click()
  114. await expect(page.locator("html")).toHaveAttribute("data-color-scheme", "dark")
  115. const fontSelect = dialog.locator(settingsFontSelector)
  116. await expect(fontSelect).toBeVisible()
  117. const initialFontFamily = await page.evaluate(() => {
  118. return getComputedStyle(document.documentElement).getPropertyValue("--font-family-mono").trim()
  119. })
  120. const initialSettings = await page.evaluate((key) => {
  121. const raw = localStorage.getItem(key)
  122. return raw ? JSON.parse(raw) : null
  123. }, settingsKey)
  124. const currentFont =
  125. (await fontSelect.locator('[data-slot="select-select-trigger-value"]').textContent())?.trim() ?? ""
  126. await fontSelect.locator('[data-slot="select-select-trigger"]').click()
  127. const fontItems = page.locator('[data-slot="select-select-item"]')
  128. expect(await fontItems.count()).toBeGreaterThan(1)
  129. if (currentFont) {
  130. await fontItems.filter({ hasNotText: currentFont }).first().click()
  131. }
  132. if (!currentFont) {
  133. await fontItems.nth(1).click()
  134. }
  135. await expect
  136. .poll(async () => {
  137. return await page.evaluate((key) => {
  138. const raw = localStorage.getItem(key)
  139. return raw ? JSON.parse(raw) : null
  140. }, settingsKey)
  141. })
  142. .toMatchObject({
  143. appearance: {
  144. font: expect.any(String),
  145. },
  146. })
  147. const updatedSettings = await page.evaluate((key) => {
  148. const raw = localStorage.getItem(key)
  149. return raw ? JSON.parse(raw) : null
  150. }, settingsKey)
  151. const updatedFontFamily = await page.evaluate(() => {
  152. return getComputedStyle(document.documentElement).getPropertyValue("--font-family-mono").trim()
  153. })
  154. expect(updatedFontFamily).not.toBe(initialFontFamily)
  155. expect(updatedSettings?.appearance?.font).not.toBe(initialSettings?.appearance?.font)
  156. await closeDialog(page, dialog)
  157. await page.reload()
  158. await expect(page.locator("html")).toHaveAttribute("data-color-scheme", "dark")
  159. await expect
  160. .poll(async () => {
  161. return await page.evaluate((key) => {
  162. const raw = localStorage.getItem(key)
  163. return raw ? JSON.parse(raw) : null
  164. }, settingsKey)
  165. })
  166. .toMatchObject({
  167. appearance: {
  168. font: updatedSettings?.appearance?.font,
  169. },
  170. })
  171. const rehydratedSettings = await page.evaluate((key) => {
  172. const raw = localStorage.getItem(key)
  173. return raw ? JSON.parse(raw) : null
  174. }, settingsKey)
  175. await expect
  176. .poll(async () => {
  177. return await page.evaluate(() => {
  178. return getComputedStyle(document.documentElement).getPropertyValue("--font-family-mono").trim()
  179. })
  180. })
  181. .not.toBe(initialFontFamily)
  182. const rehydratedFontFamily = await page.evaluate(() => {
  183. return getComputedStyle(document.documentElement).getPropertyValue("--font-family-mono").trim()
  184. })
  185. expect(rehydratedFontFamily).not.toBe(initialFontFamily)
  186. expect(rehydratedSettings?.appearance?.font).toBe(updatedSettings?.appearance?.font)
  187. })
  188. test("toggling notification agent switch updates localStorage", async ({ page, gotoSession }) => {
  189. await gotoSession()
  190. const dialog = await openSettings(page)
  191. const switchContainer = dialog.locator(settingsNotificationsAgentSelector)
  192. await expect(switchContainer).toBeVisible()
  193. const toggleInput = switchContainer.locator('[data-slot="switch-input"]')
  194. const initialState = await toggleInput.evaluate((el: HTMLInputElement) => el.checked)
  195. expect(initialState).toBe(true)
  196. await switchContainer.locator('[data-slot="switch-control"]').click()
  197. await page.waitForTimeout(100)
  198. const newState = await toggleInput.evaluate((el: HTMLInputElement) => el.checked)
  199. expect(newState).toBe(false)
  200. const stored = await page.evaluate((key) => {
  201. const raw = localStorage.getItem(key)
  202. return raw ? JSON.parse(raw) : null
  203. }, settingsKey)
  204. expect(stored?.notifications?.agent).toBe(false)
  205. })
  206. test("toggling notification permissions switch updates localStorage", async ({ page, gotoSession }) => {
  207. await gotoSession()
  208. const dialog = await openSettings(page)
  209. const switchContainer = dialog.locator(settingsNotificationsPermissionsSelector)
  210. await expect(switchContainer).toBeVisible()
  211. const toggleInput = switchContainer.locator('[data-slot="switch-input"]')
  212. const initialState = await toggleInput.evaluate((el: HTMLInputElement) => el.checked)
  213. expect(initialState).toBe(true)
  214. await switchContainer.locator('[data-slot="switch-control"]').click()
  215. await page.waitForTimeout(100)
  216. const newState = await toggleInput.evaluate((el: HTMLInputElement) => el.checked)
  217. expect(newState).toBe(false)
  218. const stored = await page.evaluate((key) => {
  219. const raw = localStorage.getItem(key)
  220. return raw ? JSON.parse(raw) : null
  221. }, settingsKey)
  222. expect(stored?.notifications?.permissions).toBe(false)
  223. })
  224. test("toggling notification errors switch updates localStorage", async ({ page, gotoSession }) => {
  225. await gotoSession()
  226. const dialog = await openSettings(page)
  227. const switchContainer = dialog.locator(settingsNotificationsErrorsSelector)
  228. await expect(switchContainer).toBeVisible()
  229. const toggleInput = switchContainer.locator('[data-slot="switch-input"]')
  230. const initialState = await toggleInput.evaluate((el: HTMLInputElement) => el.checked)
  231. expect(initialState).toBe(false)
  232. await switchContainer.locator('[data-slot="switch-control"]').click()
  233. await page.waitForTimeout(100)
  234. const newState = await toggleInput.evaluate((el: HTMLInputElement) => el.checked)
  235. expect(newState).toBe(true)
  236. const stored = await page.evaluate((key) => {
  237. const raw = localStorage.getItem(key)
  238. return raw ? JSON.parse(raw) : null
  239. }, settingsKey)
  240. expect(stored?.notifications?.errors).toBe(true)
  241. })
  242. test("changing sound agent selection persists in localStorage", async ({ page, gotoSession }) => {
  243. await gotoSession()
  244. const dialog = await openSettings(page)
  245. const select = dialog.locator(settingsSoundsAgentSelector)
  246. await expect(select).toBeVisible()
  247. await select.locator('[data-slot="select-select-trigger"]').click()
  248. const items = page.locator('[data-slot="select-select-item"]')
  249. await items.nth(2).click()
  250. const stored = await page.evaluate((key) => {
  251. const raw = localStorage.getItem(key)
  252. return raw ? JSON.parse(raw) : null
  253. }, settingsKey)
  254. expect(stored?.sounds?.agent).not.toBe("staplebops-01")
  255. })
  256. test("disabling agent sound disables sound selection", async ({ page, gotoSession }) => {
  257. await gotoSession()
  258. const dialog = await openSettings(page)
  259. const select = dialog.locator(settingsSoundsAgentSelector)
  260. const switchContainer = dialog.locator(settingsSoundsAgentEnabledSelector)
  261. const trigger = select.locator('[data-slot="select-select-trigger"]')
  262. await expect(select).toBeVisible()
  263. await expect(switchContainer).toBeVisible()
  264. await expect(trigger).toBeEnabled()
  265. await switchContainer.locator('[data-slot="switch-control"]').click()
  266. await page.waitForTimeout(100)
  267. await expect(trigger).toBeDisabled()
  268. const stored = await page.evaluate((key) => {
  269. const raw = localStorage.getItem(key)
  270. return raw ? JSON.parse(raw) : null
  271. }, settingsKey)
  272. expect(stored?.sounds?.agentEnabled).toBe(false)
  273. })
  274. test("changing permissions and errors sounds updates localStorage", async ({ page, gotoSession }) => {
  275. await gotoSession()
  276. const dialog = await openSettings(page)
  277. const permissionsSelect = dialog.locator(settingsSoundsPermissionsSelector)
  278. const errorsSelect = dialog.locator(settingsSoundsErrorsSelector)
  279. await expect(permissionsSelect).toBeVisible()
  280. await expect(errorsSelect).toBeVisible()
  281. const initial = await page.evaluate((key) => {
  282. const raw = localStorage.getItem(key)
  283. return raw ? JSON.parse(raw) : null
  284. }, settingsKey)
  285. const permissionsCurrent =
  286. (await permissionsSelect.locator('[data-slot="select-select-trigger-value"]').textContent())?.trim() ?? ""
  287. await permissionsSelect.locator('[data-slot="select-select-trigger"]').click()
  288. const permissionItems = page.locator('[data-slot="select-select-item"]')
  289. expect(await permissionItems.count()).toBeGreaterThan(1)
  290. if (permissionsCurrent) {
  291. await permissionItems.filter({ hasNotText: permissionsCurrent }).first().click()
  292. }
  293. if (!permissionsCurrent) {
  294. await permissionItems.nth(1).click()
  295. }
  296. const errorsCurrent =
  297. (await errorsSelect.locator('[data-slot="select-select-trigger-value"]').textContent())?.trim() ?? ""
  298. await errorsSelect.locator('[data-slot="select-select-trigger"]').click()
  299. const errorItems = page.locator('[data-slot="select-select-item"]')
  300. expect(await errorItems.count()).toBeGreaterThan(1)
  301. if (errorsCurrent) {
  302. await errorItems.filter({ hasNotText: errorsCurrent }).first().click()
  303. }
  304. if (!errorsCurrent) {
  305. await errorItems.nth(1).click()
  306. }
  307. await expect
  308. .poll(async () => {
  309. return await page.evaluate((key) => {
  310. const raw = localStorage.getItem(key)
  311. return raw ? JSON.parse(raw) : null
  312. }, settingsKey)
  313. })
  314. .toMatchObject({
  315. sounds: {
  316. permissions: expect.any(String),
  317. errors: expect.any(String),
  318. },
  319. })
  320. const stored = await page.evaluate((key) => {
  321. const raw = localStorage.getItem(key)
  322. return raw ? JSON.parse(raw) : null
  323. }, settingsKey)
  324. expect(stored?.sounds?.permissions).not.toBe(initial?.sounds?.permissions)
  325. expect(stored?.sounds?.errors).not.toBe(initial?.sounds?.errors)
  326. })
  327. test("toggling updates startup switch updates localStorage", async ({ page, gotoSession }) => {
  328. await gotoSession()
  329. const dialog = await openSettings(page)
  330. const switchContainer = dialog.locator(settingsUpdatesStartupSelector)
  331. await expect(switchContainer).toBeVisible()
  332. const toggleInput = switchContainer.locator('[data-slot="switch-input"]')
  333. const isDisabled = await toggleInput.evaluate((el: HTMLInputElement) => el.disabled)
  334. if (isDisabled) {
  335. test.skip()
  336. return
  337. }
  338. const initialState = await toggleInput.evaluate((el: HTMLInputElement) => el.checked)
  339. expect(initialState).toBe(true)
  340. await switchContainer.locator('[data-slot="switch-control"]').click()
  341. await page.waitForTimeout(100)
  342. const newState = await toggleInput.evaluate((el: HTMLInputElement) => el.checked)
  343. expect(newState).toBe(false)
  344. const stored = await page.evaluate((key) => {
  345. const raw = localStorage.getItem(key)
  346. return raw ? JSON.parse(raw) : null
  347. }, settingsKey)
  348. expect(stored?.updates?.startup).toBe(false)
  349. })
  350. test("toggling release notes switch updates localStorage", async ({ page, gotoSession }) => {
  351. await gotoSession()
  352. const dialog = await openSettings(page)
  353. const switchContainer = dialog.locator(settingsReleaseNotesSelector)
  354. await expect(switchContainer).toBeVisible()
  355. const toggleInput = switchContainer.locator('[data-slot="switch-input"]')
  356. const initialState = await toggleInput.evaluate((el: HTMLInputElement) => el.checked)
  357. expect(initialState).toBe(true)
  358. await switchContainer.locator('[data-slot="switch-control"]').click()
  359. await page.waitForTimeout(100)
  360. const newState = await toggleInput.evaluate((el: HTMLInputElement) => el.checked)
  361. expect(newState).toBe(false)
  362. const stored = await page.evaluate((key) => {
  363. const raw = localStorage.getItem(key)
  364. return raw ? JSON.parse(raw) : null
  365. }, settingsKey)
  366. expect(stored?.general?.releaseNotes).toBe(false)
  367. })