PrintersPage.test.tsx 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237
  1. /**
  2. * Tests for the PrintersPage component.
  3. */
  4. import { describe, it, expect, beforeEach } from 'vitest';
  5. import { screen, waitFor, fireEvent } from '@testing-library/react';
  6. import userEvent from '@testing-library/user-event';
  7. import { render } from '../utils';
  8. import { PrintersPage } from '../../pages/PrintersPage';
  9. import { http, HttpResponse } from 'msw';
  10. import { server } from '../mocks/server';
  11. const mockPrinters = [
  12. {
  13. id: 1,
  14. name: 'X1 Carbon',
  15. ip_address: '192.168.1.100',
  16. serial_number: '00M09A350100001',
  17. access_code: '12345678',
  18. model: 'X1C',
  19. enabled: true,
  20. nozzle_diameter: 0.4,
  21. nozzle_type: 'hardened_steel',
  22. location: 'Workshop',
  23. auto_archive: true,
  24. created_at: '2024-01-01T00:00:00Z',
  25. updated_at: '2024-01-01T00:00:00Z',
  26. },
  27. {
  28. id: 2,
  29. name: 'P1S Backup',
  30. ip_address: '192.168.1.101',
  31. serial_number: '00W00A123456789',
  32. access_code: '87654321',
  33. model: 'P1S',
  34. enabled: false,
  35. nozzle_diameter: 0.4,
  36. nozzle_type: 'stainless_steel',
  37. location: null,
  38. auto_archive: true,
  39. created_at: '2024-01-02T00:00:00Z',
  40. updated_at: '2024-01-02T00:00:00Z',
  41. },
  42. ];
  43. const mockPrinterStatus = {
  44. connected: true,
  45. state: 'IDLE',
  46. awaiting_plate_clear: false,
  47. progress: 0,
  48. layer_num: 0,
  49. total_layers: 0,
  50. temperatures: {
  51. nozzle: 25,
  52. bed: 25,
  53. chamber: 25,
  54. },
  55. remaining_time: 0,
  56. filename: null,
  57. wifi_signal: -50,
  58. vt_tray: [],
  59. };
  60. const selectToolbarDropdownOption = async (triggerName: RegExp, optionName: RegExp) => {
  61. const user = userEvent.setup();
  62. await user.click(screen.getByRole('button', { name: triggerName }));
  63. await user.click(await screen.findByRole('button', { name: optionName }));
  64. };
  65. describe('PrintersPage', () => {
  66. beforeEach(() => {
  67. localStorage.removeItem('printerCardSize');
  68. server.use(
  69. http.get('/api/v1/printers/', () => {
  70. return HttpResponse.json(mockPrinters);
  71. }),
  72. http.get('/api/v1/printers/:id/status', () => {
  73. return HttpResponse.json(mockPrinterStatus);
  74. }),
  75. http.post('/api/v1/printers/:id/clear-plate', () => {
  76. return HttpResponse.json({ success: true, message: 'Plate cleared' });
  77. }),
  78. http.get('/api/v1/settings/', () => {
  79. return HttpResponse.json({
  80. auto_archive: true,
  81. save_thumbnails: true,
  82. capture_finish_photo: true,
  83. default_filament_cost: 25.0,
  84. currency: 'USD',
  85. ams_humidity_good: 40,
  86. ams_humidity_fair: 60,
  87. ams_temp_good: 30,
  88. ams_temp_fair: 35,
  89. require_plate_clear: true,
  90. });
  91. }),
  92. http.get('/api/v1/queue/', () => {
  93. return HttpResponse.json([]);
  94. })
  95. );
  96. });
  97. describe('rendering', () => {
  98. it('renders the page title', async () => {
  99. render(<PrintersPage />);
  100. await waitFor(() => {
  101. expect(screen.getByText('Printers')).toBeInTheDocument();
  102. });
  103. });
  104. it('shows printer cards', async () => {
  105. render(<PrintersPage />);
  106. await waitFor(() => {
  107. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  108. expect(screen.getByText('P1S Backup')).toBeInTheDocument();
  109. });
  110. });
  111. it('shows printer models', async () => {
  112. render(<PrintersPage />);
  113. await waitFor(() => {
  114. expect(screen.getByText('X1C')).toBeInTheDocument();
  115. expect(screen.getByText('P1S')).toBeInTheDocument();
  116. });
  117. });
  118. it('shows printer status', async () => {
  119. render(<PrintersPage />);
  120. await waitFor(() => {
  121. // Status should be shown - may vary based on state
  122. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  123. });
  124. });
  125. });
  126. describe('printer info', () => {
  127. it('shows IP address in printer info modal', async () => {
  128. render(<PrintersPage />);
  129. await waitFor(() => {
  130. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  131. });
  132. // IP address is shown in the PrinterInfoModal (accessed via 3-dot menu),
  133. // not directly on the card. Verify the printer data loaded correctly.
  134. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  135. });
  136. it('shows location when set', async () => {
  137. render(<PrintersPage />);
  138. await waitFor(() => {
  139. // Printers should render - location display may vary
  140. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  141. });
  142. });
  143. });
  144. describe('temperature display', () => {
  145. it('shows nozzle temperature', async () => {
  146. render(<PrintersPage />);
  147. await waitFor(() => {
  148. // Temperatures are shown in the UI
  149. expect(screen.getAllByText(/25/)).toBeTruthy();
  150. });
  151. });
  152. });
  153. describe('empty state', () => {
  154. it('shows empty state when no printers', async () => {
  155. server.use(
  156. http.get('/api/v1/printers/', () => {
  157. return HttpResponse.json([]);
  158. })
  159. );
  160. render(<PrintersPage />);
  161. await waitFor(() => {
  162. expect(screen.getByText(/no printers/i)).toBeInTheDocument();
  163. });
  164. });
  165. });
  166. describe('printer actions', () => {
  167. it('has action buttons', async () => {
  168. render(<PrintersPage />);
  169. await waitFor(() => {
  170. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  171. });
  172. // There should be some interactive elements for printer actions
  173. const buttons = screen.getAllByRole('button');
  174. expect(buttons.length).toBeGreaterThan(0);
  175. });
  176. it('shows plate clear status and action on finished printers when not cleared', async () => {
  177. server.use(
  178. http.get('/api/v1/printers/:id/status', () => {
  179. return HttpResponse.json({ ...mockPrinterStatus, state: 'FINISH', awaiting_plate_clear: true });
  180. })
  181. );
  182. render(<PrintersPage />);
  183. await waitFor(() => {
  184. expect(screen.getAllByText('Plate not Clear').length).toBeGreaterThan(0);
  185. });
  186. expect(screen.getAllByRole('button', { name: 'Mark plate as cleared' }).length).toBeGreaterThan(0);
  187. });
  188. it('shows plate clear status and action on failed printers when not cleared', async () => {
  189. server.use(
  190. http.get('/api/v1/printers/:id/status', () => {
  191. return HttpResponse.json({ ...mockPrinterStatus, state: 'FAILED', awaiting_plate_clear: true });
  192. })
  193. );
  194. render(<PrintersPage />);
  195. await waitFor(() => {
  196. expect(screen.getAllByText('Plate not Clear').length).toBeGreaterThan(0);
  197. });
  198. expect(screen.getAllByRole('button', { name: 'Mark plate as cleared' }).length).toBeGreaterThan(0);
  199. });
  200. it('keeps the clear action available when an idle printer is still awaiting acknowledgment', async () => {
  201. server.use(
  202. http.get('/api/v1/printers/:id/status', () => {
  203. return HttpResponse.json({ ...mockPrinterStatus, state: 'IDLE', awaiting_plate_clear: true });
  204. })
  205. );
  206. render(<PrintersPage />);
  207. await waitFor(() => {
  208. expect(screen.getAllByText('Plate not Clear').length).toBeGreaterThan(0);
  209. });
  210. expect(screen.getAllByRole('button', { name: 'Mark plate as cleared' }).length).toBeGreaterThan(0);
  211. });
  212. it('updates the plate clear status after using the printer card action', async () => {
  213. let awaitingPlateClear = true;
  214. server.use(
  215. http.get('/api/v1/printers/', () => {
  216. return HttpResponse.json([mockPrinters[0]]);
  217. }),
  218. http.get('/api/v1/printers/:id/status', () => {
  219. return HttpResponse.json({ ...mockPrinterStatus, state: 'FINISH', awaiting_plate_clear: awaitingPlateClear });
  220. }),
  221. http.post('/api/v1/printers/:id/clear-plate', () => {
  222. awaitingPlateClear = false;
  223. return HttpResponse.json({ success: true, message: 'Plate cleared' });
  224. })
  225. );
  226. render(<PrintersPage />);
  227. await waitFor(() => {
  228. expect(screen.getAllByText('Plate not Clear').length).toBeGreaterThan(0);
  229. });
  230. fireEvent.click(screen.getAllByRole('button', { name: 'Mark plate as cleared' })[0]);
  231. await waitFor(() => {
  232. expect(screen.queryByText('Plate not Clear')).not.toBeInTheDocument();
  233. });
  234. expect(screen.getAllByText('Plate Clear').length).toBeGreaterThan(0);
  235. });
  236. it('shows an icon-only plate clear action in small card view', async () => {
  237. let awaitingPlateClear = true;
  238. server.use(
  239. http.get('/api/v1/printers/', () => {
  240. return HttpResponse.json([mockPrinters[0]]);
  241. }),
  242. http.get('/api/v1/printers/:id/status', () => {
  243. return HttpResponse.json({ ...mockPrinterStatus, state: 'FINISH', awaiting_plate_clear: awaitingPlateClear });
  244. }),
  245. http.post('/api/v1/printers/:id/clear-plate', () => {
  246. awaitingPlateClear = false;
  247. return HttpResponse.json({ success: true, message: 'Plate cleared' });
  248. })
  249. );
  250. render(<PrintersPage />);
  251. await waitFor(() => {
  252. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  253. });
  254. fireEvent.click(screen.getByRole('button', { name: 'S' }));
  255. await waitFor(() => {
  256. expect(screen.queryByText('Mark plate as cleared')).not.toBeInTheDocument();
  257. });
  258. const clearButton = screen.getByRole('button', { name: 'Mark plate as cleared' });
  259. fireEvent.click(clearButton);
  260. await waitFor(() => {
  261. expect(screen.queryByRole('button', { name: 'Mark plate as cleared' })).not.toBeInTheDocument();
  262. });
  263. });
  264. it('shows plate clear status but no action while idle', async () => {
  265. render(<PrintersPage />);
  266. await waitFor(() => {
  267. expect(screen.getAllByText('Plate Clear').length).toBeGreaterThan(0);
  268. });
  269. expect(screen.queryByRole('button', { name: 'Mark plate as cleared' })).not.toBeInTheDocument();
  270. });
  271. it('shows plate in use status while printing and hides the clear action', async () => {
  272. server.use(
  273. http.get('/api/v1/printers/:id/status', () => {
  274. return HttpResponse.json({ ...mockPrinterStatus, state: 'RUNNING', awaiting_plate_clear: false });
  275. })
  276. );
  277. render(<PrintersPage />);
  278. await waitFor(() => {
  279. expect(screen.getAllByText('Plate in Use').length).toBeGreaterThan(0);
  280. });
  281. expect(screen.queryByRole('button', { name: 'Mark plate as cleared' })).not.toBeInTheDocument();
  282. });
  283. it('hides plate status and action when plate-clear confirmation is disabled', async () => {
  284. server.use(
  285. http.get('/api/v1/settings/', () => {
  286. return HttpResponse.json({
  287. auto_archive: true,
  288. save_thumbnails: true,
  289. capture_finish_photo: true,
  290. default_filament_cost: 25.0,
  291. currency: 'USD',
  292. ams_humidity_good: 40,
  293. ams_humidity_fair: 60,
  294. ams_temp_good: 30,
  295. ams_temp_fair: 35,
  296. require_plate_clear: false,
  297. });
  298. }),
  299. http.get('/api/v1/printers/:id/status', () => {
  300. return HttpResponse.json({ ...mockPrinterStatus, state: 'FINISH', awaiting_plate_clear: true });
  301. })
  302. );
  303. render(<PrintersPage />);
  304. await waitFor(() => {
  305. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  306. });
  307. expect(screen.queryByText('Plate not Clear')).not.toBeInTheDocument();
  308. expect(screen.queryByText('Plate Clear')).not.toBeInTheDocument();
  309. expect(screen.queryByText('Plate in Use')).not.toBeInTheDocument();
  310. expect(screen.queryByRole('button', { name: 'Mark plate as cleared' })).not.toBeInTheDocument();
  311. });
  312. });
  313. describe('disabled printer', () => {
  314. it('shows disabled state for disabled printers', async () => {
  315. render(<PrintersPage />);
  316. await waitFor(() => {
  317. expect(screen.getByText('P1S Backup')).toBeInTheDocument();
  318. });
  319. // Disabled printers have visual indication
  320. const disabledPrinter = screen.getByText('P1S Backup').closest('div');
  321. expect(disabledPrinter).toBeInTheDocument();
  322. });
  323. });
  324. describe('nozzle rack card', () => {
  325. const h2cStatus = {
  326. ...mockPrinterStatus,
  327. nozzle_rack: [
  328. { id: 0, nozzle_type: 'HS', nozzle_diameter: '0.4', wear: 5, stat: 1, max_temp: 300, serial_number: 'SN-L', filament_color: '', filament_id: '', filament_type: '' },
  329. { id: 1, nozzle_type: 'HS', nozzle_diameter: '0.4', wear: 3, stat: 0, max_temp: 300, serial_number: 'SN-R', filament_color: '', filament_id: '', filament_type: '' },
  330. { id: 16, nozzle_type: 'HS', nozzle_diameter: '0.4', wear: 10, stat: 0, max_temp: 300, serial_number: 'SN-16', filament_color: '', filament_id: '', filament_type: '' },
  331. { id: 17, nozzle_type: 'HH01', nozzle_diameter: '0.6', wear: 0, stat: 0, max_temp: 300, serial_number: 'SN-17', filament_color: '', filament_id: '', filament_type: '' },
  332. { id: 18, nozzle_type: 'HS', nozzle_diameter: '0.4', wear: 2, stat: 0, max_temp: 300, serial_number: 'SN-18', filament_color: '', filament_id: '', filament_type: '' },
  333. { id: 19, nozzle_type: '', nozzle_diameter: '', wear: null, stat: null, max_temp: 0, serial_number: '', filament_color: '', filament_id: '', filament_type: '' },
  334. { id: 20, nozzle_type: '', nozzle_diameter: '', wear: null, stat: null, max_temp: 0, serial_number: '', filament_color: '', filament_id: '', filament_type: '' },
  335. { id: 21, nozzle_type: '', nozzle_diameter: '', wear: null, stat: null, max_temp: 0, serial_number: '', filament_color: '', filament_id: '', filament_type: '' },
  336. ],
  337. };
  338. it('shows nozzle rack when H2C rack slots present', async () => {
  339. server.use(
  340. http.get('/api/v1/printers/:id/status', () => {
  341. return HttpResponse.json(h2cStatus);
  342. })
  343. );
  344. render(<PrintersPage />);
  345. await waitFor(() => {
  346. expect(screen.getAllByText('Nozzle Rack').length).toBeGreaterThan(0);
  347. });
  348. });
  349. it('shows 6 rack slot elements for H2C', async () => {
  350. server.use(
  351. http.get('/api/v1/printers/:id/status', () => {
  352. return HttpResponse.json(h2cStatus);
  353. })
  354. );
  355. render(<PrintersPage />);
  356. await waitFor(() => {
  357. expect(screen.getAllByText('Nozzle Rack').length).toBeGreaterThan(0);
  358. });
  359. // Rack shows diameters for occupied slots and dashes for empty ones
  360. const dashes = screen.getAllByText('—');
  361. expect(dashes.length).toBeGreaterThanOrEqual(3); // 3 empty rack positions (IDs 19,20,21)
  362. });
  363. it('keeps empty slot anchored to physical position when its nozzle is mounted (#943)', async () => {
  364. // H2C with rack slot 16 picked up into the hotend — firmware omits ID 16
  365. // entirely from nozzle.info. Each rack diameter is unique so we can assert
  366. // the ordering by tooltip lookup.
  367. const h2cSlot16Mounted = {
  368. ...mockPrinterStatus,
  369. nozzle_rack: [
  370. { id: 0, nozzle_type: 'HS', nozzle_diameter: '0.4', wear: 5, stat: 1, max_temp: 300, serial_number: 'SN-L', filament_color: '', filament_id: '', filament_type: '' },
  371. { id: 1, nozzle_type: 'HS', nozzle_diameter: '0.4', wear: 3, stat: 0, max_temp: 300, serial_number: 'SN-R', filament_color: '', filament_id: '', filament_type: '' },
  372. // ID 16 missing — currently in hotend
  373. { id: 17, nozzle_type: 'HS', nozzle_diameter: '0.2', wear: 0, stat: 0, max_temp: 300, serial_number: 'SN-17', filament_color: '', filament_id: '', filament_type: '' },
  374. { id: 18, nozzle_type: 'HS', nozzle_diameter: '0.6', wear: 0, stat: 0, max_temp: 300, serial_number: 'SN-18', filament_color: '', filament_id: '', filament_type: '' },
  375. { id: 19, nozzle_type: 'HS', nozzle_diameter: '0.8', wear: 0, stat: 0, max_temp: 300, serial_number: 'SN-19', filament_color: '', filament_id: '', filament_type: '' },
  376. { id: 20, nozzle_type: 'HH01', nozzle_diameter: '1.0', wear: 0, stat: 0, max_temp: 300, serial_number: 'SN-20', filament_color: '', filament_id: '', filament_type: '' },
  377. { id: 21, nozzle_type: 'HH01', nozzle_diameter: '1.2', wear: 0, stat: 0, max_temp: 300, serial_number: 'SN-21', filament_color: '', filament_id: '', filament_type: '' },
  378. ],
  379. };
  380. server.use(
  381. http.get('/api/v1/printers/:id/status', () => {
  382. return HttpResponse.json(h2cSlot16Mounted);
  383. })
  384. );
  385. render(<PrintersPage />);
  386. await waitFor(() => {
  387. expect(screen.getAllByText('Nozzle Rack').length).toBeGreaterThan(0);
  388. });
  389. // Slot 1 (leftmost, ID 16) should be the empty dash; slots 2..6 should
  390. // hold the 5 remaining nozzles in order 17, 18, 19, 20, 21.
  391. const rackLabel = screen.getAllByText('Nozzle Rack')[0];
  392. const rackCard = rackLabel.parentElement!;
  393. const slotRow = rackCard.querySelectorAll('div.flex')[0];
  394. const slotTexts = Array.from(slotRow.querySelectorAll('span')).map(s => s.textContent);
  395. expect(slotTexts).toEqual(['—', '0.2', '0.6', '0.8', '1.0', '1.2']);
  396. });
  397. it('hides nozzle rack when only L/R nozzles present (H2D)', async () => {
  398. const h2dStatus = {
  399. ...mockPrinterStatus,
  400. nozzle_rack: [
  401. { id: 0, nozzle_type: 'HS', nozzle_diameter: '0.4', wear: 5, stat: 1, max_temp: 300, serial_number: '', filament_color: '', filament_id: '', filament_type: '' },
  402. { id: 1, nozzle_type: 'HS', nozzle_diameter: '0.4', wear: 3, stat: 1, max_temp: 300, serial_number: '', filament_color: '', filament_id: '', filament_type: '' },
  403. ],
  404. };
  405. server.use(
  406. http.get('/api/v1/printers/:id/status', () => {
  407. return HttpResponse.json(h2dStatus);
  408. })
  409. );
  410. render(<PrintersPage />);
  411. await waitFor(() => {
  412. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  413. });
  414. expect(screen.queryByText('Nozzle Rack')).not.toBeInTheDocument();
  415. });
  416. });
  417. describe('firmware version badge', () => {
  418. const firmwareUpToDate = {
  419. printer_id: 1,
  420. current_version: '01.09.00.00',
  421. latest_version: '01.09.00.00',
  422. update_available: false,
  423. download_url: null,
  424. release_notes: 'Bug fixes and improvements.',
  425. };
  426. const firmwareUpdateAvailable = {
  427. printer_id: 1,
  428. current_version: '01.08.00.00',
  429. latest_version: '01.09.00.00',
  430. update_available: true,
  431. download_url: 'https://example.com/firmware.bin',
  432. release_notes: 'New features added.',
  433. };
  434. it('shows green badge when firmware is up to date', async () => {
  435. server.use(
  436. http.get('/api/v1/firmware/updates/:id', () => {
  437. return HttpResponse.json(firmwareUpToDate);
  438. }),
  439. http.get('/api/v1/settings/', () => {
  440. return HttpResponse.json({
  441. check_printer_firmware: true,
  442. auto_archive: true,
  443. save_thumbnails: true,
  444. });
  445. })
  446. );
  447. render(<PrintersPage />);
  448. await waitFor(() => {
  449. expect(screen.getAllByText('01.09.00.00').length).toBeGreaterThan(0);
  450. });
  451. const badge = screen.getAllByText('01.09.00.00')[0].closest('button');
  452. expect(badge).toBeInTheDocument();
  453. expect(badge?.className).toContain('text-status-ok');
  454. });
  455. it('shows orange badge when firmware update is available', async () => {
  456. server.use(
  457. http.get('/api/v1/firmware/updates/:id', () => {
  458. return HttpResponse.json(firmwareUpdateAvailable);
  459. }),
  460. http.get('/api/v1/settings/', () => {
  461. return HttpResponse.json({
  462. check_printer_firmware: true,
  463. auto_archive: true,
  464. save_thumbnails: true,
  465. });
  466. })
  467. );
  468. render(<PrintersPage />);
  469. await waitFor(() => {
  470. expect(screen.getAllByText('01.08.00.00').length).toBeGreaterThan(0);
  471. });
  472. const badge = screen.getAllByText('01.08.00.00')[0].closest('button');
  473. expect(badge).toBeInTheDocument();
  474. expect(badge?.className).toContain('text-orange-400');
  475. });
  476. it('hides badge when firmware check is disabled', async () => {
  477. server.use(
  478. http.get('/api/v1/settings/', () => {
  479. return HttpResponse.json({
  480. check_printer_firmware: false,
  481. auto_archive: true,
  482. save_thumbnails: true,
  483. });
  484. })
  485. );
  486. render(<PrintersPage />);
  487. await waitFor(() => {
  488. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  489. });
  490. // Version should not appear when firmware check is disabled
  491. expect(screen.queryByText('01.09.00.00')).not.toBeInTheDocument();
  492. expect(screen.queryByText('01.08.00.00')).not.toBeInTheDocument();
  493. });
  494. it('hides badge when API has no firmware data for the model', async () => {
  495. const firmwareNoData = {
  496. printer_id: 1,
  497. current_version: '01.01.03.00',
  498. latest_version: null,
  499. update_available: false,
  500. download_url: null,
  501. release_notes: null,
  502. };
  503. server.use(
  504. http.get('/api/v1/firmware/updates/:id', () => {
  505. return HttpResponse.json(firmwareNoData);
  506. }),
  507. http.get('/api/v1/settings/', () => {
  508. return HttpResponse.json({
  509. check_printer_firmware: true,
  510. auto_archive: true,
  511. save_thumbnails: true,
  512. });
  513. })
  514. );
  515. render(<PrintersPage />);
  516. await waitFor(() => {
  517. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  518. });
  519. // Badge should not appear when API returns no latest_version
  520. expect(screen.queryByText('01.01.03.00')).not.toBeInTheDocument();
  521. });
  522. });
  523. describe('bulk selection', () => {
  524. it('shows select button in toolbar', async () => {
  525. render(<PrintersPage />);
  526. await waitFor(() => {
  527. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  528. });
  529. // The Select button should be in the toolbar (title attribute)
  530. const selectButton = screen.getByTitle('Select');
  531. expect(selectButton).toBeInTheDocument();
  532. });
  533. it('shows selection toolbar after clicking select button', async () => {
  534. render(<PrintersPage />);
  535. await waitFor(() => {
  536. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  537. });
  538. // Click the Select button to enter selection mode
  539. fireEvent.click(screen.getByTitle('Select'));
  540. // The floating toolbar should appear with Select All
  541. await waitFor(() => {
  542. expect(screen.getByText('Select All')).toBeInTheDocument();
  543. });
  544. });
  545. it('shows selection count when printers are selected', async () => {
  546. render(<PrintersPage />);
  547. await waitFor(() => {
  548. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  549. });
  550. // Enter selection mode
  551. fireEvent.click(screen.getByTitle('Select'));
  552. await waitFor(() => {
  553. expect(screen.getByText('Select All')).toBeInTheDocument();
  554. });
  555. // Click Select All to select both printers
  556. fireEvent.click(screen.getByText('Select All'));
  557. // Should show "2 selected"
  558. await waitFor(() => {
  559. expect(screen.getByText('2 selected')).toBeInTheDocument();
  560. });
  561. });
  562. it('shows select by state dropdown', async () => {
  563. render(<PrintersPage />);
  564. await waitFor(() => {
  565. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  566. });
  567. // Enter selection mode
  568. fireEvent.click(screen.getByTitle('Select'));
  569. await waitFor(() => {
  570. expect(screen.getByText('Select by State')).toBeInTheDocument();
  571. });
  572. });
  573. it('exits selection mode on close button', async () => {
  574. render(<PrintersPage />);
  575. await waitFor(() => {
  576. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  577. });
  578. // Enter selection mode
  579. fireEvent.click(screen.getByTitle('Select'));
  580. await waitFor(() => {
  581. expect(screen.getByText('Select All')).toBeInTheDocument();
  582. });
  583. // Click the Select button again to exit (it toggles)
  584. fireEvent.click(screen.getByTitle('Select'));
  585. // Floating toolbar should disappear
  586. await waitFor(() => {
  587. expect(screen.queryByText('Select All')).not.toBeInTheDocument();
  588. });
  589. });
  590. });
  591. describe('search and filter', () => {
  592. beforeEach(() => {
  593. server.use(
  594. http.get('/api/v1/printers/', () => HttpResponse.json(mockPrinters)),
  595. http.get('/api/v1/printers/:id/status', () => HttpResponse.json(mockPrinterStatus)),
  596. http.get('/api/v1/queue/', () => HttpResponse.json([]))
  597. );
  598. });
  599. it('filters by name (case-insensitive)', async () => {
  600. render(<PrintersPage />);
  601. await waitFor(() => expect(screen.getByText('X1 Carbon')).toBeInTheDocument());
  602. fireEvent.change(screen.getByPlaceholderText('Search printers...'), { target: { value: 'x1 carbon' } });
  603. await waitFor(() => {
  604. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  605. expect(screen.queryByText('P1S Backup')).not.toBeInTheDocument();
  606. });
  607. });
  608. it('trims leading and trailing whitespace from search', async () => {
  609. render(<PrintersPage />);
  610. await waitFor(() => expect(screen.getByText('X1 Carbon')).toBeInTheDocument());
  611. // " X1 Carbon " with surrounding spaces must still match
  612. fireEvent.change(screen.getByPlaceholderText('Search printers...'), { target: { value: ' X1 Carbon ' } });
  613. await waitFor(() => {
  614. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  615. expect(screen.queryByText('P1S Backup')).not.toBeInTheDocument();
  616. });
  617. });
  618. it('filters by model', async () => {
  619. render(<PrintersPage />);
  620. await waitFor(() => expect(screen.getByText('X1 Carbon')).toBeInTheDocument());
  621. fireEvent.change(screen.getByPlaceholderText('Search printers...'), { target: { value: 'P1S' } });
  622. await waitFor(() => {
  623. expect(screen.queryByText('X1 Carbon')).not.toBeInTheDocument();
  624. expect(screen.getByText('P1S Backup')).toBeInTheDocument();
  625. });
  626. });
  627. it('filters by serial number', async () => {
  628. render(<PrintersPage />);
  629. await waitFor(() => expect(screen.getByText('X1 Carbon')).toBeInTheDocument());
  630. fireEvent.change(screen.getByPlaceholderText('Search printers...'), { target: { value: '00M09A' } });
  631. await waitFor(() => {
  632. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  633. expect(screen.queryByText('P1S Backup')).not.toBeInTheDocument();
  634. });
  635. });
  636. it('shows empty state when no printers match search', async () => {
  637. render(<PrintersPage />);
  638. await waitFor(() => expect(screen.getByText('X1 Carbon')).toBeInTheDocument());
  639. fireEvent.change(screen.getByPlaceholderText('Search printers...'), { target: { value: 'ZZZ_NO_MATCH' } });
  640. await waitFor(() => {
  641. expect(screen.getByText('No printers match your search or filters')).toBeInTheDocument();
  642. });
  643. });
  644. it('clear button resets search and shows all printers', async () => {
  645. render(<PrintersPage />);
  646. await waitFor(() => expect(screen.getByText('X1 Carbon')).toBeInTheDocument());
  647. fireEvent.change(screen.getByPlaceholderText('Search printers...'), { target: { value: 'X1 Carbon' } });
  648. await waitFor(() => expect(screen.queryByText('P1S Backup')).not.toBeInTheDocument());
  649. // Click the accessible clear button
  650. fireEvent.click(screen.getByRole('button', { name: 'Clear' }));
  651. await waitFor(() => {
  652. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  653. expect(screen.getByText('P1S Backup')).toBeInTheDocument();
  654. });
  655. });
  656. it('filters by status (offline) via dropdown', async () => {
  657. // Override: printer 1 online, printer 2 offline
  658. server.use(
  659. http.get('/api/v1/printers/:id/status', ({ params }) => {
  660. if (Number(params.id) === 2) {
  661. return HttpResponse.json({ ...mockPrinterStatus, connected: false });
  662. }
  663. return HttpResponse.json(mockPrinterStatus);
  664. })
  665. );
  666. render(<PrintersPage />);
  667. await waitFor(() => expect(screen.getByText('X1 Carbon')).toBeInTheDocument());
  668. await selectToolbarDropdownOption(/all statuses/i, /^offline$/i);
  669. await waitFor(() => {
  670. expect(screen.queryByText('X1 Carbon')).not.toBeInTheDocument();
  671. expect(screen.getByText('P1S Backup')).toBeInTheDocument();
  672. });
  673. });
  674. it('shows empty state when status filter matches nothing', async () => {
  675. render(<PrintersPage />);
  676. await waitFor(() => expect(screen.getByText('X1 Carbon')).toBeInTheDocument());
  677. // Both printers are IDLE; filtering by "printing" should yield no results
  678. await selectToolbarDropdownOption(/all statuses/i, /^printing$/i);
  679. await waitFor(() => {
  680. expect(screen.getByText('No printers match your search or filters')).toBeInTheDocument();
  681. });
  682. });
  683. it('combines search and status filter', async () => {
  684. // Printer 1 = RUNNING (printing), printer 2 = IDLE
  685. server.use(
  686. http.get('/api/v1/printers/:id/status', ({ params }) => {
  687. if (Number(params.id) === 1) {
  688. return HttpResponse.json({ ...mockPrinterStatus, state: 'RUNNING' });
  689. }
  690. return HttpResponse.json(mockPrinterStatus);
  691. })
  692. );
  693. render(<PrintersPage />);
  694. await waitFor(() => expect(screen.getByText('X1 Carbon')).toBeInTheDocument());
  695. // Filter to only "printing" printers
  696. await selectToolbarDropdownOption(/all statuses/i, /^printing$/i);
  697. // Then also search for a term that only matches printer 1
  698. fireEvent.change(screen.getByPlaceholderText('Search printers...'), { target: { value: 'X1' } });
  699. await waitFor(() => {
  700. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  701. expect(screen.queryByText('P1S Backup')).not.toBeInTheDocument();
  702. });
  703. });
  704. it('filters by location via dropdown', async () => {
  705. // Override: give printer 2 its own location so the dropdown has two options
  706. // and we can verify the filter picks the right one. Printer 1 stays at 'Workshop'.
  707. server.use(
  708. http.get('/api/v1/printers/', () =>
  709. HttpResponse.json([
  710. mockPrinters[0],
  711. { ...mockPrinters[1], location: 'Office' },
  712. ])
  713. )
  714. );
  715. render(<PrintersPage />);
  716. await waitFor(() => {
  717. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  718. expect(screen.getByText('P1S Backup')).toBeInTheDocument();
  719. });
  720. await selectToolbarDropdownOption(/all locations/i, /^workshop$/i);
  721. await waitFor(() => {
  722. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  723. expect(screen.queryByText('P1S Backup')).not.toBeInTheDocument();
  724. });
  725. await selectToolbarDropdownOption(/^workshop$/i, /^office$/i);
  726. await waitFor(() => {
  727. expect(screen.queryByText('X1 Carbon')).not.toBeInTheDocument();
  728. expect(screen.getByText('P1S Backup')).toBeInTheDocument();
  729. });
  730. });
  731. it('hides location filter when no printers have a location', async () => {
  732. // Both printers have null location — dropdown should not render at all
  733. server.use(
  734. http.get('/api/v1/printers/', () =>
  735. HttpResponse.json([
  736. { ...mockPrinters[0], location: null },
  737. { ...mockPrinters[1], location: null },
  738. ])
  739. )
  740. );
  741. render(<PrintersPage />);
  742. await waitFor(() => expect(screen.getByText('X1 Carbon')).toBeInTheDocument());
  743. // Status filter is still there, but the location filter should be absent.
  744. expect(screen.getByRole('button', { name: /all statuses/i })).toBeInTheDocument();
  745. expect(screen.queryByRole('button', { name: /all locations/i })).not.toBeInTheDocument();
  746. });
  747. });
  748. describe('Spoolman loading guard', () => {
  749. it('does not show Assign Spool button while Spoolman queries are loading', async () => {
  750. // Spoolman enabled but inventory and slot-assignment queries never resolve
  751. server.use(
  752. http.get('/api/v1/spoolman/status', () =>
  753. HttpResponse.json({ enabled: true, connected: true })
  754. ),
  755. http.get('/api/v1/spoolman/inventory/spools', () =>
  756. new Promise(() => {}) // never resolves
  757. ),
  758. http.get('/api/v1/spoolman/inventory/slot-assignments/all', () =>
  759. new Promise(() => {}) // never resolves
  760. )
  761. );
  762. render(<PrintersPage />);
  763. // Wait for the page to render (printers should be visible)
  764. await waitFor(() => expect(screen.getByText('X1 Carbon')).toBeInTheDocument());
  765. // While Spoolman queries are still loading, the "Assign Spool" button must
  766. // not appear (inventory prop is undefined → {inventory && ...} guard fires)
  767. expect(screen.queryByText('Assign Spool')).not.toBeInTheDocument();
  768. });
  769. });
  770. });
  771. /**
  772. * Phase 13 P13-1 (PrintersPage EmptySlotHoverCard onAssignSpool gate removal)
  773. *
  774. * Pre-Phase-13 each of the three EmptySlotHoverCard call-sites in PrintersPage
  775. * gated `onAssignSpool` on `spoolmanEnabled ? (...) : undefined`, so empty
  776. * slots in local-Inventory mode never showed an Assign action. Maintainer
  777. * Foto 7 confirmed users expect the button regardless of mode.
  778. *
  779. * To assert wiring without going through hover-card animations, we mock the
  780. * EmptySlotHoverCard component at module level and capture every props
  781. * payload. The same mock is active in both modes; tests differ only in the
  782. * spoolman-settings mock. The mock module covers BOTH FilamentHoverCard exports
  783. * so tests outside this `describe` aren't affected (we re-export the real
  784. * FilamentHoverCard).
  785. */
  786. const phase13EmptySlotProps: Array<Record<string, unknown>> = [];
  787. const phase14HoverCardProps: Array<Record<string, unknown>> = [];
  788. vi.mock('../../components/FilamentHoverCard', async (importOriginal) => {
  789. const actual = await importOriginal<typeof import('../../components/FilamentHoverCard')>();
  790. return {
  791. ...actual,
  792. EmptySlotHoverCard: (props: Record<string, unknown>) => {
  793. phase13EmptySlotProps.push({ ...props });
  794. return null;
  795. },
  796. FilamentHoverCard: (props: Record<string, unknown>) => {
  797. phase14HoverCardProps.push({ ...props });
  798. return null;
  799. },
  800. };
  801. });
  802. describe('PrintersPage Phase 13 — EmptySlotHoverCard onAssignSpool wiring', () => {
  803. beforeEach(() => {
  804. phase13EmptySlotProps.length = 0;
  805. localStorage.removeItem('printerCardSize');
  806. server.use(
  807. http.get('/api/v1/printers/', () => HttpResponse.json(mockPrinters)),
  808. // Status response includes an empty AMS slot so EmptySlotHoverCard renders.
  809. http.get('/api/v1/printers/:id/status', () => HttpResponse.json({
  810. ...mockPrinterStatus,
  811. ams: [{
  812. id: 0,
  813. tray: [{ id: 0, tray_type: '' }],
  814. }],
  815. })),
  816. http.get('/api/v1/settings/', () => HttpResponse.json({
  817. auto_archive: true, save_thumbnails: true, capture_finish_photo: true,
  818. default_filament_cost: 25.0, currency: 'USD',
  819. ams_humidity_good: 40, ams_humidity_fair: 60,
  820. ams_temp_good: 30, ams_temp_fair: 35,
  821. })),
  822. http.get('/api/v1/queue/', () => HttpResponse.json([])),
  823. );
  824. });
  825. it('P13-1 (local mode): EmptySlotHoverCard receives onAssignSpool callback', async () => {
  826. server.use(
  827. http.get('/api/v1/spoolman/settings', () => HttpResponse.json({
  828. spoolman_enabled: 'false', spoolman_url: '',
  829. })),
  830. );
  831. render(<PrintersPage />);
  832. // Wait for printer status to load and at least one EmptySlotHoverCard
  833. // to mount with an onAssignSpool callback. Pre-Phase-13 this would have
  834. // been undefined in local mode (the gate filtered it out).
  835. await waitFor(() => {
  836. const withCallback = phase13EmptySlotProps.filter(p => typeof p.onAssignSpool === 'function');
  837. expect(withCallback.length).toBeGreaterThan(0);
  838. }, { timeout: 3000 });
  839. });
  840. it('P13-1 (spoolman mode): EmptySlotHoverCard still receives onAssignSpool callback', async () => {
  841. server.use(
  842. http.get('/api/v1/spoolman/settings', () => HttpResponse.json({
  843. spoolman_enabled: 'true', spoolman_url: 'http://x:7912',
  844. })),
  845. http.get('/api/v1/spoolman/spools/inventory*', () => HttpResponse.json([])),
  846. http.get('/api/v1/spoolman/inventory/spools', () => HttpResponse.json([])),
  847. http.get('/api/v1/spoolman/inventory/slot-assignments/all', () => HttpResponse.json([])),
  848. );
  849. render(<PrintersPage />);
  850. await waitFor(() => {
  851. const withCallback = phase13EmptySlotProps.filter(p => typeof p.onAssignSpool === 'function');
  852. expect(withCallback.length).toBeGreaterThan(0);
  853. }, { timeout: 3000 });
  854. });
  855. });
  856. /**
  857. * Phase 14 — Local-Branch BL-detection symmetry.
  858. *
  859. * The Spoolman branch of every IIFE in PrintersPage already passes
  860. * isAssigned: !!slotAssignment || isBambuLabSpool(tray)
  861. * onUnassignSpool: (spoolmanSpool && !isBambuLabSpool(tray)) ? ... : undefined
  862. *
  863. * The local branch was missing both. As a result a BL-RFID-tagged slot in
  864. * local-Inventory mode showed an "Assign Spool" button (because no manual
  865. * SpoolAssignment exists), and a manually-assigned BL-RFID slot showed
  866. * "Unassign" — which would be overwritten on the next RFID re-read.
  867. *
  868. * The same FilamentHoverCard mock from the Phase 13 block above captures
  869. * inventory props on every render so we can inspect them after setup.
  870. */
  871. describe('PrintersPage Phase 14 — Local-Branch BL-detection symmetry', () => {
  872. beforeEach(() => {
  873. phase14HoverCardProps.length = 0;
  874. localStorage.removeItem('printerCardSize');
  875. server.use(
  876. http.get('/api/v1/printers/', () => HttpResponse.json(mockPrinters)),
  877. http.get('/api/v1/settings/', () => HttpResponse.json({
  878. auto_archive: true, save_thumbnails: true, capture_finish_photo: true,
  879. default_filament_cost: 25.0, currency: 'USD',
  880. ams_humidity_good: 40, ams_humidity_fair: 60,
  881. ams_temp_good: 30, ams_temp_fair: 35,
  882. })),
  883. http.get('/api/v1/queue/', () => HttpResponse.json([])),
  884. http.get('/api/v1/spoolman/settings', () => HttpResponse.json({
  885. spoolman_enabled: 'false', spoolman_url: '',
  886. })),
  887. );
  888. });
  889. it('P14-1a (local + BL-RFID + no assignment): inventory.isAssigned=true', async () => {
  890. server.use(
  891. http.get('/api/v1/printers/:id/status', () => HttpResponse.json({
  892. ...mockPrinterStatus,
  893. ams: [{
  894. id: 0,
  895. tray: [{
  896. id: 0,
  897. tray_type: 'PLA',
  898. tray_uuid: '11223344556677880011223344556677',
  899. tag_uid: '0000000000000000',
  900. tray_color: 'FF0000FF',
  901. tray_sub_brands: 'Bambu PLA Basic',
  902. }],
  903. }],
  904. })),
  905. http.get('/api/v1/inventory/assignments', () => HttpResponse.json([])),
  906. );
  907. render(<PrintersPage />);
  908. await waitFor(() => {
  909. const matches = phase14HoverCardProps.filter(
  910. p => (p.inventory as { isAssigned?: boolean } | undefined)?.isAssigned === true
  911. );
  912. expect(matches.length).toBeGreaterThan(0);
  913. }, { timeout: 3000 });
  914. });
  915. it('P14-1b (local + non-BL + no assignment): inventory.isAssigned is falsy', async () => {
  916. server.use(
  917. http.get('/api/v1/printers/:id/status', () => HttpResponse.json({
  918. ...mockPrinterStatus,
  919. ams: [{
  920. id: 0,
  921. tray: [{
  922. id: 0,
  923. tray_type: 'PLA',
  924. tray_uuid: '00000000000000000000000000000000',
  925. tag_uid: '0000000000000000',
  926. tray_color: 'FF0000FF',
  927. tray_sub_brands: 'Generic PLA',
  928. }],
  929. }],
  930. })),
  931. http.get('/api/v1/inventory/assignments', () => HttpResponse.json([])),
  932. );
  933. render(<PrintersPage />);
  934. // Wait for FilamentHoverCard to render at least once.
  935. await waitFor(() => {
  936. expect(phase14HoverCardProps.length).toBeGreaterThan(0);
  937. }, { timeout: 3000 });
  938. // No render should ever set isAssigned=true for this slot.
  939. const truthyMatches = phase14HoverCardProps.filter(
  940. p => (p.inventory as { isAssigned?: boolean } | undefined)?.isAssigned === true
  941. );
  942. expect(truthyMatches.length).toBe(0);
  943. });
  944. it('P14-1c (local + manual assignment): inventory.isAssigned=true', async () => {
  945. server.use(
  946. http.get('/api/v1/printers/:id/status', () => HttpResponse.json({
  947. ...mockPrinterStatus,
  948. ams: [{
  949. id: 0,
  950. tray: [{
  951. id: 0,
  952. tray_type: 'PLA',
  953. tray_uuid: '00000000000000000000000000000000',
  954. tag_uid: '0000000000000000',
  955. tray_color: 'FF0000FF',
  956. tray_sub_brands: 'Generic PLA',
  957. }],
  958. }],
  959. })),
  960. http.get('/api/v1/inventory/assignments', () => HttpResponse.json([
  961. {
  962. id: 1,
  963. spool_id: 42,
  964. printer_id: 1,
  965. ams_id: 0,
  966. tray_id: 0,
  967. printer_name: 'X1 Carbon',
  968. ams_label: null,
  969. spool: {
  970. id: 42,
  971. material: 'PLA',
  972. brand: 'Generic',
  973. color_name: 'Red',
  974. label_weight: 1000,
  975. weight_used: 0,
  976. rgba: 'FF0000FF',
  977. },
  978. },
  979. ])),
  980. );
  981. render(<PrintersPage />);
  982. await waitFor(() => {
  983. const matches = phase14HoverCardProps.filter(
  984. p => (p.inventory as { isAssigned?: boolean } | undefined)?.isAssigned === true
  985. );
  986. expect(matches.length).toBeGreaterThan(0);
  987. }, { timeout: 3000 });
  988. });
  989. it('P14-2 (local + BL-RFID + manual assignment): onUnassignSpool=undefined', async () => {
  990. server.use(
  991. http.get('/api/v1/printers/:id/status', () => HttpResponse.json({
  992. ...mockPrinterStatus,
  993. ams: [{
  994. id: 0,
  995. tray: [{
  996. id: 0,
  997. tray_type: 'PLA',
  998. tray_uuid: '11223344556677880011223344556677',
  999. tag_uid: '0000000000000000',
  1000. tray_color: 'FF0000FF',
  1001. tray_sub_brands: 'Bambu PLA Basic',
  1002. }],
  1003. }],
  1004. })),
  1005. http.get('/api/v1/inventory/assignments', () => HttpResponse.json([
  1006. {
  1007. id: 1,
  1008. spool_id: 42,
  1009. printer_id: 1,
  1010. ams_id: 0,
  1011. tray_id: 0,
  1012. printer_name: 'X1 Carbon',
  1013. ams_label: null,
  1014. spool: {
  1015. id: 42,
  1016. material: 'PLA',
  1017. brand: 'Bambu Lab',
  1018. color_name: 'Red',
  1019. label_weight: 1000,
  1020. weight_used: 0,
  1021. rgba: 'FF0000FF',
  1022. },
  1023. },
  1024. ])),
  1025. );
  1026. render(<PrintersPage />);
  1027. // Wait for FilamentHoverCard renders to settle.
  1028. await waitFor(() => {
  1029. expect(phase14HoverCardProps.length).toBeGreaterThan(0);
  1030. }, { timeout: 3000 });
  1031. // For BL-detected slots in local mode, onUnassignSpool must always be
  1032. // undefined — even when a manual assignment exists. Otherwise the user
  1033. // could unassign a BL-RFID slot that the printer would re-assign on the
  1034. // next re-read, surprising them with phantom ghost-assignments.
  1035. const definedUnassign = phase14HoverCardProps.filter(
  1036. p => typeof (p.inventory as { onUnassignSpool?: () => void } | undefined)?.onUnassignSpool === 'function'
  1037. );
  1038. expect(definedUnassign.length).toBe(0);
  1039. });
  1040. });