FilamentOverride.test.tsx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. /**
  2. * Tests for the FilamentOverride component.
  3. *
  4. * FilamentOverride allows users to override the 3MF's original filament
  5. * choices with filaments available across printers of the selected model.
  6. */
  7. import { describe, it, expect, vi, afterEach } from 'vitest';
  8. import { screen, fireEvent, cleanup, waitFor, within } from '@testing-library/react';
  9. import { http, HttpResponse } from 'msw';
  10. import { render } from '../utils';
  11. import { server } from '../mocks/server';
  12. import { FilamentOverride } from '../../components/PrintModal/FilamentOverride';
  13. import type { FilamentReqsData } from '../../components/PrintModal/types';
  14. const defaultFilamentReqs: FilamentReqsData = {
  15. filaments: [
  16. { slot_id: 1, type: 'PLA', color: '#FF0000', used_grams: 25, used_meters: 8.5 },
  17. ],
  18. };
  19. const defaultAvailable = [
  20. { type: 'PLA', color: '#FF0000', tray_info_idx: 'GFA00', tray_sub_brands: 'PLA Basic', extruder_id: null },
  21. { type: 'PLA', color: '#00FF00', tray_info_idx: 'GFA01', tray_sub_brands: 'PLA Basic', extruder_id: null },
  22. { type: 'PETG', color: '#0000FF', tray_info_idx: 'GFG00', tray_sub_brands: 'PETG Basic', extruder_id: null },
  23. ];
  24. const mockOnChange = vi.fn();
  25. /**
  26. * Open an override picker and hand back its rows.
  27. *
  28. * These assertions used to read `select.querySelectorAll('option')`. The
  29. * control gained a swatch per choice (#3159), which an `<option>` cannot
  30. * render, so it is a listbox now: its rows exist only while it is open, and
  31. * each carries its identity on `data-value` the way `<option value>` did.
  32. */
  33. function openPicker(index = 0): HTMLElement[] {
  34. fireEvent.click(screen.getAllByRole('combobox')[index]);
  35. return within(screen.getByRole('listbox')).getAllByRole('option');
  36. }
  37. /** The identities the picker offers, in order — the old `option.value` list. */
  38. function optionValues(index = 0): (string | null)[] {
  39. return openPicker(index).map((o) => o.getAttribute('data-value'));
  40. }
  41. /**
  42. * What the closed control reads as. With nothing overridden this is the
  43. * "original filament" row, which is where the #1718 label resolution lands —
  44. * previously read off `option[value=""]`.
  45. */
  46. function triggerText(index = 0): string {
  47. return screen.getAllByRole('combobox')[index].textContent ?? '';
  48. }
  49. afterEach(() => {
  50. cleanup();
  51. vi.clearAllMocks();
  52. });
  53. describe('FilamentOverride', () => {
  54. describe('rendering', () => {
  55. it('returns null when filamentReqs is undefined', () => {
  56. render(
  57. <FilamentOverride
  58. filamentReqs={undefined}
  59. availableFilaments={defaultAvailable}
  60. overrides={{}}
  61. onChange={mockOnChange}
  62. />
  63. );
  64. expect(screen.queryByText('Filament Override')).not.toBeInTheDocument();
  65. });
  66. it('returns null when filaments array is empty', () => {
  67. render(
  68. <FilamentOverride
  69. filamentReqs={{ filaments: [] }}
  70. availableFilaments={defaultAvailable}
  71. overrides={{}}
  72. onChange={mockOnChange}
  73. />
  74. );
  75. expect(screen.queryByText('Filament Override')).not.toBeInTheDocument();
  76. });
  77. it('returns null when availableFilaments is empty', () => {
  78. render(
  79. <FilamentOverride
  80. filamentReqs={defaultFilamentReqs}
  81. availableFilaments={[]}
  82. overrides={{}}
  83. onChange={mockOnChange}
  84. />
  85. );
  86. expect(screen.queryByText('Filament Override')).not.toBeInTheDocument();
  87. });
  88. it('renders filament slot with type and grams', () => {
  89. render(
  90. <FilamentOverride
  91. filamentReqs={defaultFilamentReqs}
  92. availableFilaments={defaultAvailable}
  93. overrides={{}}
  94. onChange={mockOnChange}
  95. />
  96. );
  97. // The grams text "(25g)" is in a nested span within the type label
  98. expect(screen.getByText('(25g)')).toBeInTheDocument();
  99. // "Filament Override" heading confirms the section renders
  100. expect(screen.getByText('Filament Override')).toBeInTheDocument();
  101. });
  102. it('renders override dropdown for each slot', () => {
  103. const twoSlotReqs: FilamentReqsData = {
  104. filaments: [
  105. { slot_id: 1, type: 'PLA', color: '#FF0000', used_grams: 25, used_meters: 8.5 },
  106. { slot_id: 2, type: 'PLA', color: '#00FF00', used_grams: 10, used_meters: 3.2 },
  107. ],
  108. };
  109. render(
  110. <FilamentOverride
  111. filamentReqs={twoSlotReqs}
  112. availableFilaments={defaultAvailable}
  113. overrides={{}}
  114. onChange={mockOnChange}
  115. />
  116. );
  117. const selects = screen.getAllByRole('combobox');
  118. expect(selects).toHaveLength(2);
  119. });
  120. });
  121. describe('type filtering', () => {
  122. it('only shows same-type filaments in dropdown', () => {
  123. render(
  124. <FilamentOverride
  125. filamentReqs={defaultFilamentReqs}
  126. availableFilaments={defaultAvailable}
  127. overrides={{}}
  128. onChange={mockOnChange}
  129. />
  130. );
  131. // 1 default "Original" row + 2 PLA rows (not PETG)
  132. const values = optionValues();
  133. expect(values).toHaveLength(3);
  134. expect(values).not.toContain('PETG|#0000FF');
  135. });
  136. it('shows all same-type options regardless of color', () => {
  137. const threeColorAvailable = [
  138. { type: 'PLA', color: '#FF0000', tray_info_idx: 'GFA00', tray_sub_brands: 'PLA Basic', extruder_id: null },
  139. { type: 'PLA', color: '#00FF00', tray_info_idx: 'GFA01', tray_sub_brands: 'PLA Basic', extruder_id: null },
  140. { type: 'PLA', color: '#FFFFFF', tray_info_idx: 'GFA02', tray_sub_brands: 'PLA Basic', extruder_id: null },
  141. ];
  142. render(
  143. <FilamentOverride
  144. filamentReqs={defaultFilamentReqs}
  145. availableFilaments={threeColorAvailable}
  146. overrides={{}}
  147. onChange={mockOnChange}
  148. />
  149. );
  150. // 1 default "Original" row + 3 PLA colour rows
  151. expect(optionValues()).toHaveLength(4);
  152. });
  153. });
  154. describe('subtype display', () => {
  155. it('shows tray_sub_brands in dropdown options when available', () => {
  156. const subtypeAvailable = [
  157. { type: 'PLA', color: '#000000', tray_info_idx: 'GFL99', tray_sub_brands: 'PLA Basic', extruder_id: null },
  158. { type: 'PLA', color: '#000000', tray_info_idx: 'GFL05', tray_sub_brands: 'PLA Matte', extruder_id: null },
  159. ];
  160. render(
  161. <FilamentOverride
  162. filamentReqs={defaultFilamentReqs}
  163. availableFilaments={subtypeAvailable}
  164. overrides={{}}
  165. onChange={mockOnChange}
  166. />
  167. );
  168. const optionTexts = openPicker().map((o) => o.textContent);
  169. // Should show "PLA Basic" and "PLA Matte", not just "PLA"
  170. expect(optionTexts.some((t) => t?.includes('PLA Basic'))).toBe(true);
  171. expect(optionTexts.some((t) => t?.includes('PLA Matte'))).toBe(true);
  172. });
  173. it('falls back to type when tray_sub_brands is empty', () => {
  174. const noSubtypeAvailable = [
  175. { type: 'PLA', color: '#FF0000', tray_info_idx: 'GFA00', tray_sub_brands: '', extruder_id: null },
  176. ];
  177. render(
  178. <FilamentOverride
  179. filamentReqs={defaultFilamentReqs}
  180. availableFilaments={noSubtypeAvailable}
  181. overrides={{}}
  182. onChange={mockOnChange}
  183. />
  184. );
  185. // Non-default row should show "PLA" as the type fallback
  186. const nonDefault = openPicker().filter((o) => o.getAttribute('data-value') !== '');
  187. expect(nonDefault[0].textContent).toContain('PLA');
  188. });
  189. });
  190. describe('nozzle filtering', () => {
  191. it('filters by extruder_id when nozzle_id is set', () => {
  192. const nozzleReqs: FilamentReqsData = {
  193. filaments: [
  194. { slot_id: 1, type: 'PLA', color: '#FF0000', used_grams: 25, used_meters: 8.5, nozzle_id: 0 },
  195. ],
  196. };
  197. const dualExtruderAvailable = [
  198. { type: 'PLA', color: '#FF0000', tray_info_idx: 'GFA00', tray_sub_brands: 'PLA Basic', extruder_id: 0 },
  199. { type: 'PLA', color: '#00FF00', tray_info_idx: 'GFA01', tray_sub_brands: 'PLA Basic', extruder_id: 1 },
  200. ];
  201. render(
  202. <FilamentOverride
  203. filamentReqs={nozzleReqs}
  204. availableFilaments={dualExtruderAvailable}
  205. overrides={{}}
  206. onChange={mockOnChange}
  207. />
  208. );
  209. // 1 default + 1 PLA with extruder_id=0 (extruder_id=1 is filtered out)
  210. const values = optionValues();
  211. expect(values).toHaveLength(2);
  212. expect(values).toContain('PLA|#FF0000');
  213. expect(values).not.toContain('PLA|#00FF00');
  214. });
  215. it('shows all filaments when nozzle_id is undefined', () => {
  216. const noNozzleReqs: FilamentReqsData = {
  217. filaments: [
  218. { slot_id: 1, type: 'PLA', color: '#FF0000', used_grams: 25, used_meters: 8.5 },
  219. ],
  220. };
  221. const mixedExtruderAvailable = [
  222. { type: 'PLA', color: '#FF0000', tray_info_idx: 'GFA00', tray_sub_brands: 'PLA Basic', extruder_id: 0 },
  223. { type: 'PLA', color: '#00FF00', tray_info_idx: 'GFA01', tray_sub_brands: 'PLA Basic', extruder_id: 1 },
  224. ];
  225. render(
  226. <FilamentOverride
  227. filamentReqs={noNozzleReqs}
  228. availableFilaments={mixedExtruderAvailable}
  229. overrides={{}}
  230. onChange={mockOnChange}
  231. />
  232. );
  233. // 1 default + 2 PLA rows (no nozzle filtering)
  234. expect(optionValues()).toHaveLength(3);
  235. });
  236. it('includes filaments with null extruder_id', () => {
  237. const nozzleReqs: FilamentReqsData = {
  238. filaments: [
  239. { slot_id: 1, type: 'PLA', color: '#FF0000', used_grams: 25, used_meters: 8.5, nozzle_id: 0 },
  240. ],
  241. };
  242. const mixedAvailable = [
  243. { type: 'PLA', color: '#FF0000', tray_info_idx: 'GFA00', tray_sub_brands: 'PLA Basic', extruder_id: 0 },
  244. { type: 'PLA', color: '#00FF00', tray_info_idx: 'GFA01', tray_sub_brands: 'PLA Basic', extruder_id: null },
  245. { type: 'PLA', color: '#FFFFFF', tray_info_idx: 'GFA02', tray_sub_brands: 'PLA Basic', extruder_id: 1 },
  246. ];
  247. render(
  248. <FilamentOverride
  249. filamentReqs={nozzleReqs}
  250. availableFilaments={mixedAvailable}
  251. overrides={{}}
  252. onChange={mockOnChange}
  253. />
  254. );
  255. // 1 default + extruder_id=0 + extruder_id=null (extruder_id=1 filtered out)
  256. const values = optionValues();
  257. expect(values).toHaveLength(3);
  258. expect(values).toContain('PLA|#FF0000');
  259. expect(values).toContain('PLA|#00FF00');
  260. expect(values).not.toContain('PLA|#FFFFFF');
  261. });
  262. });
  263. describe('interactions', () => {
  264. it('calls onChange when selecting an override', () => {
  265. render(
  266. <FilamentOverride
  267. filamentReqs={defaultFilamentReqs}
  268. availableFilaments={defaultAvailable}
  269. overrides={{}}
  270. onChange={mockOnChange}
  271. />
  272. );
  273. const row = openPicker().find((o) => o.getAttribute('data-value') === 'PLA|#00FF00');
  274. fireEvent.click(row as HTMLElement);
  275. expect(mockOnChange).toHaveBeenCalledWith({
  276. 1: { type: 'PLA', color: '#00FF00' },
  277. });
  278. });
  279. it('calls onChange to remove override when selecting original', () => {
  280. const activeOverrides = {
  281. 1: { type: 'PLA', color: '#00FF00' },
  282. };
  283. render(
  284. <FilamentOverride
  285. filamentReqs={defaultFilamentReqs}
  286. availableFilaments={defaultAvailable}
  287. overrides={activeOverrides}
  288. onChange={mockOnChange}
  289. />
  290. );
  291. const row = openPicker().find((o) => o.getAttribute('data-value') === '');
  292. fireEvent.click(row as HTMLElement);
  293. expect(mockOnChange).toHaveBeenCalledWith({});
  294. });
  295. });
  296. describe('colour swatches (#3159)', () => {
  297. it('draws the colour of every filament it offers, and of the original', () => {
  298. render(
  299. <FilamentOverride
  300. filamentReqs={defaultFilamentReqs}
  301. availableFilaments={defaultAvailable}
  302. overrides={{}}
  303. onChange={mockOnChange}
  304. />
  305. );
  306. const rows = openPicker();
  307. // The original-filament row plus the two same-type candidates: model
  308. // mode pools across printers, so there is no slot binding behind an
  309. // entry and each swatch is the plain tray colour.
  310. expect(rows).toHaveLength(3);
  311. for (const row of rows) {
  312. expect(within(row).getByTestId('filament-swatch')).toBeInTheDocument();
  313. }
  314. });
  315. it('prints each candidate hex and marks the one the slice asked for', () => {
  316. render(
  317. <FilamentOverride
  318. filamentReqs={defaultFilamentReqs}
  319. availableFilaments={defaultAvailable}
  320. overrides={{}}
  321. onChange={mockOnChange}
  322. />
  323. );
  324. const rows = openPicker();
  325. const listbox = screen.getByRole('listbox');
  326. expect(within(listbox).getByText('#00FF00')).toBeInTheDocument();
  327. // #FF0000 twice: the original-filament row states what the slice asked
  328. // for, and one candidate carries it.
  329. expect(within(listbox).getAllByText('#FF0000')).toHaveLength(2);
  330. // The marker belongs on the candidate, not on the original — it answers
  331. // "which of these is the colour the slice asked for", which is the
  332. // judgement the colour names cannot be trusted to make.
  333. const marked = rows.filter((r) => within(r).queryByTitle('Exact colour match'));
  334. expect(marked).toHaveLength(1);
  335. expect(marked[0].getAttribute('data-value')).toBe('PLA|#FF0000');
  336. });
  337. });
  338. describe('original-label SKU resolution (#1718)', () => {
  339. it('uses the builtin filament name when tray_info_idx maps to a known SKU', async () => {
  340. // Stamped by Bambu Studio when slicing with PLA Matte Charcoal: 3MF
  341. // carries type=PLA + the GFA01 SKU. Without resolution the label
  342. // collapses to "PLA (Black)" which was Sam's bug.
  343. server.use(
  344. http.get('/api/v1/cloud/builtin-filaments', () =>
  345. HttpResponse.json([{ filament_id: 'GFA01', name: 'Bambu PLA Matte' }]),
  346. ),
  347. http.get('/api/v1/cloud/filament-id-map', () => HttpResponse.json({})),
  348. );
  349. const reqs: FilamentReqsData = {
  350. filaments: [
  351. { slot_id: 1, type: 'PLA', color: '#1A1A1A', used_grams: 25, used_meters: 8.5, tray_info_idx: 'GFA01' },
  352. ],
  353. };
  354. render(
  355. <FilamentOverride
  356. filamentReqs={reqs}
  357. availableFilaments={defaultAvailable}
  358. overrides={{}}
  359. onChange={mockOnChange}
  360. />,
  361. );
  362. // Wait for the queries to resolve and the resolved label to land on the
  363. // control, which reads as the "original filament" row while nothing is
  364. // overridden. Reading the closed trigger rather than the open list keeps
  365. // this clear of the swatch tooltip, which carries the same text.
  366. await waitFor(() => expect(triggerText()).toMatch(/Bambu PLA Matte/));
  367. });
  368. it('prefers the cloud user-preset name over the builtin entry for the same id', async () => {
  369. // Cloud user-preset names are more specific than the builtin fallback —
  370. // e.g. a user has renamed GFA00 to "My House PLA".
  371. server.use(
  372. http.get('/api/v1/cloud/builtin-filaments', () =>
  373. HttpResponse.json([{ filament_id: 'GFA00', name: 'Bambu PLA Basic' }]),
  374. ),
  375. http.get('/api/v1/cloud/filament-id-map', () =>
  376. HttpResponse.json({ GFA00: 'My House PLA' }),
  377. ),
  378. );
  379. const reqs: FilamentReqsData = {
  380. filaments: [
  381. { slot_id: 1, type: 'PLA', color: '#FF0000', used_grams: 25, used_meters: 8.5, tray_info_idx: 'GFA00' },
  382. ],
  383. };
  384. render(
  385. <FilamentOverride
  386. filamentReqs={reqs}
  387. availableFilaments={defaultAvailable}
  388. overrides={{}}
  389. onChange={mockOnChange}
  390. />,
  391. );
  392. await waitFor(() => expect(triggerText()).toMatch(/My House PLA/));
  393. // The builtin fallback must NOT bleed through anywhere — neither the
  394. // placeholder option nor the tooltip.
  395. expect(screen.queryByText(/Bambu PLA Basic/)).not.toBeInTheDocument();
  396. });
  397. it('uses the material-disambiguated catalogue color name (PLA Matte Charcoal — #1718 round 2)', async () => {
  398. // Sam's exact case: 3MF carries hex #000000 + tray_info_idx GFA01.
  399. // Without material context, /colors/map collapses #000000 to "Black"
  400. // (PLA Basic wins the priority race). The override panel must pass
  401. // the derived material hint "PLA Matte" through to /colors/by-material
  402. // so the user sees "Charcoal" — the actually-sliced color.
  403. server.use(
  404. http.get('/api/v1/cloud/builtin-filaments', () =>
  405. HttpResponse.json([{ filament_id: 'GFA01', name: 'Bambu PLA Matte' }]),
  406. ),
  407. http.get('/api/v1/cloud/filament-id-map', () => HttpResponse.json({})),
  408. http.get('/api/v1/inventory/colors/by-material', ({ request }) => {
  409. const url = new URL(request.url);
  410. const hex = url.searchParams.get('hex');
  411. const material = url.searchParams.get('material');
  412. if (hex === '#000000' && material === 'PLA Matte') {
  413. return HttpResponse.json({ color_name: 'Charcoal' });
  414. }
  415. return HttpResponse.json({ color_name: null });
  416. }),
  417. );
  418. const reqs: FilamentReqsData = {
  419. filaments: [
  420. { slot_id: 1, type: 'PLA', color: '#000000', used_grams: 25, used_meters: 8.5, tray_info_idx: 'GFA01' },
  421. ],
  422. };
  423. render(
  424. <FilamentOverride
  425. filamentReqs={reqs}
  426. availableFilaments={defaultAvailable}
  427. overrides={{}}
  428. onChange={mockOnChange}
  429. />,
  430. );
  431. await waitFor(() => expect(triggerText()).toMatch(/Bambu PLA Matte \(Charcoal\)/));
  432. });
  433. it('disambiguates per slot when two slots share a hex but differ in material', async () => {
  434. // Regression guard: the per-slot useQueries dispatch must key on
  435. // (hex, material) so a "PLA Matte Charcoal" slot does not adopt the
  436. // "PLA Basic Black" slot's answer.
  437. server.use(
  438. http.get('/api/v1/cloud/builtin-filaments', () =>
  439. HttpResponse.json([
  440. { filament_id: 'GFA00', name: 'Bambu PLA Basic' },
  441. { filament_id: 'GFA01', name: 'Bambu PLA Matte' },
  442. ]),
  443. ),
  444. http.get('/api/v1/cloud/filament-id-map', () => HttpResponse.json({})),
  445. http.get('/api/v1/inventory/colors/by-material', ({ request }) => {
  446. const url = new URL(request.url);
  447. const material = url.searchParams.get('material');
  448. if (material === 'PLA Matte') return HttpResponse.json({ color_name: 'Charcoal' });
  449. if (material === 'PLA Basic') return HttpResponse.json({ color_name: 'Black' });
  450. return HttpResponse.json({ color_name: null });
  451. }),
  452. );
  453. const reqs: FilamentReqsData = {
  454. filaments: [
  455. { slot_id: 1, type: 'PLA', color: '#000000', used_grams: 25, used_meters: 8.5, tray_info_idx: 'GFA01' },
  456. { slot_id: 2, type: 'PLA', color: '#000000', used_grams: 10, used_meters: 3.2, tray_info_idx: 'GFA00' },
  457. ],
  458. };
  459. render(
  460. <FilamentOverride
  461. filamentReqs={reqs}
  462. availableFilaments={defaultAvailable}
  463. overrides={{}}
  464. onChange={mockOnChange}
  465. />,
  466. );
  467. await waitFor(() => {
  468. expect(screen.getAllByRole('combobox')).toHaveLength(2);
  469. expect(triggerText(0)).toMatch(/Bambu PLA Matte \(Charcoal\)/);
  470. expect(triggerText(1)).toMatch(/Bambu PLA Basic \(Black\)/);
  471. });
  472. });
  473. it('falls back to getColorName(hex) when the by-material lookup returns null', async () => {
  474. // Any time the catalogue has no entry for the hex (or the endpoint is
  475. // unreachable), the placeholder must still render — the HSL-bucket
  476. // fallback is strictly better than a blank.
  477. server.use(
  478. http.get('/api/v1/cloud/builtin-filaments', () =>
  479. HttpResponse.json([{ filament_id: 'GFA01', name: 'Bambu PLA Matte' }]),
  480. ),
  481. http.get('/api/v1/cloud/filament-id-map', () => HttpResponse.json({})),
  482. http.get('/api/v1/inventory/colors/by-material', () =>
  483. HttpResponse.json({ color_name: null }),
  484. ),
  485. );
  486. const reqs: FilamentReqsData = {
  487. filaments: [
  488. { slot_id: 1, type: 'PLA', color: '#FF0000', used_grams: 25, used_meters: 8.5, tray_info_idx: 'GFA01' },
  489. ],
  490. };
  491. render(
  492. <FilamentOverride
  493. filamentReqs={reqs}
  494. availableFilaments={defaultAvailable}
  495. overrides={{}}
  496. onChange={mockOnChange}
  497. />,
  498. );
  499. // Wait for the builtin lookup to land so we know the row mounted; the
  500. // colour fallback to getColorName for #FF0000 produces "Red"-shaped text.
  501. await waitFor(() => {
  502. expect(triggerText()).toMatch(/Bambu PLA Matte/);
  503. expect(triggerText()).not.toMatch(/null/);
  504. });
  505. });
  506. it('falls back to the raw type when the SKU is unknown to both maps', async () => {
  507. // Unknown ids must not break rendering — the original "PLA" label is
  508. // still better than a blank.
  509. server.use(
  510. http.get('/api/v1/cloud/builtin-filaments', () => HttpResponse.json([])),
  511. http.get('/api/v1/cloud/filament-id-map', () => HttpResponse.json({})),
  512. );
  513. const reqs: FilamentReqsData = {
  514. filaments: [
  515. { slot_id: 1, type: 'PLA', color: '#FF0000', used_grams: 25, used_meters: 8.5, tray_info_idx: 'GFXXX' },
  516. ],
  517. };
  518. render(
  519. <FilamentOverride
  520. filamentReqs={reqs}
  521. availableFilaments={defaultAvailable}
  522. overrides={{}}
  523. onChange={mockOnChange}
  524. />,
  525. );
  526. // (25g) is the easiest signal the row mounted at all; once it's there,
  527. // assert the placeholder option carries the raw type.
  528. await waitFor(() => {
  529. expect(screen.getByText('(25g)')).toBeInTheDocument();
  530. });
  531. expect(triggerText()).toMatch(/PLA \(/);
  532. });
  533. });
  534. });