SliceModal.test.tsx 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658
  1. /**
  2. * Tests for SliceModal.
  3. *
  4. * The modal handles preset selection across three tiers (cloud / local /
  5. * standard) + enqueueing a slice job. After enqueue success it hands the
  6. * job_id off to SliceJobTrackerProvider (which lives at app level) and
  7. * calls onClose. Polling, toasts, and query invalidation all happen in
  8. * the tracker — not here.
  9. */
  10. import { describe, it, expect, vi, beforeEach } from 'vitest';
  11. import { screen, waitFor, within } from '@testing-library/react';
  12. import userEvent from '@testing-library/user-event';
  13. import { render } from '../utils';
  14. import { SliceModal } from '../../components/SliceModal';
  15. import { pickFilamentForSlot } from '../../utils/slicePresetPicker';
  16. import { buildCompatibilityIndex } from '../../utils/slicerPrinterMatch';
  17. import { SliceJobTrackerProvider } from '../../contexts/SliceJobTrackerContext';
  18. import { api, type UnifiedPresetsResponse } from '../../api/client';
  19. vi.mock('../../api/client', () => ({
  20. api: {
  21. getSlicerPresets: vi.fn(),
  22. sliceLibraryFile: vi.fn(),
  23. sliceArchive: vi.fn(),
  24. getSliceJob: vi.fn(),
  25. getLibraryFilePlates: vi.fn(),
  26. getArchivePlates: vi.fn(),
  27. getLibraryFileFilamentRequirements: vi.fn(),
  28. getArchiveFilamentRequirements: vi.fn(),
  29. getSettings: vi.fn().mockResolvedValue({}),
  30. updateSettings: vi.fn().mockResolvedValue({}),
  31. // Slicer Pipelines (#1425)
  32. listSlicerPipelines: vi.fn(),
  33. createSlicerPipeline: vi.fn(),
  34. },
  35. }));
  36. const mockApi = api as unknown as {
  37. getSlicerPresets: ReturnType<typeof vi.fn>;
  38. sliceLibraryFile: ReturnType<typeof vi.fn>;
  39. sliceArchive: ReturnType<typeof vi.fn>;
  40. getSliceJob: ReturnType<typeof vi.fn>;
  41. getLibraryFilePlates: ReturnType<typeof vi.fn>;
  42. getArchivePlates: ReturnType<typeof vi.fn>;
  43. getLibraryFileFilamentRequirements: ReturnType<typeof vi.fn>;
  44. getArchiveFilamentRequirements: ReturnType<typeof vi.fn>;
  45. listSlicerPipelines: ReturnType<typeof vi.fn>;
  46. createSlicerPipeline: ReturnType<typeof vi.fn>;
  47. };
  48. function makeUnified(overrides: Partial<UnifiedPresetsResponse> = {}): UnifiedPresetsResponse {
  49. return {
  50. orca_cloud: { printer: [], process: [], filament: [] },
  51. cloud: { printer: [], process: [], filament: [] },
  52. local: { printer: [], process: [], filament: [] },
  53. standard: { printer: [], process: [], filament: [] },
  54. cloud_status: 'ok',
  55. orca_cloud_status: 'ok',
  56. ...overrides,
  57. };
  58. }
  59. const fullThreeTier: UnifiedPresetsResponse = makeUnified({
  60. cloud: {
  61. printer: [{ id: 'PFUcloud-printer', name: 'My Custom X1C', source: 'cloud' }],
  62. process: [{ id: 'PFUcloud-process', name: 'My 0.16mm Tweaked', source: 'cloud' }],
  63. filament: [{ id: 'PFUcloud-filament', name: 'My PLA Black', source: 'cloud' }],
  64. },
  65. local: {
  66. printer: [{ id: '1', name: 'Imported X1C 0.4', source: 'local' }],
  67. process: [{ id: '2', name: 'Imported 0.20mm', source: 'local' }],
  68. filament: [{ id: '3', name: 'Imported PLA Basic', source: 'local' }],
  69. },
  70. standard: {
  71. printer: [{ id: 'Bambu Lab X1 Carbon 0.4 nozzle', name: 'Bambu Lab X1 Carbon 0.4 nozzle', source: 'standard' }],
  72. process: [{ id: '0.20mm Standard', name: '0.20mm Standard', source: 'standard' }],
  73. filament: [{ id: 'Bambu PLA Basic', name: 'Bambu PLA Basic', source: 'standard' }],
  74. },
  75. });
  76. function renderWithTracker(props: Parameters<typeof SliceModal>[0]) {
  77. return render(
  78. <SliceJobTrackerProvider>
  79. <SliceModal {...props} />
  80. </SliceJobTrackerProvider>,
  81. );
  82. }
  83. // SliceModal renders one extra combobox for the Slicer Pipelines (#1425)
  84. // "Apply pipeline" dropdown above the preset slots. Tests written before
  85. // pipelines landed assume selects[0] = printer; this helper drops the
  86. // pipeline combobox so those indices stay stable.
  87. function presetSelects(): HTMLSelectElement[] {
  88. return (screen.getAllByRole('combobox') as HTMLSelectElement[]).filter(
  89. (el) => el.getAttribute('aria-label') !== 'Apply pipeline',
  90. );
  91. }
  92. describe('SliceModal', () => {
  93. beforeEach(() => {
  94. vi.clearAllMocks();
  95. mockApi.getSlicerPresets.mockResolvedValue(fullThreeTier);
  96. mockApi.getSliceJob.mockResolvedValue({
  97. job_id: 42,
  98. status: 'running',
  99. kind: 'library_file',
  100. source_id: 100,
  101. source_name: 'Cube.stl',
  102. created_at: new Date().toISOString(),
  103. started_at: null,
  104. completed_at: null,
  105. });
  106. // Default: single-plate (or non-3MF). Multi-plate tests override this.
  107. mockApi.getLibraryFilePlates.mockResolvedValue({
  108. file_id: 100,
  109. filename: 'Cube.stl',
  110. plates: [],
  111. is_multi_plate: false,
  112. });
  113. mockApi.getArchivePlates.mockResolvedValue({
  114. archive_id: 100,
  115. filename: 'Cube.3mf',
  116. plates: [],
  117. is_multi_plate: false,
  118. });
  119. // Default: no per-plate filament metadata available (mirrors STL or
  120. // unsliced source). Multi-color tests override this.
  121. mockApi.getLibraryFileFilamentRequirements.mockResolvedValue({
  122. file_id: 100,
  123. filename: 'Cube.stl',
  124. plate_id: 1,
  125. filaments: [],
  126. });
  127. mockApi.getArchiveFilamentRequirements.mockResolvedValue({
  128. archive_id: 100,
  129. filename: 'Cube.3mf',
  130. plate_id: 1,
  131. filaments: [],
  132. });
  133. // Default: no saved pipelines. Tests opt in by overriding this.
  134. mockApi.listSlicerPipelines.mockResolvedValue({ pipelines: [] });
  135. });
  136. it('auto-selects the highest-priority tier per slot on first load', async () => {
  137. renderWithTracker({
  138. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  139. onClose: vi.fn(),
  140. });
  141. // SliceModal-specific tier priority: imported (local) wins over cloud
  142. // and standard so the user's curated picks come first.
  143. await waitFor(() => {
  144. expect(screen.getByText('My Custom X1C')).toBeDefined();
  145. });
  146. // 4 selects: printer, process, bed-type (#1337), filament. bed-type sits
  147. // between process and filament — it overrides curr_bed_type on the
  148. // process preset so the related controls cluster — and defaults to "".
  149. const selects = presetSelects();
  150. expect(selects).toHaveLength(4);
  151. expect(selects[0].value).toBe('local:1');
  152. expect(selects[1].value).toBe('local:2');
  153. expect(selects[2].value).toBe('');
  154. expect(selects[3].value).toBe('local:3');
  155. // Slice button is enabled because all three slots auto-defaulted and
  156. // the preview-slice query has resolved (mock returns immediately).
  157. const sliceBtn = screen.getByRole('button', { name: /^Slice$/ });
  158. expect((sliceBtn as HTMLButtonElement).disabled).toBe(false);
  159. });
  160. it('renders Imported / Cloud / Standard sections via <optgroup>', async () => {
  161. renderWithTracker({
  162. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  163. onClose: vi.fn(),
  164. });
  165. await waitFor(() => expect(screen.getByText('Imported X1C 0.4')).toBeDefined());
  166. const printerSelect = presetSelects()[0];
  167. const groups = printerSelect.querySelectorAll('optgroup');
  168. expect(Array.from(groups).map((g) => g.label)).toEqual([
  169. 'Imported',
  170. 'Bambu Cloud',
  171. 'Standard',
  172. ]);
  173. // Each entry sits inside its own tier's group — pin the assignment so
  174. // a future render-shape change can't quietly mix them. Order matches
  175. // SLICE_MODAL_TIER_ORDER (local → cloud → standard).
  176. const localGroup = groups[0];
  177. expect(within(localGroup as HTMLElement).getByText('Imported X1C 0.4')).toBeDefined();
  178. const cloudGroup = groups[1];
  179. expect(within(cloudGroup as HTMLElement).getByText('My Custom X1C')).toBeDefined();
  180. const standardGroup = groups[2];
  181. expect(within(standardGroup as HTMLElement).getByText('Bambu Lab X1 Carbon 0.4 nozzle')).toBeDefined();
  182. });
  183. it('falls back to local when cloud is empty (auto-pick respects priority)', async () => {
  184. mockApi.getSlicerPresets.mockResolvedValue(
  185. makeUnified({
  186. local: fullThreeTier.local,
  187. standard: fullThreeTier.standard,
  188. }),
  189. );
  190. renderWithTracker({
  191. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  192. onClose: vi.fn(),
  193. });
  194. await waitFor(() => expect(screen.getByText('Imported X1C 0.4')).toBeDefined());
  195. const selects = presetSelects();
  196. expect(selects[0].value).toBe('local:1');
  197. });
  198. it('falls back to standard when both cloud and local are empty', async () => {
  199. mockApi.getSlicerPresets.mockResolvedValue(
  200. makeUnified({ standard: fullThreeTier.standard }),
  201. );
  202. renderWithTracker({
  203. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  204. onClose: vi.fn(),
  205. });
  206. await waitFor(() => expect(screen.getByText('Bambu Lab X1 Carbon 0.4 nozzle')).toBeDefined());
  207. const selects = presetSelects();
  208. expect(selects[0].value).toBe('standard:Bambu Lab X1 Carbon 0.4 nozzle');
  209. });
  210. it('sends source-aware refs (not legacy bare ints) on submit', async () => {
  211. const onClose = vi.fn();
  212. mockApi.sliceLibraryFile.mockResolvedValue({
  213. job_id: 42,
  214. status: 'pending',
  215. status_url: '/api/v1/slice-jobs/42',
  216. });
  217. renderWithTracker({
  218. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  219. onClose,
  220. });
  221. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  222. const user = userEvent.setup();
  223. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  224. await waitFor(() => {
  225. // SliceModal-specific tier priority puts imported (local) above cloud,
  226. // so the auto-pick lands on the local entries even when a cloud entry
  227. // with the same slot is also available in the listing.
  228. expect(mockApi.sliceLibraryFile).toHaveBeenCalledWith(100, {
  229. printer_preset: { source: 'local', id: '1' },
  230. process_preset: { source: 'local', id: '2' },
  231. filament_preset: { source: 'local', id: '3' },
  232. filament_presets: [{ source: 'local', id: '3' }],
  233. });
  234. });
  235. await waitFor(() => expect(onClose).toHaveBeenCalled());
  236. });
  237. it('offers "use the file\'s built-in settings" when the printer matches the design, and sends the flag (#2611)', async () => {
  238. const onClose = vi.fn();
  239. mockApi.sliceLibraryFile.mockResolvedValue({
  240. job_id: 42,
  241. status: 'pending',
  242. status_url: '/api/v1/slice-jobs/42',
  243. });
  244. // A project 3MF whose embedded printer matches a listed preset — the
  245. // printer pre-pick lands on it, so selectedPrinterName === embedded and
  246. // the "slice as designed" toggle is offered.
  247. mockApi.getLibraryFilePlates.mockResolvedValue({
  248. file_id: 100,
  249. filename: 'Designed.3mf',
  250. plates: [],
  251. is_multi_plate: false,
  252. embedded_printer: 'Bambu Lab X1 Carbon 0.4 nozzle',
  253. embedded_process: '0.20mm Standard',
  254. });
  255. renderWithTracker({
  256. source: { kind: 'libraryFile', id: 100, filename: 'Designed.3mf' },
  257. onClose,
  258. });
  259. const user = userEvent.setup();
  260. const toggle = (await screen.findByLabelText(
  261. /Use the file's built-in settings/,
  262. )) as HTMLInputElement;
  263. expect(toggle.checked).toBe(false);
  264. // All preset dropdowns are live until the toggle is on, then bypassed —
  265. // the printer included, so changing it can't silently drop the mode.
  266. const printerSelect = presetSelects()[0];
  267. const processSelect = presetSelects()[1];
  268. expect(printerSelect.disabled).toBe(false);
  269. expect(processSelect.disabled).toBe(false);
  270. await user.click(toggle);
  271. expect(printerSelect.disabled).toBe(true);
  272. expect(processSelect.disabled).toBe(true);
  273. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  274. await waitFor(() => {
  275. expect(mockApi.sliceLibraryFile).toHaveBeenCalledWith(
  276. 100,
  277. expect.objectContaining({ use_embedded_settings: true }),
  278. );
  279. });
  280. await waitFor(() => expect(onClose).toHaveBeenCalled());
  281. });
  282. it('hides the embedded-settings toggle when the picked printer differs from the design (#2611)', async () => {
  283. // Embedded target is a model with no matching preset in the listing, so
  284. // the printer pre-pick falls back to the local default (Imported X1C),
  285. // which does not match — honouring embedded settings would risk the
  286. // wrong bed, so the toggle stays hidden.
  287. mockApi.getLibraryFilePlates.mockResolvedValue({
  288. file_id: 100,
  289. filename: 'Designed.3mf',
  290. plates: [],
  291. is_multi_plate: false,
  292. embedded_printer: 'Bambu Lab P1S 0.4 nozzle',
  293. embedded_process: '0.20mm Standard',
  294. });
  295. renderWithTracker({
  296. source: { kind: 'libraryFile', id: 100, filename: 'Designed.3mf' },
  297. onClose: vi.fn(),
  298. });
  299. await waitFor(() => expect(screen.getByText('Imported X1C 0.4')).toBeDefined());
  300. expect(screen.queryByLabelText(/Use the file's built-in settings/)).toBeNull();
  301. });
  302. // #2622: a MakerWorld 3MF designed for another printer carries the author's
  303. // own process tweaks. BambuStudio records which keys deviate from the stock
  304. // preset inside the file, so a cross-printer re-slice can carry them instead
  305. // of losing them to the picked process profile.
  306. const designedFor = {
  307. file_id: 100,
  308. filename: 'Designed.3mf',
  309. plates: [],
  310. is_multi_plate: false,
  311. embedded_printer: 'Bambu Lab A1 0.4 nozzle',
  312. embedded_process: '0.20mm Standard @BBL A1',
  313. design_overrides: [
  314. { key: 'wall_loops', value: '5', printer_coupled: false },
  315. { key: 'sparse_infill_density', value: '100%', printer_coupled: false },
  316. { key: 'outer_wall_speed', value: '200', printer_coupled: true },
  317. ],
  318. };
  319. async function openDesignSection() {
  320. const user = userEvent.setup();
  321. await user.click(await screen.findByText(/Keep the designer's settings/));
  322. return user;
  323. }
  324. it("carries the design's printer-independent settings by default (#2622)", async () => {
  325. mockApi.sliceLibraryFile.mockResolvedValue({
  326. job_id: 42,
  327. status: 'pending',
  328. status_url: '/api/v1/slice-jobs/42',
  329. });
  330. mockApi.getLibraryFilePlates.mockResolvedValue(designedFor);
  331. renderWithTracker({
  332. source: { kind: 'libraryFile', id: 100, filename: 'Designed.3mf' },
  333. onClose: vi.fn(),
  334. });
  335. // Two of three pre-selected: the speed key is machine-coupled.
  336. expect(await screen.findByText('2 of 3 selected')).toBeInTheDocument();
  337. const user = userEvent.setup();
  338. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  339. await waitFor(() => expect(mockApi.sliceLibraryFile).toHaveBeenCalled());
  340. const payload = mockApi.sliceLibraryFile.mock.calls[0][1] as { design_overrides?: string[] };
  341. expect([...(payload.design_overrides ?? [])].sort()).toEqual(['sparse_infill_density', 'wall_loops']);
  342. });
  343. it('lists every changed setting with its value and flags the machine-coupled ones (#2622)', async () => {
  344. mockApi.getLibraryFilePlates.mockResolvedValue(designedFor);
  345. renderWithTracker({
  346. source: { kind: 'libraryFile', id: 100, filename: 'Designed.3mf' },
  347. onClose: vi.fn(),
  348. });
  349. await openDesignSection();
  350. expect(screen.getByText('wall_loops')).toBeInTheDocument();
  351. expect(screen.getByText('5')).toBeInTheDocument();
  352. expect(screen.getByText('sparse_infill_density')).toBeInTheDocument();
  353. expect(screen.getByText('100%')).toBeInTheDocument();
  354. // The risky one is listed too — visible, explained, just not pre-ticked.
  355. expect(screen.getByText('outer_wall_speed')).toBeInTheDocument();
  356. expect(screen.getByText('printer-specific')).toBeInTheDocument();
  357. });
  358. it('lets the user opt a machine-coupled setting in and a safe one out (#2622)', async () => {
  359. mockApi.sliceLibraryFile.mockResolvedValue({
  360. job_id: 42,
  361. status: 'pending',
  362. status_url: '/api/v1/slice-jobs/42',
  363. });
  364. mockApi.getLibraryFilePlates.mockResolvedValue(designedFor);
  365. renderWithTracker({
  366. source: { kind: 'libraryFile', id: 100, filename: 'Designed.3mf' },
  367. onClose: vi.fn(),
  368. });
  369. const user = await openDesignSection();
  370. const boxes = screen.getAllByRole('checkbox') as HTMLInputElement[];
  371. const byKey = (key: string) =>
  372. boxes.find((b) => b.closest('label')?.textContent?.includes(key)) as HTMLInputElement;
  373. await user.click(byKey('outer_wall_speed'));
  374. await user.click(byKey('wall_loops'));
  375. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  376. await waitFor(() => expect(mockApi.sliceLibraryFile).toHaveBeenCalled());
  377. const payload = mockApi.sliceLibraryFile.mock.calls[0][1] as { design_overrides?: string[] };
  378. expect([...(payload.design_overrides ?? [])].sort()).toEqual(['outer_wall_speed', 'sparse_infill_density']);
  379. });
  380. it('omits design_overrides entirely when the user unticks everything (#2622)', async () => {
  381. mockApi.sliceLibraryFile.mockResolvedValue({
  382. job_id: 42,
  383. status: 'pending',
  384. status_url: '/api/v1/slice-jobs/42',
  385. });
  386. mockApi.getLibraryFilePlates.mockResolvedValue(designedFor);
  387. renderWithTracker({
  388. source: { kind: 'libraryFile', id: 100, filename: 'Designed.3mf' },
  389. onClose: vi.fn(),
  390. });
  391. const user = await openDesignSection();
  392. const boxes = screen.getAllByRole('checkbox') as HTMLInputElement[];
  393. for (const box of boxes) {
  394. if (box.checked) await user.click(box);
  395. }
  396. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  397. await waitFor(() => expect(mockApi.sliceLibraryFile).toHaveBeenCalled());
  398. expect(mockApi.sliceLibraryFile.mock.calls[0][1]).not.toHaveProperty('design_overrides');
  399. });
  400. it('hides the section for a file that changes nothing (#2622)', async () => {
  401. mockApi.getLibraryFilePlates.mockResolvedValue({ ...designedFor, design_overrides: [] });
  402. renderWithTracker({
  403. source: { kind: 'libraryFile', id: 100, filename: 'Designed.3mf' },
  404. onClose: vi.fn(),
  405. });
  406. await waitFor(() => expect(screen.getByRole('button', { name: /^Slice$/ })).toBeEnabled());
  407. expect(screen.queryByText(/Keep the designer's settings/)).toBeNull();
  408. });
  409. it('includes bed_type in the request when the user picks a non-auto plate (#1337)', async () => {
  410. const onClose = vi.fn();
  411. mockApi.sliceLibraryFile.mockResolvedValue({
  412. job_id: 42,
  413. status: 'pending',
  414. status_url: '/api/v1/slice-jobs/42',
  415. });
  416. renderWithTracker({
  417. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  418. onClose,
  419. });
  420. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  421. const user = userEvent.setup();
  422. // Order with the dropdown now sits between Process and Filament:
  423. // printer (0), process (1), bed-type (2), filament (3+). Find the
  424. // bed-type select by name rather than positional index so this stays
  425. // green if the layout adds another control around it.
  426. const bedSelect = presetSelects().find((el) =>
  427. (el as HTMLSelectElement).options[0]?.textContent?.toLowerCase().includes('auto'),
  428. ) as HTMLSelectElement;
  429. expect(bedSelect).toBeDefined();
  430. await user.selectOptions(bedSelect, 'Textured PEI Plate');
  431. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  432. await waitFor(() => {
  433. expect(mockApi.sliceLibraryFile).toHaveBeenCalledWith(
  434. 100,
  435. expect.objectContaining({ bed_type: 'Textured PEI Plate' }),
  436. );
  437. });
  438. });
  439. it('omits bed_type when the user leaves it on Auto (no override)', async () => {
  440. const onClose = vi.fn();
  441. mockApi.sliceLibraryFile.mockResolvedValue({
  442. job_id: 42,
  443. status: 'pending',
  444. status_url: '/api/v1/slice-jobs/42',
  445. });
  446. renderWithTracker({
  447. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  448. onClose,
  449. });
  450. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  451. const user = userEvent.setup();
  452. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  453. await waitFor(() => {
  454. const [, body] = vi.mocked(mockApi.sliceLibraryFile).mock.calls[0];
  455. expect(body).not.toHaveProperty('bed_type');
  456. });
  457. });
  458. it('lets the user override the default and pick a Standard preset', async () => {
  459. const onClose = vi.fn();
  460. mockApi.sliceLibraryFile.mockResolvedValue({
  461. job_id: 42,
  462. status: 'pending',
  463. status_url: '/api/v1/slice-jobs/42',
  464. });
  465. renderWithTracker({
  466. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  467. onClose,
  468. });
  469. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  470. const user = userEvent.setup();
  471. const selects = presetSelects();
  472. await user.selectOptions(selects[0], 'standard:Bambu Lab X1 Carbon 0.4 nozzle');
  473. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  474. await waitFor(() => {
  475. expect(mockApi.sliceLibraryFile).toHaveBeenCalledWith(
  476. 100,
  477. expect.objectContaining({
  478. printer_preset: { source: 'standard', id: 'Bambu Lab X1 Carbon 0.4 nozzle' },
  479. }),
  480. );
  481. });
  482. });
  483. it('routes archive sources to sliceArchive instead of sliceLibraryFile', async () => {
  484. const onClose = vi.fn();
  485. mockApi.sliceArchive.mockResolvedValue({
  486. job_id: 7,
  487. status: 'pending',
  488. status_url: '/api/v1/slice-jobs/7',
  489. });
  490. renderWithTracker({
  491. source: { kind: 'archive', id: 86, filename: 'orca.3mf' },
  492. onClose,
  493. });
  494. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  495. const user = userEvent.setup();
  496. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  497. await waitFor(() => {
  498. expect(mockApi.sliceArchive).toHaveBeenCalledWith(86, expect.any(Object));
  499. expect(mockApi.sliceLibraryFile).not.toHaveBeenCalled();
  500. });
  501. });
  502. it('surfaces enqueue errors inline and keeps the modal open', async () => {
  503. const onClose = vi.fn();
  504. mockApi.sliceLibraryFile.mockRejectedValue(new Error('Server says no'));
  505. renderWithTracker({
  506. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  507. onClose,
  508. });
  509. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  510. const user = userEvent.setup();
  511. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  512. await waitFor(() => {
  513. expect(screen.getByRole('alert')).toHaveTextContent('Server says no');
  514. });
  515. expect(onClose).not.toHaveBeenCalled();
  516. });
  517. it('shows a friendly notice when getSlicerPresets fails', async () => {
  518. mockApi.getSlicerPresets.mockRejectedValue(new Error('500'));
  519. renderWithTracker({
  520. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  521. onClose: vi.fn(),
  522. });
  523. await waitFor(() => {
  524. expect(screen.getByRole('alert')).toHaveTextContent(/Failed to load presets/i);
  525. });
  526. });
  527. it('omits the cloud banner when status is not_authenticated (#1712)', async () => {
  528. // A signed-out user (Bambu or Orca) shouldn't get a permanent "sign in"
  529. // nag at the top of every slice. Sign-in lives on the Profiles page; the
  530. // modal stays silent unless a previously-signed-in session actually broke
  531. // (expired / unreachable).
  532. mockApi.getSlicerPresets.mockResolvedValue(
  533. makeUnified({
  534. cloud_status: 'not_authenticated',
  535. orca_cloud_status: 'not_authenticated',
  536. local: fullThreeTier.local,
  537. standard: fullThreeTier.standard,
  538. }),
  539. );
  540. renderWithTracker({
  541. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  542. onClose: vi.fn(),
  543. });
  544. await waitFor(() => expect(screen.getByText('Imported X1C 0.4')).toBeDefined());
  545. expect(screen.queryByRole('status')).toBeNull();
  546. });
  547. it('renders an "expired" banner when cloud_status is expired', async () => {
  548. mockApi.getSlicerPresets.mockResolvedValue(
  549. makeUnified({
  550. cloud_status: 'expired',
  551. local: fullThreeTier.local,
  552. }),
  553. );
  554. renderWithTracker({
  555. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  556. onClose: vi.fn(),
  557. });
  558. await waitFor(() => {
  559. expect(screen.getByRole('status')).toHaveTextContent(/expired/i);
  560. });
  561. });
  562. it('omits the banner entirely when cloud_status is ok', async () => {
  563. renderWithTracker({
  564. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  565. onClose: vi.fn(),
  566. });
  567. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  568. // No status-role banner should be rendered on the happy path.
  569. expect(screen.queryByRole('status')).toBeNull();
  570. });
  571. // ----- Multi-plate flow -----------------------------------------------
  572. function makeMultiPlateLibraryResponse() {
  573. return {
  574. file_id: 100,
  575. filename: 'Multi.3mf',
  576. is_multi_plate: true,
  577. plates: [
  578. {
  579. index: 1,
  580. name: 'Plate 1',
  581. objects: ['Cube'],
  582. object_count: 1,
  583. has_thumbnail: false,
  584. thumbnail_url: null,
  585. print_time_seconds: 600,
  586. filament_used_grams: 10,
  587. filaments: [],
  588. },
  589. {
  590. index: 2,
  591. name: 'Plate 2',
  592. objects: ['Pyramid'],
  593. object_count: 1,
  594. has_thumbnail: false,
  595. thumbnail_url: null,
  596. print_time_seconds: 800,
  597. filament_used_grams: 12,
  598. filaments: [],
  599. },
  600. ],
  601. };
  602. }
  603. it('shows the plate picker first for multi-plate library files', async () => {
  604. mockApi.getLibraryFilePlates.mockResolvedValue(makeMultiPlateLibraryResponse());
  605. renderWithTracker({
  606. source: { kind: 'libraryFile', id: 100, filename: 'Multi.3mf' },
  607. onClose: vi.fn(),
  608. });
  609. // Plate picker renders one button per plate — the accessible name
  610. // joins the heading ("Plate N — name") with the object summary line.
  611. await screen.findByRole('button', { name: /Plate 1.*Cube/ });
  612. expect(screen.getByRole('button', { name: /Plate 2.*Pyramid/ })).toBeDefined();
  613. // Profile dropdowns must NOT be visible yet — the user has to pick a
  614. // plate first.
  615. expect(screen.queryByRole('combobox')).toBeNull();
  616. });
  617. it('skips the plate picker for single-plate sources', async () => {
  618. mockApi.getLibraryFilePlates.mockResolvedValue({
  619. file_id: 100,
  620. filename: 'Single.3mf',
  621. is_multi_plate: false,
  622. plates: [
  623. {
  624. index: 1,
  625. name: 'Plate 1',
  626. objects: [],
  627. has_thumbnail: false,
  628. thumbnail_url: null,
  629. print_time_seconds: null,
  630. filament_used_grams: null,
  631. filaments: [],
  632. },
  633. ],
  634. });
  635. renderWithTracker({
  636. source: { kind: 'libraryFile', id: 100, filename: 'Single.3mf' },
  637. onClose: vi.fn(),
  638. });
  639. // Should jump straight to the profile dropdowns.
  640. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  641. });
  642. it('passes the picked plate to the slice request', async () => {
  643. mockApi.getLibraryFilePlates.mockResolvedValue(makeMultiPlateLibraryResponse());
  644. mockApi.sliceLibraryFile.mockResolvedValue({
  645. job_id: 42,
  646. status: 'pending',
  647. status_url: '/api/v1/slice-jobs/42',
  648. });
  649. renderWithTracker({
  650. source: { kind: 'libraryFile', id: 100, filename: 'Multi.3mf' },
  651. onClose: vi.fn(),
  652. });
  653. const user = userEvent.setup();
  654. // Step 1: pick Plate 2.
  655. const plate2Button = await screen.findByRole('button', { name: /Plate 2.*Pyramid/ });
  656. await user.click(plate2Button);
  657. // Step 2: profile dropdowns are now visible.
  658. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  659. // Step 3: submit and verify the plate index made it into the body.
  660. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  661. await waitFor(() => {
  662. expect(mockApi.sliceLibraryFile).toHaveBeenCalledWith(
  663. 100,
  664. expect.objectContaining({ plate: 2 }),
  665. );
  666. });
  667. });
  668. it('"Slice all plates" toggle sends plate=0 sentinel to the backend (#1493)', async () => {
  669. mockApi.getLibraryFilePlates.mockResolvedValue(makeMultiPlateLibraryResponse());
  670. mockApi.sliceLibraryFile.mockResolvedValue({
  671. job_id: 42,
  672. status: 'pending',
  673. status_url: '/api/v1/slice-jobs/42',
  674. });
  675. renderWithTracker({
  676. source: { kind: 'libraryFile', id: 100, filename: 'Multi.3mf' },
  677. onClose: vi.fn(),
  678. });
  679. const user = userEvent.setup();
  680. const plate1Button = await screen.findByRole('button', { name: /Plate 1.*Cube/ });
  681. await user.click(plate1Button);
  682. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  683. // The "Slice all plates" checkbox only appears for multi-plate sources.
  684. const toggle = await screen.findByRole('checkbox', { name: /Slice all 2 plates/i });
  685. await user.click(toggle);
  686. // The action button's label flips to the "Slice all" form. Click it.
  687. await user.click(screen.getByRole('button', { name: /Slice all 2 plates/i }));
  688. await waitFor(() => {
  689. expect(mockApi.sliceLibraryFile).toHaveBeenCalledTimes(1);
  690. });
  691. const [, body] = mockApi.sliceLibraryFile.mock.calls[0];
  692. // ``plate=0`` is the BS CLI's all-plates sentinel — one slice call,
  693. // one output 3MF with every plate's gcode inside, one archive.
  694. expect((body as { plate?: number }).plate).toBe(0);
  695. });
  696. it('"Slice all plates" toggle is hidden for single-plate sources', async () => {
  697. mockApi.getLibraryFilePlates.mockResolvedValue({
  698. file_id: 100,
  699. filename: 'Single.3mf',
  700. is_multi_plate: false,
  701. plates: [
  702. {
  703. index: 1,
  704. name: 'Plate 1',
  705. objects: [],
  706. has_thumbnail: false,
  707. thumbnail_url: null,
  708. print_time_seconds: null,
  709. filament_used_grams: null,
  710. filaments: [],
  711. },
  712. ],
  713. });
  714. renderWithTracker({
  715. source: { kind: 'libraryFile', id: 100, filename: 'Single.3mf' },
  716. onClose: vi.fn(),
  717. });
  718. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  719. expect(screen.queryByRole('checkbox', { name: /Slice all/i })).toBeNull();
  720. });
  721. it('routes the plate fetch through getArchivePlates for archive sources', async () => {
  722. mockApi.getArchivePlates.mockResolvedValue({
  723. ...makeMultiPlateLibraryResponse(),
  724. archive_id: 100,
  725. filename: 'Multi.3mf',
  726. });
  727. renderWithTracker({
  728. source: { kind: 'archive', id: 100, filename: 'Multi.3mf' },
  729. onClose: vi.fn(),
  730. });
  731. await screen.findByRole('button', { name: /Plate 1.*Cube/ });
  732. expect(mockApi.getArchivePlates).toHaveBeenCalledWith(100);
  733. expect(mockApi.getLibraryFilePlates).not.toHaveBeenCalled();
  734. });
  735. it('cancelling the plate picker closes the entire slice flow', async () => {
  736. const onClose = vi.fn();
  737. mockApi.getLibraryFilePlates.mockResolvedValue(makeMultiPlateLibraryResponse());
  738. renderWithTracker({
  739. source: { kind: 'libraryFile', id: 100, filename: 'Multi.3mf' },
  740. onClose,
  741. });
  742. await screen.findByRole('button', { name: /Plate 1.*Cube/ });
  743. const user = userEvent.setup();
  744. await user.click(screen.getByRole('button', { name: /^Close$/i }));
  745. expect(onClose).toHaveBeenCalled();
  746. });
  747. it('omits the plate field when the source is single-plate', async () => {
  748. mockApi.sliceLibraryFile.mockResolvedValue({
  749. job_id: 42,
  750. status: 'pending',
  751. status_url: '/api/v1/slice-jobs/42',
  752. });
  753. renderWithTracker({
  754. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  755. onClose: vi.fn(),
  756. });
  757. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  758. const user = userEvent.setup();
  759. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  760. await waitFor(() => {
  761. const [, body] = mockApi.sliceLibraryFile.mock.calls[0];
  762. expect(body).not.toHaveProperty('plate');
  763. });
  764. });
  765. // ----- Multi-color flow ------------------------------------------------
  766. function makeMultiColorPlateResponse() {
  767. // Single-plate 3MF that uses two filament slots — mirrors the realistic
  768. // "I have a multi-color file with one plate" case. Multi-plate is a
  769. // separate axis that's already covered above.
  770. return {
  771. file_id: 100,
  772. filename: 'TwoColor.3mf',
  773. is_multi_plate: false,
  774. plates: [
  775. {
  776. index: 1,
  777. name: 'Plate 1',
  778. objects: ['Logo'],
  779. object_count: 1,
  780. has_thumbnail: false,
  781. thumbnail_url: null,
  782. print_time_seconds: 600,
  783. filament_used_grams: 20,
  784. filaments: [],
  785. },
  786. ],
  787. };
  788. }
  789. function makeMultiColorRequirementsResponse() {
  790. return {
  791. file_id: 100,
  792. filename: 'TwoColor.3mf',
  793. plate_id: 1,
  794. filaments: [
  795. { slot_id: 1, type: 'PLA', color: '#000000', used_grams: 10, used_meters: 3 },
  796. { slot_id: 2, type: 'PLA', color: '#FFFFFF', used_grams: 10, used_meters: 3 },
  797. ],
  798. };
  799. }
  800. function makeColorAwarePresets(): UnifiedPresetsResponse {
  801. // Two filament presets in cloud: one black PLA, one white PLA. Pre-pick
  802. // should match each plate slot to the same-colour preset so the user
  803. // doesn't have to manually align them.
  804. return {
  805. orca_cloud: { printer: [], process: [], filament: [] },
  806. cloud: {
  807. printer: [{ id: 'P1', name: 'X1C', source: 'cloud' }],
  808. process: [{ id: 'PR1', name: '0.20mm', source: 'cloud' }],
  809. filament: [
  810. { id: 'F-BLACK', name: 'Cloud PLA Black', source: 'cloud', filament_type: 'PLA', filament_colour: '#000000' },
  811. { id: 'F-WHITE', name: 'Cloud PLA White', source: 'cloud', filament_type: 'PLA', filament_colour: '#FFFFFF' },
  812. ],
  813. },
  814. local: { printer: [], process: [], filament: [] },
  815. standard: { printer: [], process: [], filament: [] },
  816. cloud_status: 'ok',
  817. orca_cloud_status: 'ok',
  818. };
  819. }
  820. it('renders one filament dropdown per plate slot when the source is multi-color', async () => {
  821. mockApi.getLibraryFilePlates.mockResolvedValue(makeMultiColorPlateResponse());
  822. mockApi.getLibraryFileFilamentRequirements.mockResolvedValue(makeMultiColorRequirementsResponse());
  823. mockApi.getSlicerPresets.mockResolvedValue(makeColorAwarePresets());
  824. renderWithTracker({
  825. source: { kind: 'libraryFile', id: 100, filename: 'TwoColor.3mf' },
  826. onClose: vi.fn(),
  827. });
  828. await waitFor(() => expect(screen.getByText('X1C')).toBeDefined());
  829. // 1 printer + 1 process + 2 filament + 1 bed-type (#1337) = 5 dropdowns.
  830. expect(presetSelects()).toHaveLength(5);
  831. });
  832. it('pre-picks each filament slot by matching colour metadata', async () => {
  833. mockApi.getLibraryFilePlates.mockResolvedValue(makeMultiColorPlateResponse());
  834. mockApi.getLibraryFileFilamentRequirements.mockResolvedValue(makeMultiColorRequirementsResponse());
  835. mockApi.getSlicerPresets.mockResolvedValue(makeColorAwarePresets());
  836. mockApi.sliceLibraryFile.mockResolvedValue({
  837. job_id: 42,
  838. status: 'pending',
  839. status_url: '/api/v1/slice-jobs/42',
  840. });
  841. renderWithTracker({
  842. source: { kind: 'libraryFile', id: 100, filename: 'TwoColor.3mf' },
  843. onClose: vi.fn(),
  844. });
  845. await waitFor(() => expect(screen.getByText('X1C')).toBeDefined());
  846. const user = userEvent.setup();
  847. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  848. await waitFor(() => {
  849. const [, body] = mockApi.sliceLibraryFile.mock.calls[0];
  850. // Slot 1 was black plate → cloud black preset; slot 2 was white →
  851. // cloud white preset. Pre-pick aligns them by metadata so the user
  852. // doesn't have to swap them manually.
  853. expect(body.filament_presets).toEqual([
  854. { source: 'cloud', id: 'F-BLACK' },
  855. { source: 'cloud', id: 'F-WHITE' },
  856. ]);
  857. });
  858. });
  859. it('still sends the legacy filament_preset for single-color flows', async () => {
  860. // Backwards-compat with backends / proxies that read the singular field.
  861. mockApi.sliceLibraryFile.mockResolvedValue({
  862. job_id: 42,
  863. status: 'pending',
  864. status_url: '/api/v1/slice-jobs/42',
  865. });
  866. renderWithTracker({
  867. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  868. onClose: vi.fn(),
  869. });
  870. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  871. const user = userEvent.setup();
  872. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  873. await waitFor(() => {
  874. const [, body] = mockApi.sliceLibraryFile.mock.calls[0];
  875. // Single-color path mirrors the array's first entry into the legacy
  876. // singular so older backend clients that only know about
  877. // `filament_preset` still work.
  878. expect(body.filament_preset).toEqual(body.filament_presets[0]);
  879. expect(body.filament_presets).toHaveLength(1);
  880. });
  881. });
  882. it('lets the user override a pre-picked filament slot', async () => {
  883. mockApi.getLibraryFilePlates.mockResolvedValue(makeMultiColorPlateResponse());
  884. mockApi.getLibraryFileFilamentRequirements.mockResolvedValue(makeMultiColorRequirementsResponse());
  885. mockApi.getSlicerPresets.mockResolvedValue(makeColorAwarePresets());
  886. mockApi.sliceLibraryFile.mockResolvedValue({
  887. job_id: 42,
  888. status: 'pending',
  889. status_url: '/api/v1/slice-jobs/42',
  890. });
  891. renderWithTracker({
  892. source: { kind: 'libraryFile', id: 100, filename: 'TwoColor.3mf' },
  893. onClose: vi.fn(),
  894. });
  895. await waitFor(() => expect(screen.getByText('X1C')).toBeDefined());
  896. const user = userEvent.setup();
  897. const selects = presetSelects();
  898. // Order: 0 printer, 1 process, 2 bed-type, 3 filament-1, 4 filament-2
  899. // (#1337). Auto-picks land on printer/process/filaments; bed-type
  900. // defaults to "". Swap filament-1 (index 3) from the auto-picked black
  901. // to white.
  902. await user.selectOptions(selects[3], 'cloud:F-WHITE');
  903. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  904. await waitFor(() => {
  905. const [, body] = mockApi.sliceLibraryFile.mock.calls[0];
  906. expect(body.filament_presets[0]).toEqual({ source: 'cloud', id: 'F-WHITE' });
  907. // Slot 1 stayed at the auto-picked white.
  908. expect(body.filament_presets[1]).toEqual({ source: 'cloud', id: 'F-WHITE' });
  909. });
  910. });
  911. // Cross-printer re-slicing is a normal, supported operation as of
  912. // 2026-05-20 (Step 0 empirical test: sidecar overrides printer / process
  913. // / bed / kinematics from the picked profile triplet, producing valid
  914. // target-printer G-code). No banner, no warning — the picker UI already
  915. // shows which printer the user picked, and that's enough.
  916. it('does not surface any cross-printer banner and keeps Slice enabled when models differ', async () => {
  917. mockApi.getLibraryFilePlates.mockResolvedValue({
  918. file_id: 100,
  919. filename: 'A1Original.3mf',
  920. is_multi_plate: false,
  921. plates: [
  922. {
  923. index: 1,
  924. name: 'Plate 1',
  925. objects: [],
  926. has_thumbnail: false,
  927. thumbnail_url: null,
  928. print_time_seconds: null,
  929. filament_used_grams: null,
  930. filaments: [],
  931. },
  932. ],
  933. });
  934. // Standard tier offers an X1C profile — the user picks (auto-picks) it.
  935. mockApi.getSlicerPresets.mockResolvedValue(makeUnified({
  936. standard: {
  937. printer: [{ id: 'Bambu Lab X1 Carbon 0.4 nozzle', name: 'Bambu Lab X1 Carbon 0.4 nozzle', source: 'standard' }],
  938. process: [{ id: '0.20mm Standard', name: '0.20mm Standard', source: 'standard' }],
  939. filament: [{ id: 'Bambu PLA Basic', name: 'Bambu PLA Basic', source: 'standard' }],
  940. },
  941. }));
  942. renderWithTracker({
  943. source: { kind: 'libraryFile', id: 100, filename: 'A1Original.3mf' },
  944. onClose: vi.fn(),
  945. });
  946. await waitFor(() =>
  947. expect(screen.getByText('Bambu Lab X1 Carbon 0.4 nozzle')).toBeDefined(),
  948. );
  949. // No banner, no alert — re-slicing across printers is just a normal slice now.
  950. expect(screen.queryByRole('alert')).toBeNull();
  951. const sliceButton = screen.getByRole('button', { name: /^Slice$/ }) as HTMLButtonElement;
  952. expect(sliceButton.disabled).toBe(false);
  953. });
  954. // The `used_in_plate` flag tells the modal which AMS slots are
  955. // actually consumed by the picked plate. Slots flagged as unused
  956. // are still rendered (the slicer CLI needs a profile per project
  957. // slot, otherwise it silently fills the gap from embedded defaults
  958. // and unwanted colours leak into the output) but disabled in the UI
  959. // so the user only interacts with the dropdowns that matter.
  960. it('disables filament dropdowns for slots not used by the picked plate', async () => {
  961. mockApi.getLibraryFilePlates.mockResolvedValue({
  962. file_id: 100,
  963. filename: 'Helmet.3mf',
  964. is_multi_plate: false,
  965. plates: [
  966. {
  967. index: 1,
  968. name: 'Plate 1',
  969. objects: ['Helmet'],
  970. has_thumbnail: false,
  971. thumbnail_url: null,
  972. print_time_seconds: 1200,
  973. filament_used_grams: 80,
  974. filaments: [],
  975. },
  976. ],
  977. });
  978. // Project has 2 AMS slots configured (white + grey support), but
  979. // plate 1 only paints with white (slot 1). The backend now returns
  980. // BOTH slots with used_in_plate flagging the difference.
  981. mockApi.getLibraryFileFilamentRequirements.mockResolvedValue({
  982. file_id: 100,
  983. filename: 'Helmet.3mf',
  984. plate_id: 1,
  985. filaments: [
  986. { slot_id: 1, type: 'PLA', color: '#FFFFFF', used_grams: 80, used_meters: 27, used_in_plate: true },
  987. { slot_id: 2, type: 'PLA', color: '#808080', used_grams: 0, used_meters: 0, used_in_plate: false },
  988. ],
  989. });
  990. mockApi.getSlicerPresets.mockResolvedValue({
  991. cloud: {
  992. printer: [{ id: 'P1', name: 'X1C', source: 'cloud' }],
  993. process: [{ id: 'PR1', name: '0.20mm', source: 'cloud' }],
  994. filament: [
  995. { id: 'F-WHITE', name: 'Cloud PLA White', source: 'cloud', filament_type: 'PLA', filament_colour: '#FFFFFF' },
  996. { id: 'F-GREY', name: 'Cloud PLA Grey', source: 'cloud', filament_type: 'PLA', filament_colour: '#808080' },
  997. ],
  998. },
  999. local: { printer: [], process: [], filament: [] },
  1000. standard: { printer: [], process: [], filament: [] },
  1001. cloud_status: 'ok',
  1002. orca_cloud: { printer: [], process: [], filament: [] },
  1003. orca_cloud_status: 'ok',
  1004. });
  1005. renderWithTracker({
  1006. source: { kind: 'libraryFile', id: 100, filename: 'Helmet.3mf' },
  1007. onClose: vi.fn(),
  1008. });
  1009. await waitFor(() => expect(screen.getByText('X1C')).toBeDefined());
  1010. // Both filament rows render — 1 printer + 1 process + 1 bed-type +
  1011. // 2 filament (#1337) = 5. bed-type sits at index 2, filament slots
  1012. // follow at 3 and 4.
  1013. const selects = presetSelects();
  1014. expect(selects).toHaveLength(5);
  1015. // Slot 1 (used) is editable, slot 2 (not used) is disabled.
  1016. expect(selects[3].disabled).toBe(false);
  1017. expect(selects[4].disabled).toBe(true);
  1018. // The disabled row's label calls out why it's disabled.
  1019. expect(screen.getByText(/not used by this plate/i)).toBeDefined();
  1020. });
  1021. it('still sends both filaments to the backend even when one slot is disabled', async () => {
  1022. // The auto-pick scoring fills the disabled slot from project
  1023. // metadata — the slicer CLI requires a profile for every project
  1024. // slot, otherwise it silently fills the gap. The disabled UI is
  1025. // purely cosmetic; the wire format must include the full list.
  1026. mockApi.getLibraryFilePlates.mockResolvedValue({
  1027. file_id: 100,
  1028. filename: 'Helmet.3mf',
  1029. is_multi_plate: false,
  1030. plates: [
  1031. {
  1032. index: 1,
  1033. name: 'Plate 1',
  1034. objects: ['Helmet'],
  1035. has_thumbnail: false,
  1036. thumbnail_url: null,
  1037. print_time_seconds: 1200,
  1038. filament_used_grams: 80,
  1039. filaments: [],
  1040. },
  1041. ],
  1042. });
  1043. mockApi.getLibraryFileFilamentRequirements.mockResolvedValue({
  1044. file_id: 100,
  1045. filename: 'Helmet.3mf',
  1046. plate_id: 1,
  1047. filaments: [
  1048. { slot_id: 1, type: 'PLA', color: '#FFFFFF', used_grams: 80, used_meters: 27, used_in_plate: true },
  1049. { slot_id: 2, type: 'PLA', color: '#808080', used_grams: 0, used_meters: 0, used_in_plate: false },
  1050. ],
  1051. });
  1052. mockApi.getSlicerPresets.mockResolvedValue({
  1053. cloud: {
  1054. printer: [{ id: 'P1', name: 'X1C', source: 'cloud' }],
  1055. process: [{ id: 'PR1', name: '0.20mm', source: 'cloud' }],
  1056. filament: [
  1057. { id: 'F-WHITE', name: 'Cloud PLA White', source: 'cloud', filament_type: 'PLA', filament_colour: '#FFFFFF' },
  1058. { id: 'F-GREY', name: 'Cloud PLA Grey', source: 'cloud', filament_type: 'PLA', filament_colour: '#808080' },
  1059. ],
  1060. },
  1061. local: { printer: [], process: [], filament: [] },
  1062. standard: { printer: [], process: [], filament: [] },
  1063. cloud_status: 'ok',
  1064. orca_cloud: { printer: [], process: [], filament: [] },
  1065. orca_cloud_status: 'ok',
  1066. });
  1067. mockApi.sliceLibraryFile.mockResolvedValue({
  1068. job_id: 50,
  1069. status: 'pending',
  1070. status_url: '/api/v1/slice-jobs/50',
  1071. });
  1072. renderWithTracker({
  1073. source: { kind: 'libraryFile', id: 100, filename: 'Helmet.3mf' },
  1074. onClose: vi.fn(),
  1075. });
  1076. await waitFor(() => expect(screen.getByText('X1C')).toBeDefined());
  1077. const user = userEvent.setup();
  1078. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  1079. await waitFor(() => {
  1080. const [, body] = mockApi.sliceLibraryFile.mock.calls[0];
  1081. // Both slots populated: slot 1 with the user's white pick, slot
  1082. // 2 auto-picked with grey from the colour-match scoring.
  1083. expect(body.filament_presets).toHaveLength(2);
  1084. expect(body.filament_presets[0]).toEqual({ source: 'cloud', id: 'F-WHITE' });
  1085. expect(body.filament_presets[1]).toEqual({ source: 'cloud', id: 'F-GREY' });
  1086. });
  1087. });
  1088. // #2712: the filament list is positional the whole way down — index 0 is
  1089. // slot 1, and the backend forwards it as filament_1.json..filament_N.json.
  1090. // A MakerWorld source that ships slice_info and paints with slot 4 alone
  1091. // used to yield a one-row list, so the user's only pick was bound to slot 1
  1092. // and slot 4 sliced with the source's embedded default: picking PETG gave a
  1093. // PLA print. The modal now asks for every project slot so the positions
  1094. // line up.
  1095. it('requests every project slot, not just the ones the plate prints with', async () => {
  1096. renderWithTracker({
  1097. source: { kind: 'libraryFile', id: 100, filename: 'Tunnel.3mf' },
  1098. onClose: vi.fn(),
  1099. });
  1100. await waitFor(() => expect(mockApi.getLibraryFileFilamentRequirements).toHaveBeenCalled());
  1101. const [, plateArg, , fullSlots] = mockApi.getLibraryFileFilamentRequirements.mock.calls[0];
  1102. expect(plateArg).toBe(1);
  1103. expect(fullSlots).toBe(true);
  1104. });
  1105. it('sends the pick for a high-numbered slot at its own index', async () => {
  1106. // Four project slots, only slot 4 printed. The pick must arrive as the
  1107. // FOURTH entry; anywhere else and the slicer binds it to the wrong slot.
  1108. mockApi.getLibraryFilePlates.mockResolvedValue({
  1109. file_id: 100,
  1110. filename: 'Tunnel.3mf',
  1111. is_multi_plate: false,
  1112. plates: [
  1113. {
  1114. index: 1,
  1115. name: 'Plate 1',
  1116. objects: ['Tunnel'],
  1117. has_thumbnail: false,
  1118. thumbnail_url: null,
  1119. print_time_seconds: 1200,
  1120. filament_used_grams: 105,
  1121. filaments: [],
  1122. },
  1123. ],
  1124. });
  1125. mockApi.getLibraryFileFilamentRequirements.mockResolvedValue({
  1126. file_id: 100,
  1127. filename: 'Tunnel.3mf',
  1128. plate_id: 1,
  1129. filaments: [
  1130. { slot_id: 1, type: 'PLA', color: '#38CC0A', used_grams: 0, used_meters: 0, used_in_plate: false },
  1131. { slot_id: 2, type: 'PLA', color: '#161616', used_grams: 0, used_meters: 0, used_in_plate: false },
  1132. { slot_id: 3, type: 'PLA', color: '#898989', used_grams: 0, used_meters: 0, used_in_plate: false },
  1133. { slot_id: 4, type: 'PLA', color: '#898989', used_grams: 105, used_meters: 35, used_in_plate: true },
  1134. ],
  1135. });
  1136. mockApi.getSlicerPresets.mockResolvedValue({
  1137. cloud: {
  1138. printer: [{ id: 'P1', name: 'X1C', source: 'cloud' }],
  1139. process: [{ id: 'PR1', name: '0.20mm', source: 'cloud' }],
  1140. filament: [
  1141. { id: 'F-PLA', name: 'Cloud PLA Grey', source: 'cloud', filament_type: 'PLA', filament_colour: '#898989' },
  1142. { id: 'F-PETG', name: 'Cloud PETG', source: 'cloud', filament_type: 'PETG', filament_colour: '#00FF00' },
  1143. ],
  1144. },
  1145. local: { printer: [], process: [], filament: [] },
  1146. standard: { printer: [], process: [], filament: [] },
  1147. cloud_status: 'ok',
  1148. orca_cloud: { printer: [], process: [], filament: [] },
  1149. orca_cloud_status: 'ok',
  1150. });
  1151. mockApi.sliceLibraryFile.mockResolvedValue({
  1152. job_id: 51,
  1153. status: 'pending',
  1154. status_url: '/api/v1/slice-jobs/51',
  1155. });
  1156. renderWithTracker({
  1157. source: { kind: 'libraryFile', id: 100, filename: 'Tunnel.3mf' },
  1158. onClose: vi.fn(),
  1159. });
  1160. await waitFor(() => expect(screen.getByText('X1C')).toBeDefined());
  1161. // 1 printer + 1 process + 1 bed-type + 4 filament rows.
  1162. const selects = presetSelects();
  1163. expect(selects).toHaveLength(7);
  1164. // Only slot 4 is selectable — the other three are the padding.
  1165. expect([selects[3].disabled, selects[4].disabled, selects[5].disabled]).toEqual([true, true, true]);
  1166. expect(selects[6].disabled).toBe(false);
  1167. const user = userEvent.setup();
  1168. await user.selectOptions(selects[6], 'cloud:F-PETG');
  1169. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  1170. await waitFor(() => {
  1171. const [, body] = mockApi.sliceLibraryFile.mock.calls[0];
  1172. expect(body.filament_presets).toHaveLength(4);
  1173. expect(body.filament_presets[3]).toEqual({ source: 'cloud', id: 'F-PETG' });
  1174. });
  1175. });
  1176. // ------------------------------------------------------------------
  1177. // Slicer Pipelines (#1425) — Apply / Save integration in SliceModal
  1178. // ------------------------------------------------------------------
  1179. it('Apply pipeline dropdown is disabled and shows empty hint when no pipelines exist', async () => {
  1180. mockApi.listSlicerPipelines.mockResolvedValue({ pipelines: [] });
  1181. renderWithTracker({
  1182. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  1183. onClose: vi.fn(),
  1184. });
  1185. await waitFor(() => {
  1186. const select = screen.getByLabelText(/Apply pipeline/i) as HTMLSelectElement;
  1187. expect(select.disabled).toBe(true);
  1188. expect(select.querySelector('option')?.textContent).toMatch(/No saved pipelines/i);
  1189. });
  1190. });
  1191. it('applies a saved pipeline to printer, process, and bed_type slots on selection', async () => {
  1192. mockApi.listSlicerPipelines.mockResolvedValue({
  1193. pipelines: [
  1194. {
  1195. id: 7,
  1196. name: 'Production Batch',
  1197. description: null,
  1198. printer_preset: { source: 'local', id: '1' },
  1199. process_preset: { source: 'local', id: '2' },
  1200. filament_presets: [{ source: 'local', id: '3' }],
  1201. bed_type: 'Textured PEI Plate',
  1202. target_kind: 'printer_class',
  1203. target_printer_id: null,
  1204. target_model_class: null,
  1205. fanout_strategy: 'max_parallel',
  1206. created_by: null,
  1207. created_at: '2026-06-27T00:00:00Z',
  1208. updated_at: '2026-06-27T00:00:00Z',
  1209. },
  1210. ],
  1211. });
  1212. renderWithTracker({
  1213. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  1214. onClose: vi.fn(),
  1215. });
  1216. // Wait for presets + pipelines listing to populate the modal.
  1217. await waitFor(() => {
  1218. const select = screen.getByLabelText(/Apply pipeline/i) as HTMLSelectElement;
  1219. expect(select.disabled).toBe(false);
  1220. expect(within(select).getByText('Production Batch')).toBeDefined();
  1221. });
  1222. const user = userEvent.setup();
  1223. await user.selectOptions(screen.getByLabelText(/Apply pipeline/i), '7');
  1224. // After applying, submitting the slice request should carry the
  1225. // pipeline's preset refs end-to-end.
  1226. mockApi.sliceLibraryFile.mockResolvedValue({
  1227. job_id: 42,
  1228. status: 'queued',
  1229. status_url: '/api/v1/slice-jobs/42',
  1230. });
  1231. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  1232. await waitFor(() => {
  1233. expect(mockApi.sliceLibraryFile).toHaveBeenCalled();
  1234. const [, body] = mockApi.sliceLibraryFile.mock.calls[0];
  1235. expect(body.printer_preset).toEqual({ source: 'local', id: '1' });
  1236. expect(body.process_preset).toEqual({ source: 'local', id: '2' });
  1237. expect(body.filament_presets[0]).toEqual({ source: 'local', id: '3' });
  1238. expect(body.bed_type).toBe('Textured PEI Plate');
  1239. });
  1240. });
  1241. it('saves the current four-slot selection as a new pipeline when the user clicks Save as pipeline', async () => {
  1242. mockApi.listSlicerPipelines.mockResolvedValue({ pipelines: [] });
  1243. mockApi.createSlicerPipeline.mockResolvedValue({
  1244. id: 99,
  1245. name: 'My Default',
  1246. description: null,
  1247. printer_preset: { source: 'local', id: '1' },
  1248. process_preset: { source: 'local', id: '2' },
  1249. filament_presets: [{ source: 'local', id: '3' }],
  1250. bed_type: null,
  1251. target_kind: 'printer_class',
  1252. target_printer_id: null,
  1253. target_model_class: null,
  1254. fanout_strategy: 'max_parallel',
  1255. created_by: null,
  1256. created_at: '2026-06-27T00:00:00Z',
  1257. updated_at: '2026-06-27T00:00:00Z',
  1258. });
  1259. renderWithTracker({
  1260. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  1261. onClose: vi.fn(),
  1262. });
  1263. // Wait for auto-pick to populate all four slots from the fullThreeTier
  1264. // listing — then Save as pipeline becomes enabled.
  1265. const user = userEvent.setup();
  1266. let saveBtn: HTMLButtonElement;
  1267. await waitFor(() => {
  1268. saveBtn = screen.getByRole('button', { name: /^Save as pipeline$/ }) as HTMLButtonElement;
  1269. expect(saveBtn.disabled).toBe(false);
  1270. });
  1271. await user.click(saveBtn!);
  1272. const nameInput = screen.getByLabelText(/New pipeline name/i);
  1273. await user.type(nameInput, 'My Default');
  1274. await user.click(screen.getByRole('button', { name: /^Save$/ }));
  1275. await waitFor(() => {
  1276. expect(mockApi.createSlicerPipeline).toHaveBeenCalledTimes(1);
  1277. const body = mockApi.createSlicerPipeline.mock.calls[0][0];
  1278. expect(body.name).toBe('My Default');
  1279. // The four slots come from the auto-picked unified-presets listing —
  1280. // local tier wins per SLICE_MODAL_TIER_ORDER.
  1281. expect(body.printer_preset.source).toBe('local');
  1282. expect(body.process_preset.source).toBe('local');
  1283. expect(body.filament_presets[0].source).toBe('local');
  1284. });
  1285. });
  1286. });
  1287. // Pure-function tests for the filament slot picker. Pinned as a separate
  1288. // describe so the contract is visible without needing the modal mount.
  1289. describe('pickFilamentForSlot — printer-compat contract (#1851)', () => {
  1290. // Index that recognises @BBL H2C / @BBL A1 tokens via the canonical
  1291. // PRINTER_MODEL_MAP. Real production data comes through
  1292. // ``api.getSlicerPrinterModels`` — the H2C / A1 fragments are the ones
  1293. // the production registry ships.
  1294. const index = buildCompatibilityIndex({
  1295. 'Bambu Lab A1': 'A1',
  1296. 'Bambu Lab H2C': 'H2C',
  1297. });
  1298. it('prefers a printer-compatible preset over a printer-mismatched one even with better colour match', () => {
  1299. // The OP scenario for #1851: a Bambu Lab A1 is selected; the unused-slot
  1300. // requirement carries the original H2C plate's PLA colour. With the
  1301. // legacy soft-penalty scoring an H2C-bound preset whose colour matches
  1302. // exactly could still rise above the A1-compatible PLA Basic whose
  1303. // colour doesn't, and then the unused-slot substitution propagated the
  1304. // H2C-bound preset across every unused slot — the CLI rejected with
  1305. // ``filament preset Generic PLA @BBL H2C (slot 1) is not compatible
  1306. // with printer Bambu Lab A1 0.4 nozzle``. The hard-skip contract makes
  1307. // sure a mismatched preset is never chosen while any compatible
  1308. // alternative exists, irrespective of metadata-score arithmetic.
  1309. const presets = makeUnified({
  1310. standard: {
  1311. printer: [],
  1312. process: [],
  1313. filament: [
  1314. {
  1315. id: 'Generic PLA @BBL H2C',
  1316. name: 'Generic PLA @BBL H2C',
  1317. source: 'standard',
  1318. filament_type: 'PLA',
  1319. filament_colour: '#FF0000',
  1320. },
  1321. {
  1322. id: 'Bambu PLA Basic @BBL A1',
  1323. name: 'Bambu PLA Basic @BBL A1',
  1324. source: 'standard',
  1325. filament_type: 'PLA',
  1326. filament_colour: '#FFFFFF',
  1327. },
  1328. ],
  1329. },
  1330. });
  1331. const pick = pickFilamentForSlot(
  1332. presets,
  1333. { type: 'PLA', color: '#FF0000' },
  1334. 'Bambu Lab A1 0.4 nozzle',
  1335. index,
  1336. );
  1337. expect(pick).toEqual({ source: 'standard', id: 'Bambu PLA Basic @BBL A1' });
  1338. });
  1339. it('falls back to a mismatched preset when no compatible alternative exists', () => {
  1340. // Graceful degrade: when every available preset is printer-mismatched,
  1341. // returning ``null`` would block the slice entirely. The picker keeps
  1342. // its old behaviour of returning the best-scoring mismatch so the user
  1343. // sees a populated dropdown they can correct, not an empty one.
  1344. const presets = makeUnified({
  1345. standard: {
  1346. printer: [],
  1347. process: [],
  1348. filament: [
  1349. {
  1350. id: 'Generic PLA @BBL H2C',
  1351. name: 'Generic PLA @BBL H2C',
  1352. source: 'standard',
  1353. filament_type: 'PLA',
  1354. filament_colour: '#FF0000',
  1355. },
  1356. ],
  1357. },
  1358. });
  1359. const pick = pickFilamentForSlot(
  1360. presets,
  1361. { type: 'PLA', color: '#FF0000' },
  1362. 'Bambu Lab A1 0.4 nozzle',
  1363. index,
  1364. );
  1365. expect(pick).toEqual({ source: 'standard', id: 'Generic PLA @BBL H2C' });
  1366. });
  1367. it('treats a no-printer-context call as no-mismatch (every preset eligible)', () => {
  1368. // ``printerName === null`` happens transiently on first render before the
  1369. // printer pre-pick effect has run. ``presetCompatibility`` returns
  1370. // ``unknown`` for every preset in that case, so the picker should just
  1371. // pick by metadata score with no compatibility filter active.
  1372. const presets = makeUnified({
  1373. standard: {
  1374. printer: [],
  1375. process: [],
  1376. filament: [
  1377. {
  1378. id: 'Generic PLA @BBL H2C',
  1379. name: 'Generic PLA @BBL H2C',
  1380. source: 'standard',
  1381. filament_type: 'PLA',
  1382. filament_colour: '#FF0000',
  1383. },
  1384. ],
  1385. },
  1386. });
  1387. const pick = pickFilamentForSlot(
  1388. presets,
  1389. { type: 'PLA', color: '#FF0000' },
  1390. null,
  1391. index,
  1392. );
  1393. expect(pick).toEqual({ source: 'standard', id: 'Generic PLA @BBL H2C' });
  1394. });
  1395. });
  1396. describe('pickFilamentForSlot — long-form printer tag (#2628)', () => {
  1397. const index = buildCompatibilityIndex({
  1398. 'Bambu Lab A1': 'A1',
  1399. 'Bambu Lab H2D': 'H2D',
  1400. });
  1401. it('never auto-picks a user-saved preset scoped to another printer', () => {
  1402. // michaelklos's registry: a cloud-tier user preset carrying the full
  1403. // "@Bambu Lab H2D 0.4 nozzle" tag outscores the A1 preset on tier bonus
  1404. // alone. Until the matcher learned the long form it classified 'unknown'
  1405. // — indistinguishable from compatible — so it won the slot, landed in a
  1406. // dropdown the modal disables (slot not used by the plate), and the CLI
  1407. // rejected the whole slice.
  1408. const presets = makeUnified({
  1409. cloud: {
  1410. printer: [],
  1411. process: [],
  1412. filament: [
  1413. {
  1414. id: 'sunlu-tpu-h2d',
  1415. name: 'SUNLU TPU 95A @Bambu Lab H2D 0.4 nozzle',
  1416. source: 'cloud',
  1417. filament_type: 'PLA',
  1418. filament_colour: '#FF0000',
  1419. },
  1420. ],
  1421. },
  1422. standard: {
  1423. printer: [],
  1424. process: [],
  1425. filament: [
  1426. {
  1427. id: 'Bambu PLA Basic @BBL A1',
  1428. name: 'Bambu PLA Basic @BBL A1',
  1429. source: 'standard',
  1430. filament_type: 'PLA',
  1431. filament_colour: '#FFFFFF',
  1432. },
  1433. ],
  1434. },
  1435. });
  1436. const pick = pickFilamentForSlot(
  1437. presets,
  1438. { type: 'PLA', color: '#FF0000' },
  1439. 'Bambu Lab A1 0.4 nozzle',
  1440. index,
  1441. );
  1442. expect(pick).toEqual({ source: 'standard', id: 'Bambu PLA Basic @BBL A1' });
  1443. });
  1444. it('still picks a long-form preset for its own printer', () => {
  1445. const presets = makeUnified({
  1446. cloud: {
  1447. printer: [],
  1448. process: [],
  1449. filament: [
  1450. {
  1451. id: 'sunlu-tpu-h2d',
  1452. name: 'SUNLU TPU 95A @Bambu Lab H2D 0.4 nozzle',
  1453. source: 'cloud',
  1454. filament_type: 'TPU',
  1455. filament_colour: '#FF0000',
  1456. },
  1457. ],
  1458. },
  1459. });
  1460. const pick = pickFilamentForSlot(
  1461. presets,
  1462. { type: 'TPU', color: '#FF0000' },
  1463. 'Bambu Lab H2D 0.4 nozzle',
  1464. index,
  1465. );
  1466. expect(pick).toEqual({ source: 'cloud', id: 'sunlu-tpu-h2d' });
  1467. });
  1468. });