PrintersPage.test.tsx 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715
  1. /**
  2. * Tests for the PrintersPage component.
  3. */
  4. import { describe, it, expect, beforeEach } from 'vitest';
  5. import { screen, waitFor, fireEvent, within } 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. is_active: true,
  21. nozzle_diameter: 0.4,
  22. nozzle_type: 'hardened_steel',
  23. location: 'Workshop',
  24. auto_archive: true,
  25. created_at: '2024-01-01T00:00:00Z',
  26. updated_at: '2024-01-01T00:00:00Z',
  27. },
  28. {
  29. id: 2,
  30. name: 'P1S Backup',
  31. ip_address: '192.168.1.101',
  32. serial_number: '00W00A123456789',
  33. access_code: '87654321',
  34. model: 'P1S',
  35. enabled: false,
  36. is_active: true,
  37. nozzle_diameter: 0.4,
  38. nozzle_type: 'stainless_steel',
  39. location: null,
  40. auto_archive: true,
  41. created_at: '2024-01-02T00:00:00Z',
  42. updated_at: '2024-01-02T00:00:00Z',
  43. },
  44. ];
  45. const mockPrinterStatus = {
  46. connected: true,
  47. state: 'IDLE',
  48. awaiting_plate_clear: false,
  49. progress: 0,
  50. layer_num: 0,
  51. total_layers: 0,
  52. temperatures: {
  53. nozzle: 25,
  54. bed: 25,
  55. chamber: 25,
  56. },
  57. remaining_time: 0,
  58. filename: null,
  59. wifi_signal: -50,
  60. vt_tray: [],
  61. };
  62. const selectToolbarDropdownOption = async (triggerName: RegExp, optionName: RegExp) => {
  63. const user = userEvent.setup();
  64. await user.click(screen.getByRole('button', { name: triggerName }));
  65. await user.click(await screen.findByRole('button', { name: optionName }));
  66. };
  67. describe('PrintersPage', () => {
  68. beforeEach(() => {
  69. localStorage.removeItem('printerCardSize');
  70. server.use(
  71. http.get('/api/v1/printers/', () => {
  72. return HttpResponse.json(mockPrinters);
  73. }),
  74. http.get('/api/v1/printers/:id/status', () => {
  75. return HttpResponse.json(mockPrinterStatus);
  76. }),
  77. http.post('/api/v1/printers/:id/clear-plate', () => {
  78. return HttpResponse.json({ success: true, message: 'Plate cleared' });
  79. }),
  80. http.get('/api/v1/settings/', () => {
  81. return HttpResponse.json({
  82. auto_archive: true,
  83. save_thumbnails: true,
  84. capture_finish_photo: true,
  85. default_filament_cost: 25.0,
  86. currency: 'USD',
  87. ams_humidity_good: 40,
  88. ams_humidity_fair: 60,
  89. ams_temp_good: 30,
  90. ams_temp_fair: 35,
  91. require_plate_clear: true,
  92. });
  93. }),
  94. // PrintersPage now reads UI rendering fields from the public ui-preferences
  95. // endpoint instead of /settings (#1293) — admin pages still hit /settings.
  96. http.get('/api/v1/settings/ui-preferences', () => {
  97. return HttpResponse.json({
  98. ams_humidity_good: 40,
  99. ams_humidity_fair: 60,
  100. ams_temp_good: 30,
  101. ams_temp_fair: 35,
  102. require_plate_clear: true,
  103. });
  104. }),
  105. http.get('/api/v1/queue/', () => {
  106. return HttpResponse.json([]);
  107. })
  108. );
  109. });
  110. describe('rendering', () => {
  111. it('renders the page title', async () => {
  112. render(<PrintersPage />);
  113. await waitFor(() => {
  114. expect(screen.getByText('Printers')).toBeInTheDocument();
  115. });
  116. });
  117. it('shows printer cards', async () => {
  118. render(<PrintersPage />);
  119. await waitFor(() => {
  120. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  121. expect(screen.getByText('P1S Backup')).toBeInTheDocument();
  122. });
  123. });
  124. it('shows printer models', async () => {
  125. render(<PrintersPage />);
  126. await waitFor(() => {
  127. expect(screen.getByText('X1C')).toBeInTheDocument();
  128. expect(screen.getByText('P1S')).toBeInTheDocument();
  129. });
  130. });
  131. it('shows printer status', async () => {
  132. render(<PrintersPage />);
  133. await waitFor(() => {
  134. // Status should be shown - may vary based on state
  135. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  136. });
  137. });
  138. it('offers FTP file browsing when MQTT status is offline', async () => {
  139. server.use(
  140. http.get('/api/v1/printers/:id/status', () => {
  141. return HttpResponse.json({ ...mockPrinterStatus, connected: false });
  142. }),
  143. );
  144. render(<PrintersPage />);
  145. const browseButtons = await screen.findAllByRole('button', { name: /browse printer files/i });
  146. expect(browseButtons).toHaveLength(mockPrinters.length);
  147. await userEvent.click(browseButtons[0]);
  148. expect(await screen.findByText('File Manager')).toBeInTheDocument();
  149. });
  150. });
  151. describe('printer info', () => {
  152. it('shows IP address in printer info modal', async () => {
  153. render(<PrintersPage />);
  154. await waitFor(() => {
  155. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  156. });
  157. // IP address is shown in the PrinterInfoModal (accessed via 3-dot menu),
  158. // not directly on the card. Verify the printer data loaded correctly.
  159. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  160. });
  161. it('shows location when set', async () => {
  162. render(<PrintersPage />);
  163. await waitFor(() => {
  164. // Printers should render - location display may vary
  165. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  166. });
  167. });
  168. });
  169. describe('temperature display', () => {
  170. it('shows nozzle temperature', async () => {
  171. render(<PrintersPage />);
  172. await waitFor(() => {
  173. // Temperatures are shown in the UI
  174. expect(screen.getAllByText(/25/)).toBeTruthy();
  175. });
  176. });
  177. it('sets left and right nozzle temperatures from the nozzle selector', async () => {
  178. localStorage.setItem('printerCardSize', '2');
  179. const temperatureRequests: Array<{ target: string | null; nozzle: string | null }> = [];
  180. const dualNozzlePrinter = { ...mockPrinters[0], model: 'H2D', nozzle_count: 2 };
  181. const dualNozzleStatus = {
  182. ...mockPrinterStatus,
  183. active_extruder: 0,
  184. temperatures: {
  185. ...mockPrinterStatus.temperatures,
  186. nozzle: 31,
  187. nozzle_target: 0,
  188. nozzle_2: 32,
  189. nozzle_2_target: 0,
  190. },
  191. nozzle_rack: [
  192. { id: 0, nozzle_type: 'HS', nozzle_diameter: '0.4', wear: 5, stat: 1, max_temp: 300, serial_number: '', filament_color: '', filament_id: '', filament_type: '' },
  193. { id: 1, nozzle_type: 'HS', nozzle_diameter: '0.4', wear: 3, stat: 1, max_temp: 300, serial_number: '', filament_color: '', filament_id: '', filament_type: '' },
  194. ],
  195. };
  196. server.use(
  197. http.get('/api/v1/printers/', () => HttpResponse.json([dualNozzlePrinter])),
  198. http.get('/api/v1/printers/:id/status', () => HttpResponse.json(dualNozzleStatus)),
  199. http.post('/api/v1/printers/:id/temperature/nozzle', ({ request }) => {
  200. const url = new URL(request.url);
  201. temperatureRequests.push({
  202. target: url.searchParams.get('target'),
  203. nozzle: url.searchParams.get('nozzle'),
  204. });
  205. return HttpResponse.json({ success: true, message: 'Nozzle temperature set' });
  206. })
  207. );
  208. render(<PrintersPage />);
  209. await waitFor(() => {
  210. expect(screen.getByText('L / R')).toBeInTheDocument();
  211. });
  212. // Dual-nozzle temps live on the L/R temperature card, not the nozzle-select card.
  213. fireEvent.click(screen.getByText('L / R').parentElement!);
  214. const leftTempBox = screen.getByText('Left Temp').parentElement!.parentElement!;
  215. fireEvent.click(within(leftTempBox).getByRole('button', { name: '220 C' }));
  216. await waitFor(() => {
  217. expect(temperatureRequests).toContainEqual({ target: '220', nozzle: '1' });
  218. });
  219. fireEvent.click(screen.getByText('L / R').parentElement!);
  220. const rightTempBox = screen.getByText('Right Temp').parentElement!.parentElement!;
  221. fireEvent.click(within(rightTempBox).getByRole('button', { name: '260 C' }));
  222. await waitFor(() => {
  223. expect(temperatureRequests).toContainEqual({ target: '260', nozzle: '0' });
  224. });
  225. });
  226. });
  227. describe('fan badges', () => {
  228. // Chamber fan only exists on enclosed Bambu models. Open-frame printers
  229. // (A1, A1 Mini, A2L, P1P) have no chamber fan — the firmware reports
  230. // big_fan2_speed as 0 there and the widget would be dead UI.
  231. const statusWithFans = {
  232. ...mockPrinterStatus,
  233. cooling_fan_speed: 53,
  234. big_fan1_speed: 53,
  235. big_fan2_speed: 53,
  236. };
  237. const renderWithPrinter = (printer: typeof mockPrinters[number]) => {
  238. server.use(
  239. http.get('/api/v1/printers/', () => HttpResponse.json([printer])),
  240. http.get('/api/v1/printers/:id/status', () => HttpResponse.json(statusWithFans)),
  241. );
  242. render(<PrintersPage />);
  243. };
  244. it('hides chamber fan badge on A1 Mini (open-frame, no chamber fan)', async () => {
  245. renderWithPrinter({ ...mockPrinters[0], model: 'A1 Mini' });
  246. await waitFor(() => {
  247. // Part-cooling badge confirms the fan row rendered.
  248. expect(screen.getByTitle('Part Cooling Fan')).toBeInTheDocument();
  249. });
  250. expect(screen.getByTitle('Auxiliary Fan')).toBeInTheDocument();
  251. expect(screen.queryByTitle('Chamber Fan')).not.toBeInTheDocument();
  252. });
  253. it('hides chamber fan badge on A1 (open-frame)', async () => {
  254. renderWithPrinter({ ...mockPrinters[0], model: 'A1' });
  255. await waitFor(() => {
  256. expect(screen.getByTitle('Part Cooling Fan')).toBeInTheDocument();
  257. });
  258. expect(screen.queryByTitle('Chamber Fan')).not.toBeInTheDocument();
  259. });
  260. it('hides chamber fan badge on P1P (open-frame)', async () => {
  261. renderWithPrinter({ ...mockPrinters[0], model: 'P1P' });
  262. await waitFor(() => {
  263. expect(screen.getByTitle('Part Cooling Fan')).toBeInTheDocument();
  264. });
  265. expect(screen.queryByTitle('Chamber Fan')).not.toBeInTheDocument();
  266. });
  267. it('shows chamber fan badge on X1C (enclosed)', async () => {
  268. renderWithPrinter({ ...mockPrinters[0], model: 'X1C' });
  269. await waitFor(() => {
  270. expect(screen.getByTitle('Chamber Fan')).toBeInTheDocument();
  271. });
  272. expect(screen.getByTitle('Part Cooling Fan')).toBeInTheDocument();
  273. expect(screen.getByTitle('Auxiliary Fan')).toBeInTheDocument();
  274. });
  275. it('shows chamber fan badge on P1S (enclosed)', async () => {
  276. renderWithPrinter({ ...mockPrinters[0], model: 'P1S' });
  277. await waitFor(() => {
  278. expect(screen.getByTitle('Chamber Fan')).toBeInTheDocument();
  279. });
  280. });
  281. // P2S/X2D left auxiliary part cooling fan (airduct part id 10) — optional
  282. // hardware, so the badge must only appear when the firmware reports it.
  283. const renderWithStatus = (
  284. printer: typeof mockPrinters[number],
  285. status: Record<string, unknown>,
  286. ) => {
  287. server.use(
  288. http.get('/api/v1/printers/', () => HttpResponse.json([printer])),
  289. http.get('/api/v1/printers/:id/status', () => HttpResponse.json(status)),
  290. );
  291. render(<PrintersPage />);
  292. };
  293. it('shows the exhaust tile labeled "Exhaust" on P2S when the kit is present', async () => {
  294. // Exhaust fan is an add-on kit; the tile appears only when the printer
  295. // reports it (airduct part id 3 -> exhaust_fan_present).
  296. renderWithStatus(
  297. { ...mockPrinters[0], model: 'P2S' },
  298. { ...statusWithFans, exhaust_fan_present: true },
  299. );
  300. await waitFor(() => {
  301. expect(screen.getByTitle('Part Cooling Fan')).toBeInTheDocument();
  302. });
  303. expect(screen.getByTitle('Exhaust')).toBeInTheDocument();
  304. expect(screen.queryByTitle('Chamber Fan')).not.toBeInTheDocument();
  305. });
  306. it('hides the exhaust tile on a base P2S without the kit', async () => {
  307. renderWithStatus(
  308. { ...mockPrinters[0], model: 'P2S' },
  309. { ...statusWithFans, exhaust_fan_present: false },
  310. );
  311. await waitFor(() => {
  312. expect(screen.getByTitle('Part Cooling Fan')).toBeInTheDocument();
  313. });
  314. expect(screen.queryByTitle('Exhaust')).not.toBeInTheDocument();
  315. expect(screen.queryByTitle('Chamber Fan')).not.toBeInTheDocument();
  316. });
  317. it('keeps the always-on "Chamber Fan" tile on X1C regardless of exhaust_fan_present', async () => {
  318. renderWithStatus(
  319. { ...mockPrinters[0], model: 'X1C' },
  320. { ...statusWithFans, exhaust_fan_present: false },
  321. );
  322. await waitFor(() => {
  323. expect(screen.getByTitle('Chamber Fan')).toBeInTheDocument();
  324. });
  325. expect(screen.queryByTitle('Exhaust')).not.toBeInTheDocument();
  326. });
  327. it('hides the left aux badge when the accessory is not reported', async () => {
  328. renderWithStatus({ ...mockPrinters[0], model: 'P2S' }, statusWithFans);
  329. await waitFor(() => {
  330. expect(screen.getByTitle('Part Cooling Fan')).toBeInTheDocument();
  331. });
  332. expect(screen.queryByTitle('Left Auxiliary Fan')).not.toBeInTheDocument();
  333. });
  334. it('orders the fan badges left-to-right: part, left aux, aux, exhaust', async () => {
  335. // The two aux badges should read in the same order as the physical
  336. // hardware, so the left fan sits before the right one.
  337. renderWithStatus(
  338. { ...mockPrinters[0], model: 'P2S' },
  339. { ...statusWithFans, left_aux_fan_speed: 80, exhaust_fan_present: true },
  340. );
  341. await waitFor(() => {
  342. expect(screen.getByTitle('Left Auxiliary Fan')).toBeInTheDocument();
  343. });
  344. const order = ['Part Cooling Fan', 'Left Auxiliary Fan', 'Auxiliary Fan', 'Exhaust'].map(
  345. (title) => screen.getByTitle(title),
  346. );
  347. for (let i = 1; i < order.length; i++) {
  348. // Node.compareDocumentPosition returns FOLLOWING (4) when the argument
  349. // comes after the reference node in document order.
  350. expect(order[i - 1].compareDocumentPosition(order[i])).toBe(Node.DOCUMENT_POSITION_FOLLOWING);
  351. }
  352. });
  353. it('shows left aux fan badge when the accessory is installed (P2S)', async () => {
  354. renderWithStatus(
  355. { ...mockPrinters[0], model: 'P2S' },
  356. { ...statusWithFans, left_aux_fan_speed: 80 },
  357. );
  358. await waitFor(() => {
  359. expect(screen.getByTitle('Left Auxiliary Fan')).toBeInTheDocument();
  360. });
  361. });
  362. it('shows left aux fan badge even at 0% while installed', async () => {
  363. renderWithStatus(
  364. { ...mockPrinters[0], model: 'P2S' },
  365. { ...statusWithFans, left_aux_fan_speed: 0 },
  366. );
  367. await waitFor(() => {
  368. expect(screen.getByTitle('Left Auxiliary Fan')).toBeInTheDocument();
  369. });
  370. });
  371. });
  372. describe('empty state', () => {
  373. it('shows empty state when no printers', async () => {
  374. server.use(
  375. http.get('/api/v1/printers/', () => {
  376. return HttpResponse.json([]);
  377. })
  378. );
  379. render(<PrintersPage />);
  380. await waitFor(() => {
  381. expect(screen.getByText(/no printers/i)).toBeInTheDocument();
  382. });
  383. });
  384. });
  385. describe('printer actions', () => {
  386. it('has action buttons', async () => {
  387. render(<PrintersPage />);
  388. await waitFor(() => {
  389. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  390. });
  391. // There should be some interactive elements for printer actions
  392. const buttons = screen.getAllByRole('button');
  393. expect(buttons.length).toBeGreaterThan(0);
  394. });
  395. it('shows plate clear status and action on finished printers when not cleared', async () => {
  396. server.use(
  397. http.get('/api/v1/printers/:id/status', () => {
  398. return HttpResponse.json({ ...mockPrinterStatus, state: 'FINISH', awaiting_plate_clear: true });
  399. })
  400. );
  401. render(<PrintersPage />);
  402. await waitFor(() => {
  403. expect(screen.getAllByText('Plate not Clear').length).toBeGreaterThan(0);
  404. });
  405. expect(screen.getAllByRole('button', { name: 'Mark plate as cleared' }).length).toBeGreaterThan(0);
  406. });
  407. it('shows plate clear status and action on failed printers when not cleared', async () => {
  408. server.use(
  409. http.get('/api/v1/printers/:id/status', () => {
  410. return HttpResponse.json({ ...mockPrinterStatus, state: 'FAILED', awaiting_plate_clear: true });
  411. })
  412. );
  413. render(<PrintersPage />);
  414. await waitFor(() => {
  415. expect(screen.getAllByText('Plate not Clear').length).toBeGreaterThan(0);
  416. });
  417. expect(screen.getAllByRole('button', { name: 'Mark plate as cleared' }).length).toBeGreaterThan(0);
  418. });
  419. it('keeps the clear action available when an idle printer is still awaiting acknowledgment', async () => {
  420. server.use(
  421. http.get('/api/v1/printers/:id/status', () => {
  422. return HttpResponse.json({ ...mockPrinterStatus, state: 'IDLE', awaiting_plate_clear: true });
  423. })
  424. );
  425. render(<PrintersPage />);
  426. await waitFor(() => {
  427. expect(screen.getAllByText('Plate not Clear').length).toBeGreaterThan(0);
  428. });
  429. expect(screen.getAllByRole('button', { name: 'Mark plate as cleared' }).length).toBeGreaterThan(0);
  430. });
  431. it('offers the clear action on a powered-down printer (#2864)', async () => {
  432. // Auto Power Off leaves exactly this: gate up, printer unreachable. The
  433. // control used to be hidden here, so a plate cleared by hand could not be
  434. // acknowledged until the printer was powered back on.
  435. let awaitingPlateClear = true;
  436. let cleared = false;
  437. server.use(
  438. http.get('/api/v1/printers/', () => {
  439. return HttpResponse.json([mockPrinters[0]]);
  440. }),
  441. http.get('/api/v1/printers/:id/status', () => {
  442. return HttpResponse.json({
  443. ...mockPrinterStatus,
  444. connected: false,
  445. state: 'unknown',
  446. awaiting_plate_clear: awaitingPlateClear,
  447. });
  448. }),
  449. http.post('/api/v1/printers/:id/clear-plate', () => {
  450. cleared = true;
  451. awaitingPlateClear = false;
  452. return HttpResponse.json({ success: true, message: 'Plate cleared' });
  453. })
  454. );
  455. render(<PrintersPage />);
  456. const clearButton = await screen.findByRole('button', { name: 'Mark plate as cleared' });
  457. fireEvent.click(clearButton);
  458. await waitFor(() => {
  459. expect(cleared).toBe(true);
  460. });
  461. await waitFor(() => {
  462. expect(screen.queryByRole('button', { name: 'Mark plate as cleared' })).not.toBeInTheDocument();
  463. });
  464. });
  465. it('updates the plate clear status after using the printer card action', async () => {
  466. let awaitingPlateClear = true;
  467. server.use(
  468. http.get('/api/v1/printers/', () => {
  469. return HttpResponse.json([mockPrinters[0]]);
  470. }),
  471. http.get('/api/v1/printers/:id/status', () => {
  472. return HttpResponse.json({ ...mockPrinterStatus, state: 'FINISH', awaiting_plate_clear: awaitingPlateClear });
  473. }),
  474. http.post('/api/v1/printers/:id/clear-plate', () => {
  475. awaitingPlateClear = false;
  476. return HttpResponse.json({ success: true, message: 'Plate cleared' });
  477. })
  478. );
  479. render(<PrintersPage />);
  480. await waitFor(() => {
  481. expect(screen.getAllByText('Plate not Clear').length).toBeGreaterThan(0);
  482. });
  483. fireEvent.click(screen.getAllByRole('button', { name: 'Mark plate as cleared' })[0]);
  484. await waitFor(() => {
  485. expect(screen.queryByText('Plate not Clear')).not.toBeInTheDocument();
  486. });
  487. expect(screen.getAllByText('Plate Clear').length).toBeGreaterThan(0);
  488. });
  489. it('shows an icon-only plate clear action in small card view', async () => {
  490. let awaitingPlateClear = true;
  491. server.use(
  492. http.get('/api/v1/printers/', () => {
  493. return HttpResponse.json([mockPrinters[0]]);
  494. }),
  495. http.get('/api/v1/printers/:id/status', () => {
  496. return HttpResponse.json({ ...mockPrinterStatus, state: 'FINISH', awaiting_plate_clear: awaitingPlateClear });
  497. }),
  498. http.post('/api/v1/printers/:id/clear-plate', () => {
  499. awaitingPlateClear = false;
  500. return HttpResponse.json({ success: true, message: 'Plate cleared' });
  501. })
  502. );
  503. render(<PrintersPage />);
  504. await waitFor(() => {
  505. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  506. });
  507. fireEvent.click(screen.getByRole('button', { name: 'S' }));
  508. await waitFor(() => {
  509. expect(screen.queryByText('Mark plate as cleared')).not.toBeInTheDocument();
  510. });
  511. const clearButton = screen.getByRole('button', { name: 'Mark plate as cleared' });
  512. fireEvent.click(clearButton);
  513. await waitFor(() => {
  514. expect(screen.queryByRole('button', { name: 'Mark plate as cleared' })).not.toBeInTheDocument();
  515. });
  516. });
  517. it('shows plate clear status but no action while idle', async () => {
  518. render(<PrintersPage />);
  519. await waitFor(() => {
  520. expect(screen.getAllByText('Plate Clear').length).toBeGreaterThan(0);
  521. });
  522. expect(screen.queryByRole('button', { name: 'Mark plate as cleared' })).not.toBeInTheDocument();
  523. });
  524. it('shows plate in use status while printing and hides the clear action', async () => {
  525. server.use(
  526. http.get('/api/v1/printers/:id/status', () => {
  527. return HttpResponse.json({ ...mockPrinterStatus, state: 'RUNNING', awaiting_plate_clear: false });
  528. })
  529. );
  530. render(<PrintersPage />);
  531. await waitFor(() => {
  532. expect(screen.getAllByText('Plate in Use').length).toBeGreaterThan(0);
  533. });
  534. expect(screen.queryByRole('button', { name: 'Mark plate as cleared' })).not.toBeInTheDocument();
  535. });
  536. it('hides plate status and action when plate-clear confirmation is disabled', async () => {
  537. server.use(
  538. http.get('/api/v1/settings/', () => {
  539. return HttpResponse.json({
  540. auto_archive: true,
  541. save_thumbnails: true,
  542. capture_finish_photo: true,
  543. default_filament_cost: 25.0,
  544. currency: 'USD',
  545. ams_humidity_good: 40,
  546. ams_humidity_fair: 60,
  547. ams_temp_good: 30,
  548. ams_temp_fair: 35,
  549. require_plate_clear: false,
  550. });
  551. }),
  552. http.get('/api/v1/settings/ui-preferences', () => {
  553. return HttpResponse.json({
  554. ams_humidity_good: 40,
  555. ams_humidity_fair: 60,
  556. ams_temp_good: 30,
  557. ams_temp_fair: 35,
  558. require_plate_clear: false,
  559. });
  560. }),
  561. http.get('/api/v1/printers/:id/status', () => {
  562. return HttpResponse.json({ ...mockPrinterStatus, state: 'FINISH', awaiting_plate_clear: true });
  563. })
  564. );
  565. render(<PrintersPage />);
  566. await waitFor(() => {
  567. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  568. });
  569. expect(screen.queryByText('Plate not Clear')).not.toBeInTheDocument();
  570. expect(screen.queryByText('Plate Clear')).not.toBeInTheDocument();
  571. expect(screen.queryByText('Plate in Use')).not.toBeInTheDocument();
  572. expect(screen.queryByRole('button', { name: 'Mark plate as cleared' })).not.toBeInTheDocument();
  573. });
  574. });
  575. describe('disabled printer', () => {
  576. it('shows disabled state for disabled printers', async () => {
  577. render(<PrintersPage />);
  578. await waitFor(() => {
  579. expect(screen.getByText('P1S Backup')).toBeInTheDocument();
  580. });
  581. // Disabled printers have visual indication
  582. const disabledPrinter = screen.getByText('P1S Backup').closest('div');
  583. expect(disabledPrinter).toBeInTheDocument();
  584. });
  585. });
  586. describe('maintenance mode (#1476)', () => {
  587. // Wraps the backend is_active flag — already gates MQTT, queue dispatch,
  588. // scheduler, metrics, picker. These tests pin the UI surface: status
  589. // panel swap, pill swap, and the PATCH on toggle.
  590. const inMaintenancePrinter = { ...mockPrinters[0], is_active: false };
  591. it('shows the maintenance status panel instead of the print container', async () => {
  592. server.use(
  593. http.get('/api/v1/printers/', () => HttpResponse.json([inMaintenancePrinter])),
  594. http.get('/api/v1/printers/:id/status', () =>
  595. HttpResponse.json({ ...mockPrinterStatus, connected: false }),
  596. ),
  597. );
  598. render(<PrintersPage />);
  599. await waitFor(() => {
  600. expect(screen.getByText('In Maintenance')).toBeInTheDocument();
  601. });
  602. // Exit button rendered
  603. expect(screen.getByRole('button', { name: /exit maintenance/i })).toBeInTheDocument();
  604. // The "No active job" / "Ready to print" copy from the normal status
  605. // panel must NOT be present — confirms the swap, not a stacked render.
  606. expect(screen.queryByText(/no active job/i)).not.toBeInTheDocument();
  607. expect(screen.queryByText(/ready to print/i)).not.toBeInTheDocument();
  608. });
  609. it('shows the amber Maintenance pill in the header (no Connected/Offline)', async () => {
  610. server.use(
  611. http.get('/api/v1/printers/', () => HttpResponse.json([inMaintenancePrinter])),
  612. http.get('/api/v1/printers/:id/status', () =>
  613. HttpResponse.json({ ...mockPrinterStatus, connected: false }),
  614. ),
  615. );
  616. render(<PrintersPage />);
  617. // The header pill row contains "Maintenance" exactly once.
  618. await waitFor(() => {
  619. expect(screen.getAllByText('Maintenance').length).toBeGreaterThan(0);
  620. });
  621. // No connection diagnostic CTA (that's reserved for involuntary offline).
  622. expect(screen.queryByRole('button', { name: /run.*diagnostic/i })).not.toBeInTheDocument();
  623. });
  624. it('PATCHes is_active=true when the Exit button is clicked', async () => {
  625. const patchedBodies: unknown[] = [];
  626. server.use(
  627. http.get('/api/v1/printers/', () => HttpResponse.json([inMaintenancePrinter])),
  628. http.get('/api/v1/printers/:id/status', () =>
  629. HttpResponse.json({ ...mockPrinterStatus, connected: false }),
  630. ),
  631. http.patch('/api/v1/printers/:id', async ({ request }) => {
  632. const body = await request.json();
  633. patchedBodies.push(body);
  634. return HttpResponse.json({ ...inMaintenancePrinter, is_active: true });
  635. }),
  636. );
  637. render(<PrintersPage />);
  638. const exit = await screen.findByRole('button', { name: /exit maintenance/i });
  639. fireEvent.click(exit);
  640. await waitFor(() => {
  641. expect(patchedBodies.length).toBeGreaterThan(0);
  642. });
  643. expect(patchedBodies[0]).toEqual(expect.objectContaining({ is_active: true }));
  644. });
  645. it('renders the regular status panel when is_active=true', async () => {
  646. server.use(
  647. http.get('/api/v1/printers/', () => HttpResponse.json([{ ...mockPrinters[0], is_active: true }])),
  648. http.get('/api/v1/printers/:id/status', () => HttpResponse.json(mockPrinterStatus)),
  649. );
  650. render(<PrintersPage />);
  651. await waitFor(() => {
  652. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  653. });
  654. // Active printer never shows the maintenance panel.
  655. expect(screen.queryByText('In Maintenance')).not.toBeInTheDocument();
  656. expect(screen.queryByRole('button', { name: /exit maintenance/i })).not.toBeInTheDocument();
  657. });
  658. });
  659. describe('nozzle rack card', () => {
  660. const h2cStatus = {
  661. ...mockPrinterStatus,
  662. nozzle_rack: [
  663. { 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: '' },
  664. { 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: '' },
  665. { 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: '' },
  666. { 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: '' },
  667. { 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: '' },
  668. { id: 19, nozzle_type: '', nozzle_diameter: '', wear: null, stat: null, max_temp: 0, serial_number: '', filament_color: '', filament_id: '', filament_type: '' },
  669. { id: 20, nozzle_type: '', nozzle_diameter: '', wear: null, stat: null, max_temp: 0, serial_number: '', filament_color: '', filament_id: '', filament_type: '' },
  670. { id: 21, nozzle_type: '', nozzle_diameter: '', wear: null, stat: null, max_temp: 0, serial_number: '', filament_color: '', filament_id: '', filament_type: '' },
  671. ],
  672. };
  673. it('shows nozzle rack when H2C rack slots present', async () => {
  674. server.use(
  675. http.get('/api/v1/printers/:id/status', () => {
  676. return HttpResponse.json(h2cStatus);
  677. })
  678. );
  679. render(<PrintersPage />);
  680. await waitFor(() => {
  681. expect(screen.getAllByText('Nozzle Rack').length).toBeGreaterThan(0);
  682. });
  683. });
  684. it('shows 6 rack slot elements for H2C', async () => {
  685. server.use(
  686. http.get('/api/v1/printers/:id/status', () => {
  687. return HttpResponse.json(h2cStatus);
  688. })
  689. );
  690. render(<PrintersPage />);
  691. await waitFor(() => {
  692. expect(screen.getAllByText('Nozzle Rack').length).toBeGreaterThan(0);
  693. });
  694. // Rack shows diameters for occupied slots and dashes for empty ones
  695. const dashes = screen.getAllByText('—');
  696. expect(dashes.length).toBeGreaterThanOrEqual(3); // 3 empty rack positions (IDs 19,20,21)
  697. });
  698. it('keeps empty slot anchored to physical position when its nozzle is mounted (#943)', async () => {
  699. // H2C with rack slot 16 picked up into the hotend — firmware omits ID 16
  700. // entirely from nozzle.info. Each rack diameter is unique so we can assert
  701. // the ordering by tooltip lookup.
  702. const h2cSlot16Mounted = {
  703. ...mockPrinterStatus,
  704. nozzle_rack: [
  705. { 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: '' },
  706. { 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: '' },
  707. // ID 16 missing — currently in hotend
  708. { 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: '' },
  709. { 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: '' },
  710. { 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: '' },
  711. { 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: '' },
  712. { 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: '' },
  713. ],
  714. };
  715. server.use(
  716. http.get('/api/v1/printers/:id/status', () => {
  717. return HttpResponse.json(h2cSlot16Mounted);
  718. })
  719. );
  720. render(<PrintersPage />);
  721. await waitFor(() => {
  722. expect(screen.getAllByText('Nozzle Rack').length).toBeGreaterThan(0);
  723. });
  724. // Slot 1 (leftmost, ID 16) should be the empty dash; slots 2..6 should
  725. // hold the 5 remaining nozzles in order 17, 18, 19, 20, 21.
  726. const rackLabel = screen.getAllByText('Nozzle Rack')[0];
  727. const rackCard = rackLabel.parentElement!;
  728. const slotRow = rackCard.querySelectorAll('div.flex')[0];
  729. // Match the diameter spans specifically — each chip also carries a slot
  730. // number span, and a bare `span` sweep would interleave the two.
  731. const slotTexts = Array.from(slotRow.querySelectorAll('span[data-rack-diameter]')).map(s => s.textContent);
  732. expect(slotTexts).toEqual(['—', '0.2', '0.6', '0.8', '1.0', '1.2']);
  733. });
  734. it('labels every rack position 1..6 regardless of which nozzles are present', async () => {
  735. // The numbering is positional, not a count of what is loaded: the empty
  736. // position keeps its number so "the nozzle in slot 4" means the same
  737. // thing whether or not slots 1..3 are occupied.
  738. server.use(
  739. http.get('/api/v1/printers/:id/status', () => {
  740. return HttpResponse.json(h2cStatus);
  741. })
  742. );
  743. render(<PrintersPage />);
  744. await waitFor(() => {
  745. expect(screen.getAllByText('Nozzle Rack').length).toBeGreaterThan(0);
  746. });
  747. const rackLabel = screen.getAllByText('Nozzle Rack')[0];
  748. const slotRow = rackLabel.parentElement!.querySelectorAll('div.flex')[0];
  749. const numbers = Array.from(slotRow.querySelectorAll('span:not([data-rack-diameter])')).map(s => s.textContent);
  750. expect(numbers).toEqual(['1', '2', '3', '4', '5', '6']);
  751. });
  752. it('sizes the rack chips from the card scale rather than a fixed 28px', async () => {
  753. // The chips were hard-coded while the type and icons around them grow
  754. // with the card size, so at L and XL the rack read as a shrunken strip
  755. // next to neighbours that had grown by up to 40%.
  756. server.use(
  757. http.get('/api/v1/printers/:id/status', () => {
  758. return HttpResponse.json(h2cStatus);
  759. })
  760. );
  761. render(<PrintersPage />);
  762. await waitFor(() => {
  763. expect(screen.getAllByText('Nozzle Rack').length).toBeGreaterThan(0);
  764. });
  765. const rackLabel = screen.getAllByText('Nozzle Rack')[0];
  766. const slotRow = rackLabel.parentElement!.querySelectorAll('div.flex')[0];
  767. const chip = slotRow.querySelector('span[data-rack-diameter]')!.parentElement!;
  768. expect(chip.className).toContain('w-[var(--pc-i7,28px)]');
  769. expect(chip.className).toContain('h-[var(--pc-i7,28px)]');
  770. });
  771. it('hides nozzle rack when only L/R nozzles present (H2D)', async () => {
  772. const h2dStatus = {
  773. ...mockPrinterStatus,
  774. nozzle_rack: [
  775. { id: 0, nozzle_type: 'HS', nozzle_diameter: '0.4', wear: 5, stat: 1, max_temp: 300, serial_number: '', filament_color: '', filament_id: '', filament_type: '' },
  776. { id: 1, nozzle_type: 'HS', nozzle_diameter: '0.4', wear: 3, stat: 1, max_temp: 300, serial_number: '', filament_color: '', filament_id: '', filament_type: '' },
  777. ],
  778. };
  779. server.use(
  780. http.get('/api/v1/printers/:id/status', () => {
  781. return HttpResponse.json(h2dStatus);
  782. })
  783. );
  784. render(<PrintersPage />);
  785. await waitFor(() => {
  786. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  787. });
  788. expect(screen.queryByText('Nozzle Rack')).not.toBeInTheDocument();
  789. });
  790. });
  791. describe('firmware version badge', () => {
  792. const firmwareUpToDate = {
  793. printer_id: 1,
  794. current_version: '01.09.00.00',
  795. latest_version: '01.09.00.00',
  796. update_available: false,
  797. download_url: null,
  798. release_notes: 'Bug fixes and improvements.',
  799. };
  800. const firmwareUpdateAvailable = {
  801. printer_id: 1,
  802. current_version: '01.08.00.00',
  803. latest_version: '01.09.00.00',
  804. update_available: true,
  805. download_url: 'https://example.com/firmware.bin',
  806. release_notes: 'New features added.',
  807. };
  808. it('shows green badge when firmware is up to date', async () => {
  809. server.use(
  810. http.get('/api/v1/firmware/updates/:id', () => {
  811. return HttpResponse.json(firmwareUpToDate);
  812. }),
  813. http.get('/api/v1/settings/', () => {
  814. return HttpResponse.json({
  815. check_printer_firmware: true,
  816. auto_archive: true,
  817. save_thumbnails: true,
  818. });
  819. })
  820. );
  821. render(<PrintersPage />);
  822. await waitFor(() => {
  823. expect(screen.getAllByText('01.09.00.00').length).toBeGreaterThan(0);
  824. });
  825. const badge = screen.getAllByText('01.09.00.00')[0].closest('button');
  826. expect(badge).toBeInTheDocument();
  827. expect(badge?.className).toContain('text-status-ok');
  828. });
  829. it('shows orange badge when firmware update is available', async () => {
  830. server.use(
  831. http.get('/api/v1/firmware/updates/:id', () => {
  832. return HttpResponse.json(firmwareUpdateAvailable);
  833. }),
  834. http.get('/api/v1/settings/', () => {
  835. return HttpResponse.json({
  836. check_printer_firmware: true,
  837. auto_archive: true,
  838. save_thumbnails: true,
  839. });
  840. })
  841. );
  842. render(<PrintersPage />);
  843. await waitFor(() => {
  844. expect(screen.getAllByText('01.08.00.00').length).toBeGreaterThan(0);
  845. });
  846. const badge = screen.getAllByText('01.08.00.00')[0].closest('button');
  847. expect(badge).toBeInTheDocument();
  848. expect(badge?.className).toContain('text-orange-400');
  849. });
  850. it('hides badge when firmware check is disabled', async () => {
  851. server.use(
  852. http.get('/api/v1/settings/', () => {
  853. return HttpResponse.json({
  854. check_printer_firmware: false,
  855. auto_archive: true,
  856. save_thumbnails: true,
  857. });
  858. })
  859. );
  860. render(<PrintersPage />);
  861. await waitFor(() => {
  862. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  863. });
  864. // Version should not appear when firmware check is disabled
  865. expect(screen.queryByText('01.09.00.00')).not.toBeInTheDocument();
  866. expect(screen.queryByText('01.08.00.00')).not.toBeInTheDocument();
  867. });
  868. it('hides badge when API has no firmware data for the model', async () => {
  869. const firmwareNoData = {
  870. printer_id: 1,
  871. current_version: '01.01.03.00',
  872. latest_version: null,
  873. update_available: false,
  874. download_url: null,
  875. release_notes: null,
  876. };
  877. server.use(
  878. http.get('/api/v1/firmware/updates/:id', () => {
  879. return HttpResponse.json(firmwareNoData);
  880. }),
  881. http.get('/api/v1/settings/', () => {
  882. return HttpResponse.json({
  883. check_printer_firmware: true,
  884. auto_archive: true,
  885. save_thumbnails: true,
  886. });
  887. })
  888. );
  889. render(<PrintersPage />);
  890. await waitFor(() => {
  891. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  892. });
  893. // Badge should not appear when API returns no latest_version
  894. expect(screen.queryByText('01.01.03.00')).not.toBeInTheDocument();
  895. });
  896. });
  897. describe('bulk selection', () => {
  898. it('shows select button in toolbar', async () => {
  899. render(<PrintersPage />);
  900. await waitFor(() => {
  901. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  902. });
  903. // The Select button should be in the toolbar (title attribute)
  904. const selectButton = screen.getByTitle('Select');
  905. expect(selectButton).toBeInTheDocument();
  906. });
  907. it('shows selection toolbar after clicking select button', async () => {
  908. render(<PrintersPage />);
  909. await waitFor(() => {
  910. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  911. });
  912. // Click the Select button to enter selection mode
  913. fireEvent.click(screen.getByTitle('Select'));
  914. // The floating toolbar should appear with Select All
  915. await waitFor(() => {
  916. expect(screen.getByText('Select All')).toBeInTheDocument();
  917. });
  918. });
  919. it('shows selection count when printers are selected', async () => {
  920. render(<PrintersPage />);
  921. await waitFor(() => {
  922. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  923. });
  924. // Enter selection mode
  925. fireEvent.click(screen.getByTitle('Select'));
  926. await waitFor(() => {
  927. expect(screen.getByText('Select All')).toBeInTheDocument();
  928. });
  929. // Click Select All to select both printers
  930. fireEvent.click(screen.getByText('Select All'));
  931. // Should show "2 selected"
  932. await waitFor(() => {
  933. expect(screen.getByText('2 selected')).toBeInTheDocument();
  934. });
  935. });
  936. it('shows select by state dropdown', async () => {
  937. render(<PrintersPage />);
  938. await waitFor(() => {
  939. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  940. });
  941. // Enter selection mode
  942. fireEvent.click(screen.getByTitle('Select'));
  943. await waitFor(() => {
  944. expect(screen.getByText('Select by State')).toBeInTheDocument();
  945. });
  946. });
  947. it('exits selection mode on close button', async () => {
  948. render(<PrintersPage />);
  949. await waitFor(() => {
  950. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  951. });
  952. // Enter selection mode
  953. fireEvent.click(screen.getByTitle('Select'));
  954. await waitFor(() => {
  955. expect(screen.getByText('Select All')).toBeInTheDocument();
  956. });
  957. // Click the Select button again to exit (it toggles)
  958. fireEvent.click(screen.getByTitle('Select'));
  959. // Floating toolbar should disappear
  960. await waitFor(() => {
  961. expect(screen.queryByText('Select All')).not.toBeInTheDocument();
  962. });
  963. });
  964. });
  965. describe('search and filter', () => {
  966. beforeEach(() => {
  967. server.use(
  968. http.get('/api/v1/printers/', () => HttpResponse.json(mockPrinters)),
  969. http.get('/api/v1/printers/:id/status', () => HttpResponse.json(mockPrinterStatus)),
  970. http.get('/api/v1/queue/', () => HttpResponse.json([]))
  971. );
  972. });
  973. it('filters by name (case-insensitive)', async () => {
  974. render(<PrintersPage />);
  975. await waitFor(() => expect(screen.getByText('X1 Carbon')).toBeInTheDocument());
  976. fireEvent.change(screen.getByPlaceholderText('Search printers...'), { target: { value: 'x1 carbon' } });
  977. await waitFor(() => {
  978. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  979. expect(screen.queryByText('P1S Backup')).not.toBeInTheDocument();
  980. });
  981. });
  982. it('trims leading and trailing whitespace from search', async () => {
  983. render(<PrintersPage />);
  984. await waitFor(() => expect(screen.getByText('X1 Carbon')).toBeInTheDocument());
  985. // " X1 Carbon " with surrounding spaces must still match
  986. fireEvent.change(screen.getByPlaceholderText('Search printers...'), { target: { value: ' X1 Carbon ' } });
  987. await waitFor(() => {
  988. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  989. expect(screen.queryByText('P1S Backup')).not.toBeInTheDocument();
  990. });
  991. });
  992. it('filters by model', async () => {
  993. render(<PrintersPage />);
  994. await waitFor(() => expect(screen.getByText('X1 Carbon')).toBeInTheDocument());
  995. fireEvent.change(screen.getByPlaceholderText('Search printers...'), { target: { value: 'P1S' } });
  996. await waitFor(() => {
  997. expect(screen.queryByText('X1 Carbon')).not.toBeInTheDocument();
  998. expect(screen.getByText('P1S Backup')).toBeInTheDocument();
  999. });
  1000. });
  1001. it('filters by serial number', async () => {
  1002. render(<PrintersPage />);
  1003. await waitFor(() => expect(screen.getByText('X1 Carbon')).toBeInTheDocument());
  1004. fireEvent.change(screen.getByPlaceholderText('Search printers...'), { target: { value: '00M09A' } });
  1005. await waitFor(() => {
  1006. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  1007. expect(screen.queryByText('P1S Backup')).not.toBeInTheDocument();
  1008. });
  1009. });
  1010. it('shows empty state when no printers match search', async () => {
  1011. render(<PrintersPage />);
  1012. await waitFor(() => expect(screen.getByText('X1 Carbon')).toBeInTheDocument());
  1013. fireEvent.change(screen.getByPlaceholderText('Search printers...'), { target: { value: 'ZZZ_NO_MATCH' } });
  1014. await waitFor(() => {
  1015. expect(screen.getByText('No printers match your search or filters')).toBeInTheDocument();
  1016. });
  1017. });
  1018. it('clear button resets search and shows all printers', async () => {
  1019. render(<PrintersPage />);
  1020. await waitFor(() => expect(screen.getByText('X1 Carbon')).toBeInTheDocument());
  1021. fireEvent.change(screen.getByPlaceholderText('Search printers...'), { target: { value: 'X1 Carbon' } });
  1022. await waitFor(() => expect(screen.queryByText('P1S Backup')).not.toBeInTheDocument());
  1023. // Click the accessible clear button
  1024. fireEvent.click(screen.getByRole('button', { name: 'Clear' }));
  1025. await waitFor(() => {
  1026. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  1027. expect(screen.getByText('P1S Backup')).toBeInTheDocument();
  1028. });
  1029. });
  1030. it('filters by status (offline) via dropdown', async () => {
  1031. // Override: printer 1 online, printer 2 offline
  1032. server.use(
  1033. http.get('/api/v1/printers/:id/status', ({ params }) => {
  1034. if (Number(params.id) === 2) {
  1035. return HttpResponse.json({ ...mockPrinterStatus, connected: false });
  1036. }
  1037. return HttpResponse.json(mockPrinterStatus);
  1038. })
  1039. );
  1040. render(<PrintersPage />);
  1041. await waitFor(() => expect(screen.getByText('X1 Carbon')).toBeInTheDocument());
  1042. await selectToolbarDropdownOption(/all statuses/i, /^offline$/i);
  1043. await waitFor(() => {
  1044. expect(screen.queryByText('X1 Carbon')).not.toBeInTheDocument();
  1045. expect(screen.getByText('P1S Backup')).toBeInTheDocument();
  1046. });
  1047. });
  1048. it('shows empty state when status filter matches nothing', async () => {
  1049. render(<PrintersPage />);
  1050. await waitFor(() => expect(screen.getByText('X1 Carbon')).toBeInTheDocument());
  1051. // Both printers are IDLE; filtering by "printing" should yield no results
  1052. await selectToolbarDropdownOption(/all statuses/i, /^printing$/i);
  1053. await waitFor(() => {
  1054. expect(screen.getByText('No printers match your search or filters')).toBeInTheDocument();
  1055. });
  1056. });
  1057. it('combines search and status filter', async () => {
  1058. // Printer 1 = RUNNING (printing), printer 2 = IDLE
  1059. server.use(
  1060. http.get('/api/v1/printers/:id/status', ({ params }) => {
  1061. if (Number(params.id) === 1) {
  1062. return HttpResponse.json({ ...mockPrinterStatus, state: 'RUNNING' });
  1063. }
  1064. return HttpResponse.json(mockPrinterStatus);
  1065. })
  1066. );
  1067. render(<PrintersPage />);
  1068. await waitFor(() => expect(screen.getByText('X1 Carbon')).toBeInTheDocument());
  1069. // Filter to only "printing" printers
  1070. await selectToolbarDropdownOption(/all statuses/i, /^printing$/i);
  1071. // Then also search for a term that only matches printer 1
  1072. fireEvent.change(screen.getByPlaceholderText('Search printers...'), { target: { value: 'X1' } });
  1073. await waitFor(() => {
  1074. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  1075. expect(screen.queryByText('P1S Backup')).not.toBeInTheDocument();
  1076. });
  1077. });
  1078. it('filters by location via dropdown', async () => {
  1079. // Override: give printer 2 its own location so the dropdown has two options
  1080. // and we can verify the filter picks the right one. Printer 1 stays at 'Workshop'.
  1081. server.use(
  1082. http.get('/api/v1/printers/', () =>
  1083. HttpResponse.json([
  1084. mockPrinters[0],
  1085. { ...mockPrinters[1], location: 'Office' },
  1086. ])
  1087. )
  1088. );
  1089. render(<PrintersPage />);
  1090. await waitFor(() => {
  1091. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  1092. expect(screen.getByText('P1S Backup')).toBeInTheDocument();
  1093. });
  1094. await selectToolbarDropdownOption(/all locations/i, /^workshop$/i);
  1095. await waitFor(() => {
  1096. expect(screen.getByText('X1 Carbon')).toBeInTheDocument();
  1097. expect(screen.queryByText('P1S Backup')).not.toBeInTheDocument();
  1098. });
  1099. await selectToolbarDropdownOption(/^workshop$/i, /^office$/i);
  1100. await waitFor(() => {
  1101. expect(screen.queryByText('X1 Carbon')).not.toBeInTheDocument();
  1102. expect(screen.getByText('P1S Backup')).toBeInTheDocument();
  1103. });
  1104. });
  1105. it('hides location filter when no printers have a location', async () => {
  1106. // Both printers have null location — dropdown should not render at all
  1107. server.use(
  1108. http.get('/api/v1/printers/', () =>
  1109. HttpResponse.json([
  1110. { ...mockPrinters[0], location: null },
  1111. { ...mockPrinters[1], location: null },
  1112. ])
  1113. )
  1114. );
  1115. render(<PrintersPage />);
  1116. await waitFor(() => expect(screen.getByText('X1 Carbon')).toBeInTheDocument());
  1117. // Status filter is still there, but the location filter should be absent.
  1118. expect(screen.getByRole('button', { name: /all statuses/i })).toBeInTheDocument();
  1119. expect(screen.queryByRole('button', { name: /all locations/i })).not.toBeInTheDocument();
  1120. });
  1121. });
  1122. describe('Spoolman loading guard', () => {
  1123. it('does not show Assign Spool button while Spoolman queries are loading', async () => {
  1124. // Spoolman enabled but inventory and slot-assignment queries never resolve
  1125. server.use(
  1126. http.get('/api/v1/spoolman/status', () =>
  1127. HttpResponse.json({ enabled: true, connected: true })
  1128. ),
  1129. http.get('/api/v1/spoolman/inventory/spools', () =>
  1130. new Promise(() => {}) // never resolves
  1131. ),
  1132. http.get('/api/v1/spoolman/inventory/slot-assignments/all', () =>
  1133. new Promise(() => {}) // never resolves
  1134. )
  1135. );
  1136. render(<PrintersPage />);
  1137. // Wait for the page to render (printers should be visible)
  1138. await waitFor(() => expect(screen.getByText('X1 Carbon')).toBeInTheDocument());
  1139. // While Spoolman queries are still loading, the "Assign Spool" button must
  1140. // not appear (inventory prop is undefined → {inventory && ...} guard fires)
  1141. expect(screen.queryByText('Assign Spool')).not.toBeInTheDocument();
  1142. });
  1143. });
  1144. });
  1145. /**
  1146. * Phase 13 P13-1 (PrintersPage EmptySlotHoverCard onAssignSpool gate removal)
  1147. *
  1148. * Pre-Phase-13 each of the three EmptySlotHoverCard call-sites in PrintersPage
  1149. * gated `onAssignSpool` on `spoolmanEnabled ? (...) : undefined`, so empty
  1150. * slots in local-Inventory mode never showed an Assign action. Maintainer
  1151. * Foto 7 confirmed users expect the button regardless of mode.
  1152. *
  1153. * To assert wiring without going through hover-card animations, we mock the
  1154. * EmptySlotHoverCard component at module level and capture every props
  1155. * payload. The same mock is active in both modes; tests differ only in the
  1156. * spoolman-settings mock. The mock module covers BOTH FilamentHoverCard exports
  1157. * so tests outside this `describe` aren't affected (we re-export the real
  1158. * FilamentHoverCard).
  1159. */
  1160. const phase13EmptySlotProps: Array<Record<string, unknown>> = [];
  1161. const phase14HoverCardProps: Array<Record<string, unknown>> = [];
  1162. vi.mock('../../components/FilamentHoverCard', async (importOriginal) => {
  1163. const actual = await importOriginal<typeof import('../../components/FilamentHoverCard')>();
  1164. return {
  1165. ...actual,
  1166. EmptySlotHoverCard: (props: Record<string, unknown>) => {
  1167. phase13EmptySlotProps.push({ ...props });
  1168. return null;
  1169. },
  1170. FilamentHoverCard: (props: Record<string, unknown>) => {
  1171. phase14HoverCardProps.push({ ...props });
  1172. return null;
  1173. },
  1174. };
  1175. });
  1176. describe('PrintersPage Phase 13 — EmptySlotHoverCard onAssignSpool wiring', () => {
  1177. beforeEach(() => {
  1178. phase13EmptySlotProps.length = 0;
  1179. localStorage.removeItem('printerCardSize');
  1180. server.use(
  1181. http.get('/api/v1/printers/', () => HttpResponse.json(mockPrinters)),
  1182. // Status response includes an empty AMS slot so EmptySlotHoverCard renders.
  1183. http.get('/api/v1/printers/:id/status', () => HttpResponse.json({
  1184. ...mockPrinterStatus,
  1185. ams: [{
  1186. id: 0,
  1187. tray: [{ id: 0, tray_type: '' }],
  1188. }],
  1189. })),
  1190. http.get('/api/v1/settings/', () => HttpResponse.json({
  1191. auto_archive: true, save_thumbnails: true, capture_finish_photo: true,
  1192. default_filament_cost: 25.0, currency: 'USD',
  1193. ams_humidity_good: 40, ams_humidity_fair: 60,
  1194. ams_temp_good: 30, ams_temp_fair: 35,
  1195. })),
  1196. http.get('/api/v1/queue/', () => HttpResponse.json([])),
  1197. );
  1198. });
  1199. it('P13-1 (local mode): EmptySlotHoverCard receives onAssignSpool callback', async () => {
  1200. server.use(
  1201. http.get('/api/v1/spoolman/settings', () => HttpResponse.json({
  1202. spoolman_enabled: 'false', spoolman_url: '',
  1203. })),
  1204. );
  1205. render(<PrintersPage />);
  1206. // Wait for printer status to load and at least one EmptySlotHoverCard
  1207. // to mount with an onAssignSpool callback. Pre-Phase-13 this would have
  1208. // been undefined in local mode (the gate filtered it out).
  1209. await waitFor(() => {
  1210. const withCallback = phase13EmptySlotProps.filter(p => typeof p.onAssignSpool === 'function');
  1211. expect(withCallback.length).toBeGreaterThan(0);
  1212. }, { timeout: 3000 });
  1213. });
  1214. it('#1322: empty slot kind is "physical" when state=9 and "reset" otherwise', async () => {
  1215. // Bambuddy now distinguishes a firmware-confirmed empty slot (state=9
  1216. // via tray_exist_bits) from a slot the user reset but where the
  1217. // firmware still has a spool registered. The kind prop drives both
  1218. // the inline label ("Empty" vs "Reset") and the hover card label.
  1219. server.use(
  1220. http.get('/api/v1/spoolman/settings', () => HttpResponse.json({
  1221. spoolman_enabled: 'false', spoolman_url: '',
  1222. })),
  1223. http.get('/api/v1/printers/:id/status', () => HttpResponse.json({
  1224. ...mockPrinterStatus,
  1225. ams: [{
  1226. id: 0,
  1227. tray: [
  1228. { id: 0, tray_type: '', state: 9 }, // physically empty
  1229. { id: 1, tray_type: '', state: 3 }, // reset / unloading
  1230. { id: 2, tray_type: '', state: null }, // unknown empty
  1231. { id: 3, tray_type: 'PLA', state: 11 }, // loaded — no card here
  1232. ],
  1233. }],
  1234. })),
  1235. );
  1236. render(<PrintersPage />);
  1237. await waitFor(() => {
  1238. expect(phase13EmptySlotProps.filter(p => p.kind === 'physical').length).toBeGreaterThan(0);
  1239. }, { timeout: 3000 });
  1240. const physical = phase13EmptySlotProps.filter(p => p.kind === 'physical');
  1241. const reset = phase13EmptySlotProps.filter(p => p.kind === 'reset');
  1242. expect(physical.length).toBeGreaterThan(0);
  1243. expect(reset.length).toBeGreaterThan(0);
  1244. // state=null falls back to 'reset' too — the helper only returns
  1245. // 'physical' for the canonical 9/10 firmware codes.
  1246. });
  1247. it('P13-1 (spoolman mode): EmptySlotHoverCard still receives onAssignSpool callback', async () => {
  1248. server.use(
  1249. http.get('/api/v1/spoolman/settings', () => HttpResponse.json({
  1250. spoolman_enabled: 'true', spoolman_url: 'http://x:7912',
  1251. })),
  1252. http.get('/api/v1/spoolman/spools/inventory*', () => HttpResponse.json([])),
  1253. http.get('/api/v1/spoolman/inventory/spools', () => HttpResponse.json([])),
  1254. http.get('/api/v1/spoolman/inventory/slot-assignments/all', () => HttpResponse.json([])),
  1255. );
  1256. render(<PrintersPage />);
  1257. await waitFor(() => {
  1258. const withCallback = phase13EmptySlotProps.filter(p => typeof p.onAssignSpool === 'function');
  1259. expect(withCallback.length).toBeGreaterThan(0);
  1260. }, { timeout: 3000 });
  1261. });
  1262. });
  1263. /**
  1264. * Phase 14 — Local-Branch BL-detection symmetry.
  1265. *
  1266. * The Spoolman branch of every IIFE in PrintersPage already passes
  1267. * isAssigned: !!slotAssignment || isBambuLabSpool(tray)
  1268. * onUnassignSpool: (spoolmanSpool && !isBambuLabSpool(tray)) ? ... : undefined
  1269. *
  1270. * The local branch was missing both. As a result a BL-RFID-tagged slot in
  1271. * local-Inventory mode showed an "Assign Spool" button (because no manual
  1272. * SpoolAssignment exists), and a manually-assigned BL-RFID slot showed
  1273. * "Unassign" — which would be overwritten on the next RFID re-read.
  1274. *
  1275. * The same FilamentHoverCard mock from the Phase 13 block above captures
  1276. * inventory props on every render so we can inspect them after setup.
  1277. */
  1278. describe('PrintersPage Phase 14 — Local-Branch BL-detection symmetry', () => {
  1279. beforeEach(() => {
  1280. phase14HoverCardProps.length = 0;
  1281. localStorage.removeItem('printerCardSize');
  1282. server.use(
  1283. http.get('/api/v1/printers/', () => HttpResponse.json(mockPrinters)),
  1284. http.get('/api/v1/settings/', () => HttpResponse.json({
  1285. auto_archive: true, save_thumbnails: true, capture_finish_photo: true,
  1286. default_filament_cost: 25.0, currency: 'USD',
  1287. ams_humidity_good: 40, ams_humidity_fair: 60,
  1288. ams_temp_good: 30, ams_temp_fair: 35,
  1289. })),
  1290. http.get('/api/v1/queue/', () => HttpResponse.json([])),
  1291. http.get('/api/v1/spoolman/settings', () => HttpResponse.json({
  1292. spoolman_enabled: 'false', spoolman_url: '',
  1293. })),
  1294. );
  1295. });
  1296. it('P14-1a (local + BL-RFID + no assignment): inventory.isAssigned=true', async () => {
  1297. server.use(
  1298. http.get('/api/v1/printers/:id/status', () => HttpResponse.json({
  1299. ...mockPrinterStatus,
  1300. ams: [{
  1301. id: 0,
  1302. tray: [{
  1303. id: 0,
  1304. tray_type: 'PLA',
  1305. tray_uuid: '11223344556677880011223344556677',
  1306. tag_uid: '0000000000000000',
  1307. tray_color: 'FF0000FF',
  1308. tray_sub_brands: 'Bambu PLA Basic',
  1309. }],
  1310. }],
  1311. })),
  1312. http.get('/api/v1/inventory/assignments', () => HttpResponse.json([])),
  1313. );
  1314. render(<PrintersPage />);
  1315. await waitFor(() => {
  1316. const matches = phase14HoverCardProps.filter(
  1317. p => (p.inventory as { isAssigned?: boolean } | undefined)?.isAssigned === true
  1318. );
  1319. expect(matches.length).toBeGreaterThan(0);
  1320. }, { timeout: 3000 });
  1321. });
  1322. it('P14-1b (local + non-BL + no assignment): inventory.isAssigned is falsy', async () => {
  1323. server.use(
  1324. http.get('/api/v1/printers/:id/status', () => HttpResponse.json({
  1325. ...mockPrinterStatus,
  1326. ams: [{
  1327. id: 0,
  1328. tray: [{
  1329. id: 0,
  1330. tray_type: 'PLA',
  1331. tray_uuid: '00000000000000000000000000000000',
  1332. tag_uid: '0000000000000000',
  1333. tray_color: 'FF0000FF',
  1334. tray_sub_brands: 'Generic PLA',
  1335. }],
  1336. }],
  1337. })),
  1338. http.get('/api/v1/inventory/assignments', () => HttpResponse.json([])),
  1339. );
  1340. render(<PrintersPage />);
  1341. // Wait for FilamentHoverCard to render at least once.
  1342. await waitFor(() => {
  1343. expect(phase14HoverCardProps.length).toBeGreaterThan(0);
  1344. }, { timeout: 3000 });
  1345. // No render should ever set isAssigned=true for this slot.
  1346. const truthyMatches = phase14HoverCardProps.filter(
  1347. p => (p.inventory as { isAssigned?: boolean } | undefined)?.isAssigned === true
  1348. );
  1349. expect(truthyMatches.length).toBe(0);
  1350. });
  1351. it('P14-1c (local + manual assignment): inventory.isAssigned=true', async () => {
  1352. server.use(
  1353. http.get('/api/v1/printers/:id/status', () => HttpResponse.json({
  1354. ...mockPrinterStatus,
  1355. ams: [{
  1356. id: 0,
  1357. tray: [{
  1358. id: 0,
  1359. tray_type: 'PLA',
  1360. tray_uuid: '00000000000000000000000000000000',
  1361. tag_uid: '0000000000000000',
  1362. tray_color: 'FF0000FF',
  1363. tray_sub_brands: 'Generic PLA',
  1364. }],
  1365. }],
  1366. })),
  1367. http.get('/api/v1/inventory/assignments', () => HttpResponse.json([
  1368. {
  1369. id: 1,
  1370. spool_id: 42,
  1371. printer_id: 1,
  1372. ams_id: 0,
  1373. tray_id: 0,
  1374. printer_name: 'X1 Carbon',
  1375. ams_label: null,
  1376. spool: {
  1377. id: 42,
  1378. material: 'PLA',
  1379. brand: 'Generic',
  1380. color_name: 'Red',
  1381. label_weight: 1000,
  1382. weight_used: 0,
  1383. rgba: 'FF0000FF',
  1384. },
  1385. },
  1386. ])),
  1387. );
  1388. render(<PrintersPage />);
  1389. await waitFor(() => {
  1390. const matches = phase14HoverCardProps.filter(
  1391. p => (p.inventory as { isAssigned?: boolean } | undefined)?.isAssigned === true
  1392. );
  1393. expect(matches.length).toBeGreaterThan(0);
  1394. }, { timeout: 3000 });
  1395. });
  1396. it('P14-2 (local + BL-RFID + manual assignment): onUnassignSpool=undefined', async () => {
  1397. server.use(
  1398. http.get('/api/v1/printers/:id/status', () => HttpResponse.json({
  1399. ...mockPrinterStatus,
  1400. ams: [{
  1401. id: 0,
  1402. tray: [{
  1403. id: 0,
  1404. tray_type: 'PLA',
  1405. tray_uuid: '11223344556677880011223344556677',
  1406. tag_uid: '0000000000000000',
  1407. tray_color: 'FF0000FF',
  1408. tray_sub_brands: 'Bambu PLA Basic',
  1409. }],
  1410. }],
  1411. })),
  1412. http.get('/api/v1/inventory/assignments', () => HttpResponse.json([
  1413. {
  1414. id: 1,
  1415. spool_id: 42,
  1416. printer_id: 1,
  1417. ams_id: 0,
  1418. tray_id: 0,
  1419. printer_name: 'X1 Carbon',
  1420. ams_label: null,
  1421. spool: {
  1422. id: 42,
  1423. material: 'PLA',
  1424. brand: 'Bambu Lab',
  1425. color_name: 'Red',
  1426. label_weight: 1000,
  1427. weight_used: 0,
  1428. rgba: 'FF0000FF',
  1429. },
  1430. },
  1431. ])),
  1432. );
  1433. render(<PrintersPage />);
  1434. // Wait for FilamentHoverCard renders to settle.
  1435. await waitFor(() => {
  1436. expect(phase14HoverCardProps.length).toBeGreaterThan(0);
  1437. }, { timeout: 3000 });
  1438. // For BL-detected slots in local mode, onUnassignSpool must always be
  1439. // undefined — even when a manual assignment exists. Otherwise the user
  1440. // could unassign a BL-RFID slot that the printer would re-assign on the
  1441. // next re-read, surprising them with phantom ghost-assignments.
  1442. const definedUnassign = phase14HoverCardProps.filter(
  1443. p => typeof (p.inventory as { onUnassignSpool?: () => void } | undefined)?.onUnassignSpool === 'function'
  1444. );
  1445. expect(definedUnassign.length).toBe(0);
  1446. });
  1447. });