settings.spec.ts 15 KB

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