SettingsPage.test.tsx 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  1. /**
  2. * Tests for the SettingsPage component.
  3. */
  4. import { describe, it, expect, beforeEach, vi } from 'vitest';
  5. import { fireEvent, screen, waitFor, within } from '@testing-library/react';
  6. import userEvent from '@testing-library/user-event';
  7. import { render } from '../utils';
  8. import { SettingsPage } from '../../pages/SettingsPage';
  9. import { http, HttpResponse } from 'msw';
  10. import { server } from '../mocks/server';
  11. import { SIDEBAR_HIDDEN_SYSTEM_ITEMS_KEY, SIDEBAR_ORDER_KEY } from '../../utils/sidebarLayout';
  12. import { setAuthToken } from '../../api/client';
  13. const mockSettings = {
  14. auto_archive: true,
  15. save_thumbnails: true,
  16. capture_finish_photo: true,
  17. default_filament_cost: 25.0,
  18. currency: 'USD',
  19. ams_humidity_good: 40,
  20. ams_humidity_fair: 60,
  21. ams_temp_good: 30,
  22. ams_temp_fair: 35,
  23. time_format: 'system',
  24. date_format: 'system',
  25. mqtt_enabled: false,
  26. mqtt_host: '',
  27. mqtt_port: 1883,
  28. spoolman_enabled: false,
  29. spoolman_url: '',
  30. ha_enabled: false,
  31. ha_url: '',
  32. ha_token: '',
  33. check_updates: false,
  34. check_printer_firmware: false,
  35. bed_cooled_threshold: 35,
  36. };
  37. describe('SettingsPage', () => {
  38. beforeEach(() => {
  39. // BrowserRouter shares window.location across tests; reset it so a tab
  40. // switch in one test (e.g. clicking "Workflow") doesn't carry into
  41. // sibling tests that expect to land on the default General tab.
  42. window.history.replaceState({}, '', '/');
  43. vi.mocked(localStorage.getItem).mockReset();
  44. vi.mocked(localStorage.setItem).mockReset();
  45. vi.mocked(localStorage.removeItem).mockReset();
  46. vi.mocked(localStorage.clear).mockReset();
  47. localStorage.clear();
  48. setAuthToken(null);
  49. server.use(
  50. http.get('/api/v1/settings/', () => {
  51. return HttpResponse.json(mockSettings);
  52. }),
  53. http.put('/api/v1/settings/', async ({ request }) => {
  54. const body = await request.json();
  55. return HttpResponse.json({ ...mockSettings, ...body });
  56. }),
  57. http.get('/api/v1/printers/', () => {
  58. return HttpResponse.json([]);
  59. }),
  60. http.get('/api/v1/smart-plugs/', () => {
  61. return HttpResponse.json([]);
  62. }),
  63. http.get('/api/v1/notifications/', () => {
  64. return HttpResponse.json([]);
  65. }),
  66. http.get('/api/v1/api-keys/', () => {
  67. return HttpResponse.json([]);
  68. }),
  69. http.get('/api/v1/mqtt/status', () => {
  70. return HttpResponse.json({ enabled: false });
  71. }),
  72. http.get('/api/v1/virtual-printer/status', () => {
  73. return HttpResponse.json({ running: false });
  74. }),
  75. http.get('/api/v1/auth/status', () => {
  76. return HttpResponse.json({ auth_enabled: false, requires_setup: false });
  77. }),
  78. http.get('/api/v1/external-links/', () => {
  79. return HttpResponse.json([]);
  80. })
  81. );
  82. });
  83. describe('rendering', () => {
  84. it('renders the page title', async () => {
  85. render(<SettingsPage />);
  86. await waitFor(() => {
  87. // Use role-based query to avoid conflicts with dropdown options
  88. expect(screen.getByRole('heading', { name: 'Settings' })).toBeInTheDocument();
  89. });
  90. });
  91. it('shows settings tabs', async () => {
  92. render(<SettingsPage />);
  93. await waitFor(() => {
  94. // Use getAllByText since "General" appears both as tab and section heading
  95. expect(screen.getAllByText('General').length).toBeGreaterThan(0);
  96. expect(screen.getByText('Smart Plugs')).toBeInTheDocument();
  97. expect(screen.getAllByText('Notifications').length).toBeGreaterThan(0);
  98. expect(screen.getAllByText('Filament').length).toBeGreaterThan(0);
  99. expect(screen.getByText('Network')).toBeInTheDocument();
  100. expect(screen.getByText('API Keys')).toBeInTheDocument();
  101. });
  102. });
  103. });
  104. describe('general settings', () => {
  105. it('shows date format setting', async () => {
  106. render(<SettingsPage />);
  107. await waitFor(() => {
  108. expect(screen.getByText('Date Format')).toBeInTheDocument();
  109. });
  110. });
  111. it('shows time format setting', async () => {
  112. render(<SettingsPage />);
  113. await waitFor(() => {
  114. expect(screen.getByText('Time Format')).toBeInTheDocument();
  115. });
  116. });
  117. it('shows default printer setting', async () => {
  118. render(<SettingsPage />);
  119. await waitFor(() => {
  120. expect(screen.getByText('Default Printer')).toBeInTheDocument();
  121. });
  122. });
  123. it('shows preferred slicer setting on Workflow tab', async () => {
  124. const user = userEvent.setup();
  125. render(<SettingsPage />);
  126. await waitFor(() => {
  127. expect(screen.getByText('Workflow')).toBeInTheDocument();
  128. });
  129. await user.click(screen.getByText('Workflow'));
  130. await waitFor(() => {
  131. expect(screen.getByText('Preferred Slicer')).toBeInTheDocument();
  132. });
  133. });
  134. it('shows slicer dropdown with both options on Workflow tab', async () => {
  135. const user = userEvent.setup();
  136. render(<SettingsPage />);
  137. await waitFor(() => {
  138. expect(screen.getByText('Workflow')).toBeInTheDocument();
  139. });
  140. await user.click(screen.getByText('Workflow'));
  141. await waitFor(() => {
  142. const slicerSelect = screen.getAllByDisplayValue('Bambu Studio');
  143. expect(slicerSelect.length).toBeGreaterThan(0);
  144. });
  145. });
  146. it('shows appearance section', async () => {
  147. render(<SettingsPage />);
  148. await waitFor(() => {
  149. expect(screen.getByText('Appearance')).toBeInTheDocument();
  150. });
  151. });
  152. it('shows updates section with firmware toggle', async () => {
  153. render(<SettingsPage />);
  154. await waitFor(() => {
  155. expect(screen.getByText('Updates')).toBeInTheDocument();
  156. expect(screen.getByText('Check for updates')).toBeInTheDocument();
  157. expect(screen.getByText('Check printer firmware')).toBeInTheDocument();
  158. });
  159. });
  160. it('hides a Bambuddy sidebar page from Sidebar', async () => {
  161. const user = userEvent.setup();
  162. render(<SettingsPage />);
  163. await screen.findByRole('heading', { name: 'Sidebar' });
  164. await screen.findAllByText('Visible in sidebar');
  165. vi.mocked(localStorage.setItem).mockClear();
  166. await user.click((await screen.findAllByLabelText('Hide page'))[0]);
  167. expect(localStorage.setItem).toHaveBeenCalledWith(SIDEBAR_HIDDEN_SYSTEM_ITEMS_KEY, JSON.stringify(['printers']));
  168. expect(screen.getByText('Hidden from sidebar')).toBeInTheDocument();
  169. });
  170. it('shows a previously hidden Bambuddy sidebar page from Sidebar', async () => {
  171. vi.mocked(localStorage.getItem).mockImplementation((key) => {
  172. if (key === SIDEBAR_HIDDEN_SYSTEM_ITEMS_KEY) return JSON.stringify(['printers']);
  173. return null;
  174. });
  175. const user = userEvent.setup();
  176. render(<SettingsPage />);
  177. await screen.findByRole('heading', { name: 'Sidebar' });
  178. await screen.findByText('Hidden from sidebar');
  179. vi.mocked(localStorage.setItem).mockClear();
  180. await user.click(await screen.findByLabelText('Show page'));
  181. expect(localStorage.setItem).toHaveBeenCalledWith(SIDEBAR_HIDDEN_SYSTEM_ITEMS_KEY, JSON.stringify([]));
  182. expect(screen.getAllByText('Visible in sidebar').length).toBeGreaterThan(0);
  183. });
  184. it('does not allow Settings to be hidden from Sidebar', async () => {
  185. render(<SettingsPage />);
  186. await screen.findByRole('heading', { name: 'Sidebar' });
  187. await screen.findByText('Required in sidebar');
  188. const settingsVisibilityButton = await screen.findByLabelText('Settings cannot be hidden');
  189. expect(settingsVisibilityButton).toBeDisabled();
  190. expect(screen.getByText('Required in sidebar')).toBeInTheDocument();
  191. });
  192. it('presents external links and Bambuddy pages in saved sidebar order', async () => {
  193. vi.mocked(localStorage.getItem).mockImplementation((key) => {
  194. if (key === SIDEBAR_ORDER_KEY) return JSON.stringify(['ext-7', 'printers', 'settings']);
  195. return null;
  196. });
  197. server.use(
  198. http.get('/api/v1/external-links/', () =>
  199. HttpResponse.json([
  200. {
  201. id: 7,
  202. name: 'Docs',
  203. url: 'https://docs.example.test',
  204. icon: 'Link',
  205. open_in_new_tab: true,
  206. custom_icon: null,
  207. sort_order: 0,
  208. created_at: '2026-01-01T00:00:00Z',
  209. updated_at: '2026-01-01T00:00:00Z',
  210. },
  211. ]),
  212. ),
  213. );
  214. render(<SettingsPage />);
  215. await screen.findByRole('heading', { name: 'Sidebar' });
  216. const docs = await screen.findByText('Docs');
  217. const printers = screen.getAllByText('Printers').find(element => element.closest('[draggable="true"]'));
  218. expect(printers).toBeDefined();
  219. expect(docs.compareDocumentPosition(printers) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
  220. });
  221. it('saves mixed Sidebar order when items are dragged', async () => {
  222. server.use(
  223. http.get('/api/v1/external-links/', () =>
  224. HttpResponse.json([
  225. {
  226. id: 7,
  227. name: 'Docs',
  228. url: 'https://docs.example.test',
  229. icon: 'Link',
  230. open_in_new_tab: true,
  231. custom_icon: null,
  232. sort_order: 0,
  233. created_at: '2026-01-01T00:00:00Z',
  234. updated_at: '2026-01-01T00:00:00Z',
  235. },
  236. ]),
  237. ),
  238. );
  239. render(<SettingsPage />);
  240. await screen.findByRole('heading', { name: 'Sidebar' });
  241. const docsRow = (await screen.findByText('Docs')).closest('[draggable="true"]');
  242. const printersRow = screen.getAllByText('Printers')
  243. .find(element => element.closest('[draggable="true"]'))
  244. ?.closest('[draggable="true"]');
  245. expect(docsRow).not.toBeNull();
  246. expect(printersRow).not.toBeNull();
  247. vi.mocked(localStorage.setItem).mockClear();
  248. const dataTransfer = {
  249. effectAllowed: '',
  250. dropEffect: '',
  251. setData: vi.fn(),
  252. };
  253. fireEvent.dragStart(docsRow!, { dataTransfer });
  254. fireEvent.dragOver(printersRow!, { dataTransfer });
  255. fireEvent.drop(printersRow!, { dataTransfer });
  256. expect(localStorage.setItem).toHaveBeenCalledWith(
  257. SIDEBAR_ORDER_KEY,
  258. JSON.stringify(['ext-7', 'printers', 'inventory', 'archives', 'queue', 'projects', 'files', 'makerworld', 'profiles', 'maintenance', 'stats', 'settings']),
  259. );
  260. });
  261. it('resets Sidebar to all pages first and configured links at the bottom', async () => {
  262. vi.mocked(localStorage.getItem).mockImplementation((key) => {
  263. if (key === SIDEBAR_HIDDEN_SYSTEM_ITEMS_KEY) return JSON.stringify(['printers', 'stats']);
  264. if (key === SIDEBAR_ORDER_KEY) return JSON.stringify(['ext-7', 'settings', 'printers']);
  265. return null;
  266. });
  267. server.use(
  268. http.get('/api/v1/external-links/', () =>
  269. HttpResponse.json([
  270. {
  271. id: 7,
  272. name: 'Docs',
  273. url: 'https://docs.example.test',
  274. icon: 'Link',
  275. open_in_new_tab: true,
  276. custom_icon: null,
  277. sort_order: 0,
  278. created_at: '2026-01-01T00:00:00Z',
  279. updated_at: '2026-01-01T00:00:00Z',
  280. },
  281. ]),
  282. ),
  283. );
  284. const user = userEvent.setup();
  285. render(<SettingsPage />);
  286. const heading = await screen.findByRole('heading', { name: 'Sidebar' });
  287. const card = heading.closest('#card-sidebar-links');
  288. expect(card).not.toBeNull();
  289. await screen.findByText('Docs');
  290. vi.mocked(localStorage.setItem).mockClear();
  291. await user.click(within(card as HTMLElement).getByRole('button', { name: /reset/i }));
  292. expect(localStorage.setItem).toHaveBeenCalledWith(SIDEBAR_HIDDEN_SYSTEM_ITEMS_KEY, JSON.stringify([]));
  293. expect(localStorage.setItem).toHaveBeenCalledWith(
  294. SIDEBAR_ORDER_KEY,
  295. JSON.stringify(['printers', 'inventory', 'archives', 'queue', 'projects', 'files', 'makerworld', 'profiles', 'maintenance', 'stats', 'settings', 'ext-7']),
  296. );
  297. const settingsRow = screen.getAllByText('Settings')
  298. .find(element => element.closest('[draggable="true"]'))
  299. ?.closest('[draggable="true"]');
  300. const docsRow = screen.getByText('Docs').closest('[draggable="true"]');
  301. expect(settingsRow).not.toBeNull();
  302. expect(docsRow).not.toBeNull();
  303. expect(settingsRow!.compareDocumentPosition(docsRow!) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
  304. expect(screen.queryByText('Hidden from sidebar')).not.toBeInTheDocument();
  305. });
  306. it('sets the current Sidebar order as the backend default for settings admins', async () => {
  307. let defaultSidebarOrderPayload: string | null = null;
  308. vi.mocked(localStorage.getItem).mockImplementation((key) => {
  309. if (key === SIDEBAR_HIDDEN_SYSTEM_ITEMS_KEY) return JSON.stringify(['stats']);
  310. return null;
  311. });
  312. server.use(
  313. http.get('/api/v1/auth/status', () =>
  314. HttpResponse.json({ auth_enabled: true, requires_setup: false }),
  315. ),
  316. http.get('/api/v1/auth/me', () =>
  317. HttpResponse.json({
  318. id: 1,
  319. username: 'admin',
  320. role: 'admin',
  321. is_active: true,
  322. is_admin: false,
  323. groups: [{ id: 1, name: 'Administrators' }],
  324. permissions: ['settings:update'],
  325. created_at: '2026-01-01T00:00:00Z',
  326. }),
  327. ),
  328. http.get('/api/v1/settings/', () =>
  329. HttpResponse.json({ ...mockSettings, default_sidebar_order: '' }),
  330. ),
  331. http.put('/api/v1/settings/', async ({ request }) => {
  332. const body = await request.json() as { default_sidebar_order?: string };
  333. defaultSidebarOrderPayload = body.default_sidebar_order ?? null;
  334. return HttpResponse.json({ ...mockSettings, ...body });
  335. }),
  336. );
  337. setAuthToken('test-token');
  338. const user = userEvent.setup();
  339. render(<SettingsPage />);
  340. const heading = await screen.findByRole('heading', { name: 'Sidebar' });
  341. const card = heading.closest('#card-sidebar-links');
  342. expect(card).not.toBeNull();
  343. await user.click(within(card as HTMLElement).getByRole('switch', { name: 'Set Default' }));
  344. await waitFor(() => {
  345. expect(defaultSidebarOrderPayload).not.toBeNull();
  346. });
  347. expect(JSON.parse(defaultSidebarOrderPayload!)).toEqual({
  348. order: [
  349. 'printers',
  350. 'inventory',
  351. 'archives',
  352. 'queue',
  353. 'projects',
  354. 'files',
  355. 'makerworld',
  356. 'profiles',
  357. 'maintenance',
  358. 'stats',
  359. 'settings',
  360. ],
  361. hiddenSystemItemIds: ['stats'],
  362. });
  363. });
  364. });
  365. describe('update CTA per deployment shape', () => {
  366. // The update card branches on the deployment shape returned by
  367. // /updates/check. Each branch is mutually exclusive — verify the right
  368. // one wins so HA addon users never see the docker-compose snippet
  369. // (which they can't run from inside an HA addon container) and Docker
  370. // users never see the in-app Install button (which would no-op).
  371. const renderWithUpdateCheck = async (
  372. checkBody: Record<string, unknown>,
  373. ) => {
  374. server.use(
  375. http.get('/api/v1/settings/', () =>
  376. HttpResponse.json({ ...mockSettings, check_updates: true }),
  377. ),
  378. http.get('/api/v1/updates/check', () => HttpResponse.json(checkBody)),
  379. );
  380. render(<SettingsPage />);
  381. await waitFor(() => {
  382. expect(screen.getByText('Updates')).toBeInTheDocument();
  383. });
  384. };
  385. it('shows the HA Supervisor message when running as an HA addon', async () => {
  386. await renderWithUpdateCheck({
  387. update_available: true,
  388. current_version: '0.2.4',
  389. latest_version: '0.2.5',
  390. release_name: '0.2.5',
  391. release_notes: '',
  392. release_url: 'https://example.invalid/r',
  393. published_at: '2099-01-01T00:00:00Z',
  394. is_docker: true,
  395. is_ha_addon: true,
  396. update_method: 'ha_addon',
  397. });
  398. await waitFor(() => {
  399. expect(
  400. screen.getByText(/Home Assistant Supervisor/i),
  401. ).toBeInTheDocument();
  402. });
  403. // Docker hint must NOT render — HA branch wins.
  404. expect(screen.queryByText('docker compose pull && docker compose up -d')).not.toBeInTheDocument();
  405. expect(screen.queryByRole('button', { name: /install update/i })).not.toBeInTheDocument();
  406. });
  407. it('shows the docker-compose snippet for Docker (non-HA) deployments', async () => {
  408. await renderWithUpdateCheck({
  409. update_available: true,
  410. current_version: '0.2.4',
  411. latest_version: '0.2.5',
  412. release_name: '0.2.5',
  413. release_notes: '',
  414. release_url: 'https://example.invalid/r',
  415. published_at: '2099-01-01T00:00:00Z',
  416. is_docker: true,
  417. is_ha_addon: false,
  418. update_method: 'docker',
  419. });
  420. await waitFor(() => {
  421. expect(screen.getByText('docker compose pull && docker compose up -d')).toBeInTheDocument();
  422. });
  423. expect(screen.queryByText(/Home Assistant Supervisor/i)).not.toBeInTheDocument();
  424. expect(screen.queryByRole('button', { name: /install update/i })).not.toBeInTheDocument();
  425. });
  426. });
  427. describe('tabs navigation', () => {
  428. it('can switch to Network tab', async () => {
  429. const user = userEvent.setup();
  430. render(<SettingsPage />);
  431. // Wait for settings to load first
  432. await waitFor(() => {
  433. expect(screen.getByText('Date Format')).toBeInTheDocument();
  434. });
  435. await user.click(screen.getByText('Network'));
  436. await waitFor(() => {
  437. // Network tab contains MQTT Publishing section
  438. expect(screen.getByText('MQTT Publishing')).toBeInTheDocument();
  439. });
  440. });
  441. it('can switch to Smart Plugs tab', async () => {
  442. const user = userEvent.setup();
  443. render(<SettingsPage />);
  444. await waitFor(() => {
  445. expect(screen.getByText('Smart Plugs')).toBeInTheDocument();
  446. });
  447. await user.click(screen.getByText('Smart Plugs'));
  448. await waitFor(() => {
  449. expect(screen.getByText('Add Smart Plug')).toBeInTheDocument();
  450. });
  451. });
  452. it('can switch to Notifications tab', async () => {
  453. const user = userEvent.setup();
  454. render(<SettingsPage />);
  455. await waitFor(() => {
  456. expect(screen.getAllByText('Notifications').length).toBeGreaterThan(0);
  457. });
  458. // Click the tab button (not the mobile dropdown option)
  459. const notificationButtons = screen.getAllByText('Notifications');
  460. const tabButton = notificationButtons.find(el => el.tagName === 'BUTTON') || notificationButtons[0];
  461. await user.click(tabButton);
  462. await waitFor(() => {
  463. expect(screen.getByText('Add Provider')).toBeInTheDocument();
  464. });
  465. });
  466. it('can switch to Filament tab', async () => {
  467. const user = userEvent.setup();
  468. render(<SettingsPage />);
  469. await waitFor(() => {
  470. expect(screen.getAllByText('Filament').length).toBeGreaterThan(0);
  471. });
  472. await user.click(screen.getAllByText('Filament')[0]);
  473. await waitFor(() => {
  474. expect(screen.getByText('AMS Display Thresholds')).toBeInTheDocument();
  475. });
  476. });
  477. });
  478. describe('Workflow tab', () => {
  479. it('can switch to Workflow tab', async () => {
  480. const user = userEvent.setup();
  481. render(<SettingsPage />);
  482. await waitFor(() => {
  483. expect(screen.getByText('Workflow')).toBeInTheDocument();
  484. });
  485. await user.click(screen.getByText('Workflow'));
  486. await waitFor(() => {
  487. expect(screen.getByText('Staggered Start')).toBeInTheDocument();
  488. });
  489. });
  490. it('shows stagger settings on Workflow tab', async () => {
  491. const user = userEvent.setup();
  492. render(<SettingsPage />);
  493. await waitFor(() => {
  494. expect(screen.getByText('Workflow')).toBeInTheDocument();
  495. });
  496. await user.click(screen.getByText('Workflow'));
  497. await waitFor(() => {
  498. expect(screen.getByText('Staggered Start')).toBeInTheDocument();
  499. expect(screen.getByText('Group size')).toBeInTheDocument();
  500. expect(screen.getByText('Interval (minutes)')).toBeInTheDocument();
  501. });
  502. });
  503. it('shows auto-drying settings on Workflow tab', async () => {
  504. const user = userEvent.setup();
  505. render(<SettingsPage />);
  506. await waitFor(() => {
  507. expect(screen.getByText('Workflow')).toBeInTheDocument();
  508. });
  509. await user.click(screen.getByText('Workflow'));
  510. await waitFor(() => {
  511. expect(screen.getByText('Queue Auto-Drying')).toBeInTheDocument();
  512. });
  513. });
  514. it('shows default print options on Workflow tab', async () => {
  515. const user = userEvent.setup();
  516. render(<SettingsPage />);
  517. await waitFor(() => {
  518. expect(screen.getByText('Workflow')).toBeInTheDocument();
  519. });
  520. await user.click(screen.getByText('Workflow'));
  521. await waitFor(() => {
  522. expect(screen.getByText('Default Print Options')).toBeInTheDocument();
  523. expect(screen.getByText('Bed Levelling')).toBeInTheDocument();
  524. expect(screen.getByText('Flow Calibration')).toBeInTheDocument();
  525. expect(screen.getByText('Vibration Calibration')).toBeInTheDocument();
  526. expect(screen.getByText('First Layer Inspection')).toBeInTheDocument();
  527. expect(screen.getByText('Timelapse')).toBeInTheDocument();
  528. });
  529. });
  530. it('shows default print options description', async () => {
  531. const user = userEvent.setup();
  532. render(<SettingsPage />);
  533. await waitFor(() => {
  534. expect(screen.getByText('Workflow')).toBeInTheDocument();
  535. });
  536. await user.click(screen.getByText('Workflow'));
  537. await waitFor(() => {
  538. expect(screen.getByText(/overridden per print in the print dialog/)).toBeInTheDocument();
  539. });
  540. });
  541. });
  542. describe('API Keys tab', () => {
  543. it('can switch to API Keys tab', async () => {
  544. const user = userEvent.setup();
  545. render(<SettingsPage />);
  546. await waitFor(() => {
  547. expect(screen.getByText('API Keys')).toBeInTheDocument();
  548. });
  549. await user.click(screen.getByText('API Keys'));
  550. await waitFor(() => {
  551. // Button text is "Create Key"
  552. expect(screen.getByText('Create Key')).toBeInTheDocument();
  553. });
  554. });
  555. });
  556. describe('SpoolBuddy tab badge', () => {
  557. const baseDevice = {
  558. id: 1,
  559. device_id: 'sb-0001',
  560. hostname: 'sb-kitchen',
  561. ip_address: '10.0.0.1',
  562. backend_url: null,
  563. firmware_version: '1.0.0',
  564. has_nfc: true,
  565. has_scale: true,
  566. tare_offset: 0,
  567. calibration_factor: 1.0,
  568. nfc_reader_type: null,
  569. nfc_connection: null,
  570. display_brightness: 100,
  571. display_blank_timeout: 0,
  572. has_backlight: false,
  573. last_calibrated_at: null,
  574. last_seen: new Date().toISOString(),
  575. pending_command: null,
  576. nfc_ok: true,
  577. scale_ok: true,
  578. uptime_s: 100,
  579. update_status: null,
  580. update_message: null,
  581. system_stats: null,
  582. online: true,
  583. created_at: '2024-01-01T00:00:00Z',
  584. updated_at: '2024-01-01T00:00:00Z',
  585. };
  586. it('shows device count and green bullet when at least one device is online', async () => {
  587. server.use(
  588. http.get('/api/v1/spoolbuddy/devices', () => {
  589. return HttpResponse.json([
  590. { ...baseDevice, id: 1, device_id: 'sb-0001', hostname: 'sb-kitchen', online: true },
  591. { ...baseDevice, id: 2, device_id: 'sb-0002', hostname: 'sb-ghost', online: false },
  592. ]);
  593. })
  594. );
  595. render(<SettingsPage />);
  596. // Find the tab button (not the header) — it's the <button> containing the SpoolBuddy text
  597. const tabButton = await waitFor(() => {
  598. const buttons = screen.getAllByRole('button').filter((b) => b.textContent?.includes('SpoolBuddy'));
  599. expect(buttons.length).toBeGreaterThan(0);
  600. return buttons[0];
  601. });
  602. // Count pill rendered
  603. await waitFor(() => {
  604. expect(tabButton.textContent).toContain('2');
  605. });
  606. // Green status bullet (at least one device online)
  607. await waitFor(() => {
  608. expect(tabButton.querySelector('.bg-green-400')).not.toBeNull();
  609. });
  610. });
  611. it('shows gray bullet when all devices are offline', async () => {
  612. server.use(
  613. http.get('/api/v1/spoolbuddy/devices', () => {
  614. return HttpResponse.json([{ ...baseDevice, online: false }]);
  615. })
  616. );
  617. render(<SettingsPage />);
  618. const tabButton = await waitFor(() => {
  619. const buttons = screen.getAllByRole('button').filter((b) => b.textContent?.includes('SpoolBuddy'));
  620. expect(buttons.length).toBeGreaterThan(0);
  621. return buttons[0];
  622. });
  623. await waitFor(() => {
  624. expect(tabButton.querySelector('.bg-gray-500')).not.toBeNull();
  625. expect(tabButton.querySelector('.bg-green-400')).toBeNull();
  626. });
  627. });
  628. it('hides the count pill when no devices are registered', async () => {
  629. server.use(
  630. http.get('/api/v1/spoolbuddy/devices', () => HttpResponse.json([]))
  631. );
  632. render(<SettingsPage />);
  633. const tabButton = await waitFor(() => {
  634. const buttons = screen.getAllByRole('button').filter((b) => b.textContent?.includes('SpoolBuddy'));
  635. expect(buttons.length).toBeGreaterThan(0);
  636. return buttons[0];
  637. });
  638. // The only numeric content should NOT be present — tab label only
  639. await waitFor(() => {
  640. expect(tabButton.textContent).toBe('SpoolBuddy');
  641. });
  642. });
  643. });
  644. describe('API Keys tab — delete flow', () => {
  645. // Without setQueryData on success the deleted row stayed visible until a
  646. // manual reload — invalidateQueries didn't reliably trigger a UI swap on
  647. // every browser. Pin the synchronous-removal contract here.
  648. it('removes a deleted key from the list without a page reload', async () => {
  649. const initialKeys = [
  650. {
  651. id: 42,
  652. name: 'CI deploy key',
  653. key_prefix: 'bk_abcd1234',
  654. can_queue: true,
  655. can_control_printer: false,
  656. can_read_status: true,
  657. printer_ids: null,
  658. enabled: true,
  659. last_used: null,
  660. created_at: '2026-01-01T00:00:00Z',
  661. expires_at: null,
  662. },
  663. ];
  664. let deleteCallCount = 0;
  665. server.use(
  666. http.get('/api/v1/api-keys/', () => HttpResponse.json(initialKeys)),
  667. http.delete('/api/v1/api-keys/:id', ({ params }) => {
  668. deleteCallCount += 1;
  669. expect(params.id).toBe('42');
  670. return HttpResponse.json({ message: 'API key deleted' });
  671. })
  672. );
  673. const user = userEvent.setup();
  674. render(<SettingsPage />);
  675. // Switch to API Keys tab. Both desktop tab + mobile dropdown render
  676. // the label, so just grab the button form.
  677. await waitFor(() => {
  678. expect(screen.getAllByText('API Keys').length).toBeGreaterThan(0);
  679. });
  680. const tabButton = screen.getAllByText('API Keys').find((el) => el.tagName === 'BUTTON');
  681. expect(tabButton).toBeDefined();
  682. await user.click(tabButton!);
  683. // Key is listed
  684. await waitFor(() => {
  685. expect(screen.getByText('CI deploy key')).toBeInTheDocument();
  686. });
  687. // Click the trash button on the row
  688. const cards = screen.getByText('CI deploy key').closest('.flex.items-center.justify-between');
  689. expect(cards).not.toBeNull();
  690. const trashButton = cards!.querySelectorAll('button');
  691. await user.click(trashButton[trashButton.length - 1]);
  692. // Confirm the deletion in the modal
  693. const confirmButton = await screen.findByRole('button', { name: /delete/i });
  694. await user.click(confirmButton);
  695. // The deleted key disappears from the list immediately — no manual
  696. // reload required. setQueryData drops it before any refetch could fire.
  697. await waitFor(() => {
  698. expect(screen.queryByText('CI deploy key')).not.toBeInTheDocument();
  699. });
  700. expect(deleteCallCount).toBe(1);
  701. });
  702. });
  703. describe('API Keys tab — #1182 cloud access + ownership UI', () => {
  704. // The list now exposes two new bits of information per row:
  705. // - "Cloud" badge when can_access_cloud=true
  706. // - "Legacy" badge when user_id IS NULL (created before per-user ownership)
  707. // These tell the operator at a glance which keys can read /cloud/* data
  708. // and which keys need to be recreated to gain that capability.
  709. it('renders the Cloud badge for keys with can_access_cloud=true and the Legacy badge for ownerless keys', async () => {
  710. const keys = [
  711. {
  712. id: 1,
  713. name: 'cloud-reader',
  714. key_prefix: 'bk_cloud123',
  715. user_id: 7,
  716. can_queue: false,
  717. can_control_printer: false,
  718. can_read_status: true,
  719. can_access_cloud: true,
  720. printer_ids: null,
  721. enabled: true,
  722. last_used: null,
  723. created_at: '2026-04-30T00:00:00Z',
  724. expires_at: null,
  725. },
  726. {
  727. id: 2,
  728. name: 'legacy-key',
  729. key_prefix: 'bk_legacy01',
  730. user_id: null,
  731. can_queue: true,
  732. can_control_printer: false,
  733. can_read_status: true,
  734. can_access_cloud: false,
  735. printer_ids: null,
  736. enabled: true,
  737. last_used: null,
  738. created_at: '2025-01-01T00:00:00Z',
  739. expires_at: null,
  740. },
  741. ];
  742. server.use(http.get('/api/v1/api-keys/', () => HttpResponse.json(keys)));
  743. const user = userEvent.setup();
  744. render(<SettingsPage />);
  745. await waitFor(() => {
  746. expect(screen.getAllByText('API Keys').length).toBeGreaterThan(0);
  747. });
  748. const tabButton = screen.getAllByText('API Keys').find((el) => el.tagName === 'BUTTON');
  749. await user.click(tabButton!);
  750. await waitFor(() => {
  751. expect(screen.getByText('cloud-reader')).toBeInTheDocument();
  752. expect(screen.getByText('legacy-key')).toBeInTheDocument();
  753. });
  754. // Cloud-enabled key gets the Cloud badge but NOT the Legacy badge.
  755. const cloudRow = screen.getByText('cloud-reader').closest('.flex.items-center.justify-between');
  756. expect(cloudRow).not.toBeNull();
  757. expect(cloudRow!.textContent).toContain('Cloud');
  758. expect(cloudRow!.textContent).not.toContain('Legacy');
  759. // Ownerless key gets Legacy but NOT Cloud (can_access_cloud=false).
  760. const legacyRow = screen.getByText('legacy-key').closest('.flex.items-center.justify-between');
  761. expect(legacyRow).not.toBeNull();
  762. expect(legacyRow!.textContent).toContain('Legacy');
  763. // Strip the Cloud-flag check by limiting to badge area — the
  764. // "Allow cloud access" text from the create form isn't visible here.
  765. expect(legacyRow!.querySelector('.bg-purple-500\\/20')).toBeNull();
  766. });
  767. it('passes can_access_cloud through to the create call when the toggle is checked', async () => {
  768. let posted: { name?: string; can_access_cloud?: boolean } | null = null;
  769. server.use(
  770. http.get('/api/v1/api-keys/', () => HttpResponse.json([])),
  771. http.post('/api/v1/api-keys/', async ({ request }) => {
  772. posted = (await request.json()) as { name?: string; can_access_cloud?: boolean };
  773. return HttpResponse.json({
  774. id: 99,
  775. key: 'bk_returnedkey',
  776. name: posted.name,
  777. key_prefix: 'bk_returne',
  778. user_id: 1,
  779. can_queue: true,
  780. can_control_printer: false,
  781. can_read_status: true,
  782. can_access_cloud: posted.can_access_cloud ?? false,
  783. printer_ids: null,
  784. enabled: true,
  785. last_used: null,
  786. created_at: '2026-05-01T00:00:00Z',
  787. expires_at: null,
  788. });
  789. })
  790. );
  791. const user = userEvent.setup();
  792. render(<SettingsPage />);
  793. await waitFor(() => {
  794. expect(screen.getAllByText('API Keys').length).toBeGreaterThan(0);
  795. });
  796. const tabButton = screen.getAllByText('API Keys').find((el) => el.tagName === 'BUTTON');
  797. await user.click(tabButton!);
  798. // Open the create form. With an empty key list the empty-state card
  799. // shows "Create Your First Key" — click that to open the form.
  800. const openButton = await screen.findByRole('button', { name: /Create Your First Key/i });
  801. await user.click(openButton);
  802. // Tick the new "Allow cloud access" checkbox. The label wraps the
  803. // input AND a sibling description div, so getByLabelText doesn't
  804. // resolve via implicit-label traversal — locate via text + closest
  805. // label, then grab the checkbox from the same scope.
  806. const cloudLabelText = await screen.findByText(/Allow cloud access/i);
  807. const cloudLabel = cloudLabelText.closest('label');
  808. expect(cloudLabel).not.toBeNull();
  809. const cloudCheckbox = cloudLabel!.querySelector('input[type="checkbox"]') as HTMLInputElement;
  810. expect(cloudCheckbox).not.toBeNull();
  811. await user.click(cloudCheckbox);
  812. // Submit. Two "Create Key" buttons exist once the form is open (header
  813. // CTA + form footer); the form-footer one is the actual submit and
  814. // calls the mutation — find it by walking up from the cloud checkbox
  815. // we just clicked, since both share the same form container.
  816. const submitButtons = screen.getAllByRole('button', { name: /^Create Key$/i });
  817. // Footer submit is the one inside the same form section as the
  818. // checkbox. The header CTA is in a separate flex row.
  819. const formSubmit = submitButtons.find(
  820. (b) => b.closest('div')?.contains(cloudCheckbox) || cloudLabel?.parentElement?.parentElement?.contains(b),
  821. );
  822. await user.click(formSubmit ?? submitButtons[submitButtons.length - 1]);
  823. await waitFor(() => {
  824. expect(posted).not.toBeNull();
  825. expect(posted!.can_access_cloud).toBe(true);
  826. });
  827. });
  828. });
  829. describe('API Keys tab — #1356 energy-cost write scope', () => {
  830. /**
  831. * The narrowly-scoped settings-write toggle. We pin two contracts here:
  832. *
  833. * 1. The "Energy" badge renders for keys that have can_update_energy_cost=true.
  834. * Without a visible signal, an operator can't tell which key in their
  835. * list is the one their HA automation depends on.
  836. * 2. The create form sends can_update_energy_cost=true to the backend
  837. * when the toggle is checked. The whole point of #1356 is that the
  838. * flag must actually be persisted — a UI that drops it silently
  839. * would put us right back where the bug started.
  840. */
  841. it('renders the Energy badge for keys with can_update_energy_cost=true', async () => {
  842. const keys = [
  843. {
  844. id: 1,
  845. name: 'tariff-pusher',
  846. key_prefix: 'bk_tariff01',
  847. user_id: 7,
  848. can_queue: false,
  849. can_control_printer: false,
  850. can_read_status: true,
  851. can_access_cloud: false,
  852. can_update_energy_cost: true,
  853. printer_ids: null,
  854. enabled: true,
  855. last_used: null,
  856. created_at: '2026-05-15T00:00:00Z',
  857. expires_at: null,
  858. },
  859. ];
  860. server.use(http.get('/api/v1/api-keys/', () => HttpResponse.json(keys)));
  861. const user = userEvent.setup();
  862. render(<SettingsPage />);
  863. await waitFor(() => {
  864. expect(screen.getAllByText('API Keys').length).toBeGreaterThan(0);
  865. });
  866. const tabButton = screen.getAllByText('API Keys').find((el) => el.tagName === 'BUTTON');
  867. await user.click(tabButton!);
  868. await waitFor(() => {
  869. expect(screen.getByText('tariff-pusher')).toBeInTheDocument();
  870. });
  871. const row = screen.getByText('tariff-pusher').closest('.flex.items-center.justify-between');
  872. expect(row).not.toBeNull();
  873. expect(row!.textContent).toContain('Energy');
  874. });
  875. it('passes can_update_energy_cost through to the create call when the toggle is checked', async () => {
  876. let posted: { name?: string; can_update_energy_cost?: boolean } | null = null;
  877. server.use(
  878. http.get('/api/v1/api-keys/', () => HttpResponse.json([])),
  879. http.post('/api/v1/api-keys/', async ({ request }) => {
  880. posted = (await request.json()) as { name?: string; can_update_energy_cost?: boolean };
  881. return HttpResponse.json({
  882. id: 99,
  883. key: 'bk_returnedkey',
  884. name: posted.name,
  885. key_prefix: 'bk_returne',
  886. user_id: 1,
  887. can_queue: true,
  888. can_control_printer: false,
  889. can_read_status: true,
  890. can_access_cloud: false,
  891. can_update_energy_cost: posted.can_update_energy_cost ?? false,
  892. printer_ids: null,
  893. enabled: true,
  894. last_used: null,
  895. created_at: '2026-05-15T00:00:00Z',
  896. expires_at: null,
  897. });
  898. })
  899. );
  900. const user = userEvent.setup();
  901. render(<SettingsPage />);
  902. await waitFor(() => {
  903. expect(screen.getAllByText('API Keys').length).toBeGreaterThan(0);
  904. });
  905. const tabButton = screen.getAllByText('API Keys').find((el) => el.tagName === 'BUTTON');
  906. await user.click(tabButton!);
  907. const openButton = await screen.findByRole('button', { name: /Create Your First Key/i });
  908. await user.click(openButton);
  909. const energyLabelText = await screen.findByText(/Update electricity price/i);
  910. const energyLabel = energyLabelText.closest('label');
  911. expect(energyLabel).not.toBeNull();
  912. const energyCheckbox = energyLabel!.querySelector('input[type="checkbox"]') as HTMLInputElement;
  913. expect(energyCheckbox).not.toBeNull();
  914. await user.click(energyCheckbox);
  915. const submitButtons = screen.getAllByRole('button', { name: /^Create Key$/i });
  916. const formSubmit = submitButtons.find(
  917. (b) => b.closest('div')?.contains(energyCheckbox) || energyLabel?.parentElement?.parentElement?.contains(b),
  918. );
  919. await user.click(formSubmit ?? submitButtons[submitButtons.length - 1]);
  920. await waitFor(() => {
  921. expect(posted).not.toBeNull();
  922. expect(posted!.can_update_energy_cost).toBe(true);
  923. });
  924. });
  925. });
  926. describe('external camera snapshot URL override (#1177)', () => {
  927. /**
  928. * The snapshot URL input only appears for stream camera types where the
  929. * MJPEG warm-up problem can occur (mjpeg / rtsp / usb). Pure HTTP
  930. * snapshot sources don't need an override since their stream URL is
  931. * already a single-frame endpoint.
  932. */
  933. const mjpegPrinter = {
  934. id: 7,
  935. name: 'go2rtc Cam',
  936. serial_number: 'TEST123',
  937. ip_address: '192.168.1.100',
  938. access_code: 'XXXX',
  939. model: 'P1S',
  940. location: null,
  941. nozzle_count: 1,
  942. is_active: true,
  943. auto_archive: true,
  944. external_camera_url: 'http://192.168.1.61:1984/api/stream.mjpeg?src=printer',
  945. external_camera_type: 'mjpeg',
  946. external_camera_enabled: true,
  947. external_camera_snapshot_url: null,
  948. camera_rotation: 0,
  949. plate_detection_enabled: false,
  950. created_at: '2026-01-01T00:00:00Z',
  951. updated_at: '2026-01-01T00:00:00Z',
  952. };
  953. it('renders the snapshot URL input when camera_type is mjpeg', async () => {
  954. server.use(
  955. http.get('/api/v1/printers/', () => HttpResponse.json([mjpegPrinter])),
  956. );
  957. render(<SettingsPage />);
  958. await waitFor(() => {
  959. expect(screen.getByPlaceholderText(/api\/frame\.jpeg\?src=printer/)).toBeInTheDocument();
  960. });
  961. });
  962. it('hides the snapshot URL input when camera_type is snapshot (already a single-frame source)', async () => {
  963. server.use(
  964. http.get('/api/v1/printers/', () =>
  965. HttpResponse.json([{ ...mjpegPrinter, external_camera_type: 'snapshot' }]),
  966. ),
  967. );
  968. render(<SettingsPage />);
  969. // Wait for the live-stream URL placeholder to render so we know the
  970. // camera section finished mounting before asserting absence of the
  971. // snapshot input below.
  972. await waitFor(() => {
  973. expect(screen.getByPlaceholderText(/Camera URL/i)).toBeInTheDocument();
  974. });
  975. expect(screen.queryByPlaceholderText(/api\/frame\.jpeg\?src=printer/)).not.toBeInTheDocument();
  976. });
  977. it(
  978. 'PATCHes the printer with external_camera_snapshot_url when the user types into the input',
  979. async () => {
  980. let receivedBody: Record<string, unknown> | null = null;
  981. server.use(
  982. http.get('/api/v1/printers/', () => HttpResponse.json([mjpegPrinter])),
  983. http.patch('/api/v1/printers/7', async ({ request }) => {
  984. receivedBody = (await request.json()) as Record<string, unknown>;
  985. return HttpResponse.json({ ...mjpegPrinter, ...receivedBody });
  986. }),
  987. );
  988. render(<SettingsPage />);
  989. const input = await waitFor(() =>
  990. screen.getByPlaceholderText(/api\/frame\.jpeg\?src=printer/),
  991. );
  992. const user = userEvent.setup();
  993. await user.type(input, 'http://192.168.1.61:1984/api/frame.jpeg?src=printer');
  994. // Save is debounced by 800ms; assert the PATCH eventually fires with
  995. // the typed snapshot URL.
  996. await waitFor(
  997. () => {
  998. expect(receivedBody).not.toBeNull();
  999. expect(receivedBody!.external_camera_snapshot_url).toBe(
  1000. 'http://192.168.1.61:1984/api/frame.jpeg?src=printer',
  1001. );
  1002. },
  1003. { timeout: 5000 },
  1004. );
  1005. },
  1006. // Per-test timeout raised to 15s — `user.type()` of a 49-char URL plus
  1007. // the 800ms save debounce fits in 5s locally (~2.3s typical) but blows
  1008. // past it on slow GitHub Actions runners (5000ms timeout was the failure
  1009. // mode on PR #1263).
  1010. 15_000,
  1011. );
  1012. });
  1013. describe('theme mode buttons', () => {
  1014. it('renders Dark, Light, and System buttons', async () => {
  1015. render(<SettingsPage />);
  1016. await waitFor(() => {
  1017. expect(screen.getByRole('button', { name: 'Dark' })).toBeInTheDocument();
  1018. expect(screen.getByRole('button', { name: 'Light' })).toBeInTheDocument();
  1019. expect(screen.getByRole('button', { name: 'System' })).toBeInTheDocument();
  1020. });
  1021. });
  1022. it('highlights the active mode button with green border', async () => {
  1023. render(<SettingsPage />);
  1024. const user = userEvent.setup();
  1025. await waitFor(() => {
  1026. expect(screen.getByRole('button', { name: 'System' })).toBeInTheDocument();
  1027. });
  1028. await user.click(screen.getByRole('button', { name: 'System' }));
  1029. await waitFor(() => {
  1030. const systemBtn = screen.getByRole('button', { name: 'System' });
  1031. expect(systemBtn.className).toContain('border-bambu-green');
  1032. });
  1033. });
  1034. it('clicking a theme button switches mode', async () => {
  1035. localStorage.setItem('theme-mode', 'dark');
  1036. render(<SettingsPage />);
  1037. const user = userEvent.setup();
  1038. await waitFor(() => {
  1039. const darkBtn = screen.getByRole('button', { name: 'Dark' });
  1040. expect(darkBtn.className).toContain('border-bambu-green');
  1041. });
  1042. const lightBtn = screen.getByRole('button', { name: 'Light' });
  1043. await user.click(lightBtn);
  1044. await waitFor(() => {
  1045. expect(lightBtn.className).toContain('border-bambu-green');
  1046. });
  1047. });
  1048. it('shows a toast when theme button is clicked', async () => {
  1049. render(<SettingsPage />);
  1050. const user = userEvent.setup();
  1051. await waitFor(() => {
  1052. expect(screen.getByRole('button', { name: 'System' })).toBeInTheDocument();
  1053. });
  1054. await user.click(screen.getByRole('button', { name: 'System' }));
  1055. await waitFor(() => {
  1056. expect(screen.getByText('Settings saved')).toBeInTheDocument();
  1057. });
  1058. });
  1059. });
  1060. });