SliceModal.test.tsx 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  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 { SliceJobTrackerProvider } from '../../contexts/SliceJobTrackerContext';
  16. import { api, type UnifiedPresetsResponse } from '../../api/client';
  17. vi.mock('../../api/client', () => ({
  18. api: {
  19. getSlicerPresets: vi.fn(),
  20. sliceLibraryFile: vi.fn(),
  21. sliceArchive: vi.fn(),
  22. getSliceJob: vi.fn(),
  23. getLibraryFilePlates: vi.fn(),
  24. getArchivePlates: vi.fn(),
  25. getLibraryFileFilamentRequirements: vi.fn(),
  26. getArchiveFilamentRequirements: vi.fn(),
  27. getSettings: vi.fn().mockResolvedValue({}),
  28. updateSettings: vi.fn().mockResolvedValue({}),
  29. // Slicer Pipelines (#1425)
  30. listSlicerPipelines: vi.fn(),
  31. createSlicerPipeline: vi.fn(),
  32. },
  33. }));
  34. const mockApi = api as unknown as {
  35. getSlicerPresets: ReturnType<typeof vi.fn>;
  36. sliceLibraryFile: ReturnType<typeof vi.fn>;
  37. sliceArchive: ReturnType<typeof vi.fn>;
  38. getSliceJob: ReturnType<typeof vi.fn>;
  39. getLibraryFilePlates: ReturnType<typeof vi.fn>;
  40. getArchivePlates: ReturnType<typeof vi.fn>;
  41. getLibraryFileFilamentRequirements: ReturnType<typeof vi.fn>;
  42. getArchiveFilamentRequirements: ReturnType<typeof vi.fn>;
  43. listSlicerPipelines: ReturnType<typeof vi.fn>;
  44. createSlicerPipeline: ReturnType<typeof vi.fn>;
  45. };
  46. function makeUnified(overrides: Partial<UnifiedPresetsResponse> = {}): UnifiedPresetsResponse {
  47. return {
  48. orca_cloud: { printer: [], process: [], filament: [] },
  49. cloud: { printer: [], process: [], filament: [] },
  50. local: { printer: [], process: [], filament: [] },
  51. standard: { printer: [], process: [], filament: [] },
  52. cloud_status: 'ok',
  53. orca_cloud_status: 'ok',
  54. ...overrides,
  55. };
  56. }
  57. const fullThreeTier: UnifiedPresetsResponse = makeUnified({
  58. cloud: {
  59. printer: [{ id: 'PFUcloud-printer', name: 'My Custom X1C', source: 'cloud' }],
  60. process: [{ id: 'PFUcloud-process', name: 'My 0.16mm Tweaked', source: 'cloud' }],
  61. filament: [{ id: 'PFUcloud-filament', name: 'My PLA Black', source: 'cloud' }],
  62. },
  63. local: {
  64. printer: [{ id: '1', name: 'Imported X1C 0.4', source: 'local' }],
  65. process: [{ id: '2', name: 'Imported 0.20mm', source: 'local' }],
  66. filament: [{ id: '3', name: 'Imported PLA Basic', source: 'local' }],
  67. },
  68. standard: {
  69. printer: [{ id: 'Bambu Lab X1 Carbon 0.4 nozzle', name: 'Bambu Lab X1 Carbon 0.4 nozzle', source: 'standard' }],
  70. process: [{ id: '0.20mm Standard', name: '0.20mm Standard', source: 'standard' }],
  71. filament: [{ id: 'Bambu PLA Basic', name: 'Bambu PLA Basic', source: 'standard' }],
  72. },
  73. });
  74. function renderWithTracker(props: Parameters<typeof SliceModal>[0]) {
  75. return render(
  76. <SliceJobTrackerProvider>
  77. <SliceModal {...props} />
  78. </SliceJobTrackerProvider>,
  79. );
  80. }
  81. // SliceModal renders one extra combobox for the Slicer Pipelines (#1425)
  82. // "Apply pipeline" dropdown above the preset slots. Tests written before
  83. // pipelines landed assume selects[0] = printer; this helper drops the
  84. // pipeline combobox so those indices stay stable.
  85. function presetSelects(): HTMLSelectElement[] {
  86. return (screen.getAllByRole('combobox') as HTMLSelectElement[]).filter(
  87. (el) => el.getAttribute('aria-label') !== 'Apply pipeline',
  88. );
  89. }
  90. describe('SliceModal', () => {
  91. beforeEach(() => {
  92. vi.clearAllMocks();
  93. mockApi.getSlicerPresets.mockResolvedValue(fullThreeTier);
  94. mockApi.getSliceJob.mockResolvedValue({
  95. job_id: 42,
  96. status: 'running',
  97. kind: 'library_file',
  98. source_id: 100,
  99. source_name: 'Cube.stl',
  100. created_at: new Date().toISOString(),
  101. started_at: null,
  102. completed_at: null,
  103. });
  104. // Default: single-plate (or non-3MF). Multi-plate tests override this.
  105. mockApi.getLibraryFilePlates.mockResolvedValue({
  106. file_id: 100,
  107. filename: 'Cube.stl',
  108. plates: [],
  109. is_multi_plate: false,
  110. });
  111. mockApi.getArchivePlates.mockResolvedValue({
  112. archive_id: 100,
  113. filename: 'Cube.3mf',
  114. plates: [],
  115. is_multi_plate: false,
  116. });
  117. // Default: no per-plate filament metadata available (mirrors STL or
  118. // unsliced source). Multi-color tests override this.
  119. mockApi.getLibraryFileFilamentRequirements.mockResolvedValue({
  120. file_id: 100,
  121. filename: 'Cube.stl',
  122. plate_id: 1,
  123. filaments: [],
  124. });
  125. mockApi.getArchiveFilamentRequirements.mockResolvedValue({
  126. archive_id: 100,
  127. filename: 'Cube.3mf',
  128. plate_id: 1,
  129. filaments: [],
  130. });
  131. // Default: no saved pipelines. Tests opt in by overriding this.
  132. mockApi.listSlicerPipelines.mockResolvedValue({ pipelines: [] });
  133. });
  134. it('auto-selects the highest-priority tier per slot on first load', async () => {
  135. renderWithTracker({
  136. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  137. onClose: vi.fn(),
  138. });
  139. // SliceModal-specific tier priority: imported (local) wins over cloud
  140. // and standard so the user's curated picks come first.
  141. await waitFor(() => {
  142. expect(screen.getByText('My Custom X1C')).toBeDefined();
  143. });
  144. // 4 selects: printer, process, bed-type (#1337), filament. bed-type sits
  145. // between process and filament — it overrides curr_bed_type on the
  146. // process preset so the related controls cluster — and defaults to "".
  147. const selects = presetSelects();
  148. expect(selects).toHaveLength(4);
  149. expect(selects[0].value).toBe('local:1');
  150. expect(selects[1].value).toBe('local:2');
  151. expect(selects[2].value).toBe('');
  152. expect(selects[3].value).toBe('local:3');
  153. // Slice button is enabled because all three slots auto-defaulted and
  154. // the preview-slice query has resolved (mock returns immediately).
  155. const sliceBtn = screen.getByRole('button', { name: /^Slice$/ });
  156. expect((sliceBtn as HTMLButtonElement).disabled).toBe(false);
  157. });
  158. it('renders Imported / Cloud / Standard sections via <optgroup>', async () => {
  159. renderWithTracker({
  160. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  161. onClose: vi.fn(),
  162. });
  163. await waitFor(() => expect(screen.getByText('Imported X1C 0.4')).toBeDefined());
  164. const printerSelect = presetSelects()[0];
  165. const groups = printerSelect.querySelectorAll('optgroup');
  166. expect(Array.from(groups).map((g) => g.label)).toEqual([
  167. 'Imported',
  168. 'Bambu Cloud',
  169. 'Standard',
  170. ]);
  171. // Each entry sits inside its own tier's group — pin the assignment so
  172. // a future render-shape change can't quietly mix them. Order matches
  173. // SLICE_MODAL_TIER_ORDER (local → cloud → standard).
  174. const localGroup = groups[0];
  175. expect(within(localGroup as HTMLElement).getByText('Imported X1C 0.4')).toBeDefined();
  176. const cloudGroup = groups[1];
  177. expect(within(cloudGroup as HTMLElement).getByText('My Custom X1C')).toBeDefined();
  178. const standardGroup = groups[2];
  179. expect(within(standardGroup as HTMLElement).getByText('Bambu Lab X1 Carbon 0.4 nozzle')).toBeDefined();
  180. });
  181. it('falls back to local when cloud is empty (auto-pick respects priority)', async () => {
  182. mockApi.getSlicerPresets.mockResolvedValue(
  183. makeUnified({
  184. local: fullThreeTier.local,
  185. standard: fullThreeTier.standard,
  186. }),
  187. );
  188. renderWithTracker({
  189. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  190. onClose: vi.fn(),
  191. });
  192. await waitFor(() => expect(screen.getByText('Imported X1C 0.4')).toBeDefined());
  193. const selects = presetSelects();
  194. expect(selects[0].value).toBe('local:1');
  195. });
  196. it('falls back to standard when both cloud and local are empty', async () => {
  197. mockApi.getSlicerPresets.mockResolvedValue(
  198. makeUnified({ standard: fullThreeTier.standard }),
  199. );
  200. renderWithTracker({
  201. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  202. onClose: vi.fn(),
  203. });
  204. await waitFor(() => expect(screen.getByText('Bambu Lab X1 Carbon 0.4 nozzle')).toBeDefined());
  205. const selects = presetSelects();
  206. expect(selects[0].value).toBe('standard:Bambu Lab X1 Carbon 0.4 nozzle');
  207. });
  208. it('sends source-aware refs (not legacy bare ints) on submit', async () => {
  209. const onClose = vi.fn();
  210. mockApi.sliceLibraryFile.mockResolvedValue({
  211. job_id: 42,
  212. status: 'pending',
  213. status_url: '/api/v1/slice-jobs/42',
  214. });
  215. renderWithTracker({
  216. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  217. onClose,
  218. });
  219. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  220. const user = userEvent.setup();
  221. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  222. await waitFor(() => {
  223. // SliceModal-specific tier priority puts imported (local) above cloud,
  224. // so the auto-pick lands on the local entries even when a cloud entry
  225. // with the same slot is also available in the listing.
  226. expect(mockApi.sliceLibraryFile).toHaveBeenCalledWith(100, {
  227. printer_preset: { source: 'local', id: '1' },
  228. process_preset: { source: 'local', id: '2' },
  229. filament_preset: { source: 'local', id: '3' },
  230. filament_presets: [{ source: 'local', id: '3' }],
  231. });
  232. });
  233. await waitFor(() => expect(onClose).toHaveBeenCalled());
  234. });
  235. it('includes bed_type in the request when the user picks a non-auto plate (#1337)', async () => {
  236. const onClose = vi.fn();
  237. mockApi.sliceLibraryFile.mockResolvedValue({
  238. job_id: 42,
  239. status: 'pending',
  240. status_url: '/api/v1/slice-jobs/42',
  241. });
  242. renderWithTracker({
  243. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  244. onClose,
  245. });
  246. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  247. const user = userEvent.setup();
  248. // Order with the dropdown now sits between Process and Filament:
  249. // printer (0), process (1), bed-type (2), filament (3+). Find the
  250. // bed-type select by name rather than positional index so this stays
  251. // green if the layout adds another control around it.
  252. const bedSelect = presetSelects().find((el) =>
  253. (el as HTMLSelectElement).options[0]?.textContent?.toLowerCase().includes('auto'),
  254. ) as HTMLSelectElement;
  255. expect(bedSelect).toBeDefined();
  256. await user.selectOptions(bedSelect, 'Textured PEI Plate');
  257. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  258. await waitFor(() => {
  259. expect(mockApi.sliceLibraryFile).toHaveBeenCalledWith(
  260. 100,
  261. expect.objectContaining({ bed_type: 'Textured PEI Plate' }),
  262. );
  263. });
  264. });
  265. it('omits bed_type when the user leaves it on Auto (no override)', async () => {
  266. const onClose = vi.fn();
  267. mockApi.sliceLibraryFile.mockResolvedValue({
  268. job_id: 42,
  269. status: 'pending',
  270. status_url: '/api/v1/slice-jobs/42',
  271. });
  272. renderWithTracker({
  273. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  274. onClose,
  275. });
  276. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  277. const user = userEvent.setup();
  278. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  279. await waitFor(() => {
  280. const [, body] = vi.mocked(mockApi.sliceLibraryFile).mock.calls[0];
  281. expect(body).not.toHaveProperty('bed_type');
  282. });
  283. });
  284. it('lets the user override the default and pick a Standard preset', async () => {
  285. const onClose = vi.fn();
  286. mockApi.sliceLibraryFile.mockResolvedValue({
  287. job_id: 42,
  288. status: 'pending',
  289. status_url: '/api/v1/slice-jobs/42',
  290. });
  291. renderWithTracker({
  292. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  293. onClose,
  294. });
  295. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  296. const user = userEvent.setup();
  297. const selects = presetSelects();
  298. await user.selectOptions(selects[0], 'standard:Bambu Lab X1 Carbon 0.4 nozzle');
  299. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  300. await waitFor(() => {
  301. expect(mockApi.sliceLibraryFile).toHaveBeenCalledWith(
  302. 100,
  303. expect.objectContaining({
  304. printer_preset: { source: 'standard', id: 'Bambu Lab X1 Carbon 0.4 nozzle' },
  305. }),
  306. );
  307. });
  308. });
  309. it('routes archive sources to sliceArchive instead of sliceLibraryFile', async () => {
  310. const onClose = vi.fn();
  311. mockApi.sliceArchive.mockResolvedValue({
  312. job_id: 7,
  313. status: 'pending',
  314. status_url: '/api/v1/slice-jobs/7',
  315. });
  316. renderWithTracker({
  317. source: { kind: 'archive', id: 86, filename: 'orca.3mf' },
  318. onClose,
  319. });
  320. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  321. const user = userEvent.setup();
  322. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  323. await waitFor(() => {
  324. expect(mockApi.sliceArchive).toHaveBeenCalledWith(86, expect.any(Object));
  325. expect(mockApi.sliceLibraryFile).not.toHaveBeenCalled();
  326. });
  327. });
  328. it('surfaces enqueue errors inline and keeps the modal open', async () => {
  329. const onClose = vi.fn();
  330. mockApi.sliceLibraryFile.mockRejectedValue(new Error('Server says no'));
  331. renderWithTracker({
  332. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  333. onClose,
  334. });
  335. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  336. const user = userEvent.setup();
  337. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  338. await waitFor(() => {
  339. expect(screen.getByRole('alert')).toHaveTextContent('Server says no');
  340. });
  341. expect(onClose).not.toHaveBeenCalled();
  342. });
  343. it('shows a friendly notice when getSlicerPresets fails', async () => {
  344. mockApi.getSlicerPresets.mockRejectedValue(new Error('500'));
  345. renderWithTracker({
  346. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  347. onClose: vi.fn(),
  348. });
  349. await waitFor(() => {
  350. expect(screen.getByRole('alert')).toHaveTextContent(/Failed to load presets/i);
  351. });
  352. });
  353. it('omits the cloud banner when status is not_authenticated (#1712)', async () => {
  354. // A signed-out user (Bambu or Orca) shouldn't get a permanent "sign in"
  355. // nag at the top of every slice. Sign-in lives on the Profiles page; the
  356. // modal stays silent unless a previously-signed-in session actually broke
  357. // (expired / unreachable).
  358. mockApi.getSlicerPresets.mockResolvedValue(
  359. makeUnified({
  360. cloud_status: 'not_authenticated',
  361. orca_cloud_status: 'not_authenticated',
  362. local: fullThreeTier.local,
  363. standard: fullThreeTier.standard,
  364. }),
  365. );
  366. renderWithTracker({
  367. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  368. onClose: vi.fn(),
  369. });
  370. await waitFor(() => expect(screen.getByText('Imported X1C 0.4')).toBeDefined());
  371. expect(screen.queryByRole('status')).toBeNull();
  372. });
  373. it('renders an "expired" banner when cloud_status is expired', async () => {
  374. mockApi.getSlicerPresets.mockResolvedValue(
  375. makeUnified({
  376. cloud_status: 'expired',
  377. local: fullThreeTier.local,
  378. }),
  379. );
  380. renderWithTracker({
  381. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  382. onClose: vi.fn(),
  383. });
  384. await waitFor(() => {
  385. expect(screen.getByRole('status')).toHaveTextContent(/expired/i);
  386. });
  387. });
  388. it('omits the banner entirely when cloud_status is ok', async () => {
  389. renderWithTracker({
  390. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  391. onClose: vi.fn(),
  392. });
  393. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  394. // No status-role banner should be rendered on the happy path.
  395. expect(screen.queryByRole('status')).toBeNull();
  396. });
  397. // ----- Multi-plate flow -----------------------------------------------
  398. function makeMultiPlateLibraryResponse() {
  399. return {
  400. file_id: 100,
  401. filename: 'Multi.3mf',
  402. is_multi_plate: true,
  403. plates: [
  404. {
  405. index: 1,
  406. name: 'Plate 1',
  407. objects: ['Cube'],
  408. object_count: 1,
  409. has_thumbnail: false,
  410. thumbnail_url: null,
  411. print_time_seconds: 600,
  412. filament_used_grams: 10,
  413. filaments: [],
  414. },
  415. {
  416. index: 2,
  417. name: 'Plate 2',
  418. objects: ['Pyramid'],
  419. object_count: 1,
  420. has_thumbnail: false,
  421. thumbnail_url: null,
  422. print_time_seconds: 800,
  423. filament_used_grams: 12,
  424. filaments: [],
  425. },
  426. ],
  427. };
  428. }
  429. it('shows the plate picker first for multi-plate library files', async () => {
  430. mockApi.getLibraryFilePlates.mockResolvedValue(makeMultiPlateLibraryResponse());
  431. renderWithTracker({
  432. source: { kind: 'libraryFile', id: 100, filename: 'Multi.3mf' },
  433. onClose: vi.fn(),
  434. });
  435. // Plate picker renders one button per plate — the accessible name
  436. // joins the heading ("Plate N — name") with the object summary line.
  437. await screen.findByRole('button', { name: /Plate 1.*Cube/ });
  438. expect(screen.getByRole('button', { name: /Plate 2.*Pyramid/ })).toBeDefined();
  439. // Profile dropdowns must NOT be visible yet — the user has to pick a
  440. // plate first.
  441. expect(screen.queryByRole('combobox')).toBeNull();
  442. });
  443. it('skips the plate picker for single-plate sources', async () => {
  444. mockApi.getLibraryFilePlates.mockResolvedValue({
  445. file_id: 100,
  446. filename: 'Single.3mf',
  447. is_multi_plate: false,
  448. plates: [
  449. {
  450. index: 1,
  451. name: 'Plate 1',
  452. objects: [],
  453. has_thumbnail: false,
  454. thumbnail_url: null,
  455. print_time_seconds: null,
  456. filament_used_grams: null,
  457. filaments: [],
  458. },
  459. ],
  460. });
  461. renderWithTracker({
  462. source: { kind: 'libraryFile', id: 100, filename: 'Single.3mf' },
  463. onClose: vi.fn(),
  464. });
  465. // Should jump straight to the profile dropdowns.
  466. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  467. });
  468. it('passes the picked plate to the slice request', async () => {
  469. mockApi.getLibraryFilePlates.mockResolvedValue(makeMultiPlateLibraryResponse());
  470. mockApi.sliceLibraryFile.mockResolvedValue({
  471. job_id: 42,
  472. status: 'pending',
  473. status_url: '/api/v1/slice-jobs/42',
  474. });
  475. renderWithTracker({
  476. source: { kind: 'libraryFile', id: 100, filename: 'Multi.3mf' },
  477. onClose: vi.fn(),
  478. });
  479. const user = userEvent.setup();
  480. // Step 1: pick Plate 2.
  481. const plate2Button = await screen.findByRole('button', { name: /Plate 2.*Pyramid/ });
  482. await user.click(plate2Button);
  483. // Step 2: profile dropdowns are now visible.
  484. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  485. // Step 3: submit and verify the plate index made it into the body.
  486. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  487. await waitFor(() => {
  488. expect(mockApi.sliceLibraryFile).toHaveBeenCalledWith(
  489. 100,
  490. expect.objectContaining({ plate: 2 }),
  491. );
  492. });
  493. });
  494. it('"Slice all plates" toggle sends plate=0 sentinel to the backend (#1493)', async () => {
  495. mockApi.getLibraryFilePlates.mockResolvedValue(makeMultiPlateLibraryResponse());
  496. mockApi.sliceLibraryFile.mockResolvedValue({
  497. job_id: 42,
  498. status: 'pending',
  499. status_url: '/api/v1/slice-jobs/42',
  500. });
  501. renderWithTracker({
  502. source: { kind: 'libraryFile', id: 100, filename: 'Multi.3mf' },
  503. onClose: vi.fn(),
  504. });
  505. const user = userEvent.setup();
  506. const plate1Button = await screen.findByRole('button', { name: /Plate 1.*Cube/ });
  507. await user.click(plate1Button);
  508. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  509. // The "Slice all plates" checkbox only appears for multi-plate sources.
  510. const toggle = await screen.findByRole('checkbox', { name: /Slice all 2 plates/i });
  511. await user.click(toggle);
  512. // The action button's label flips to the "Slice all" form. Click it.
  513. await user.click(screen.getByRole('button', { name: /Slice all 2 plates/i }));
  514. await waitFor(() => {
  515. expect(mockApi.sliceLibraryFile).toHaveBeenCalledTimes(1);
  516. });
  517. const [, body] = mockApi.sliceLibraryFile.mock.calls[0];
  518. // ``plate=0`` is the BS CLI's all-plates sentinel — one slice call,
  519. // one output 3MF with every plate's gcode inside, one archive.
  520. expect((body as { plate?: number }).plate).toBe(0);
  521. });
  522. it('"Slice all plates" toggle is hidden for single-plate sources', async () => {
  523. mockApi.getLibraryFilePlates.mockResolvedValue({
  524. file_id: 100,
  525. filename: 'Single.3mf',
  526. is_multi_plate: false,
  527. plates: [
  528. {
  529. index: 1,
  530. name: 'Plate 1',
  531. objects: [],
  532. has_thumbnail: false,
  533. thumbnail_url: null,
  534. print_time_seconds: null,
  535. filament_used_grams: null,
  536. filaments: [],
  537. },
  538. ],
  539. });
  540. renderWithTracker({
  541. source: { kind: 'libraryFile', id: 100, filename: 'Single.3mf' },
  542. onClose: vi.fn(),
  543. });
  544. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  545. expect(screen.queryByRole('checkbox', { name: /Slice all/i })).toBeNull();
  546. });
  547. it('routes the plate fetch through getArchivePlates for archive sources', async () => {
  548. mockApi.getArchivePlates.mockResolvedValue({
  549. ...makeMultiPlateLibraryResponse(),
  550. archive_id: 100,
  551. filename: 'Multi.3mf',
  552. });
  553. renderWithTracker({
  554. source: { kind: 'archive', id: 100, filename: 'Multi.3mf' },
  555. onClose: vi.fn(),
  556. });
  557. await screen.findByRole('button', { name: /Plate 1.*Cube/ });
  558. expect(mockApi.getArchivePlates).toHaveBeenCalledWith(100);
  559. expect(mockApi.getLibraryFilePlates).not.toHaveBeenCalled();
  560. });
  561. it('cancelling the plate picker closes the entire slice flow', async () => {
  562. const onClose = vi.fn();
  563. mockApi.getLibraryFilePlates.mockResolvedValue(makeMultiPlateLibraryResponse());
  564. renderWithTracker({
  565. source: { kind: 'libraryFile', id: 100, filename: 'Multi.3mf' },
  566. onClose,
  567. });
  568. await screen.findByRole('button', { name: /Plate 1.*Cube/ });
  569. const user = userEvent.setup();
  570. await user.click(screen.getByRole('button', { name: /^Close$/i }));
  571. expect(onClose).toHaveBeenCalled();
  572. });
  573. it('omits the plate field when the source is single-plate', async () => {
  574. mockApi.sliceLibraryFile.mockResolvedValue({
  575. job_id: 42,
  576. status: 'pending',
  577. status_url: '/api/v1/slice-jobs/42',
  578. });
  579. renderWithTracker({
  580. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  581. onClose: vi.fn(),
  582. });
  583. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  584. const user = userEvent.setup();
  585. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  586. await waitFor(() => {
  587. const [, body] = mockApi.sliceLibraryFile.mock.calls[0];
  588. expect(body).not.toHaveProperty('plate');
  589. });
  590. });
  591. // ----- Multi-color flow ------------------------------------------------
  592. function makeMultiColorPlateResponse() {
  593. // Single-plate 3MF that uses two filament slots — mirrors the realistic
  594. // "I have a multi-color file with one plate" case. Multi-plate is a
  595. // separate axis that's already covered above.
  596. return {
  597. file_id: 100,
  598. filename: 'TwoColor.3mf',
  599. is_multi_plate: false,
  600. plates: [
  601. {
  602. index: 1,
  603. name: 'Plate 1',
  604. objects: ['Logo'],
  605. object_count: 1,
  606. has_thumbnail: false,
  607. thumbnail_url: null,
  608. print_time_seconds: 600,
  609. filament_used_grams: 20,
  610. filaments: [],
  611. },
  612. ],
  613. };
  614. }
  615. function makeMultiColorRequirementsResponse() {
  616. return {
  617. file_id: 100,
  618. filename: 'TwoColor.3mf',
  619. plate_id: 1,
  620. filaments: [
  621. { slot_id: 1, type: 'PLA', color: '#000000', used_grams: 10, used_meters: 3 },
  622. { slot_id: 2, type: 'PLA', color: '#FFFFFF', used_grams: 10, used_meters: 3 },
  623. ],
  624. };
  625. }
  626. function makeColorAwarePresets(): UnifiedPresetsResponse {
  627. // Two filament presets in cloud: one black PLA, one white PLA. Pre-pick
  628. // should match each plate slot to the same-colour preset so the user
  629. // doesn't have to manually align them.
  630. return {
  631. orca_cloud: { printer: [], process: [], filament: [] },
  632. cloud: {
  633. printer: [{ id: 'P1', name: 'X1C', source: 'cloud' }],
  634. process: [{ id: 'PR1', name: '0.20mm', source: 'cloud' }],
  635. filament: [
  636. { id: 'F-BLACK', name: 'Cloud PLA Black', source: 'cloud', filament_type: 'PLA', filament_colour: '#000000' },
  637. { id: 'F-WHITE', name: 'Cloud PLA White', source: 'cloud', filament_type: 'PLA', filament_colour: '#FFFFFF' },
  638. ],
  639. },
  640. local: { printer: [], process: [], filament: [] },
  641. standard: { printer: [], process: [], filament: [] },
  642. cloud_status: 'ok',
  643. orca_cloud_status: 'ok',
  644. };
  645. }
  646. it('renders one filament dropdown per plate slot when the source is multi-color', async () => {
  647. mockApi.getLibraryFilePlates.mockResolvedValue(makeMultiColorPlateResponse());
  648. mockApi.getLibraryFileFilamentRequirements.mockResolvedValue(makeMultiColorRequirementsResponse());
  649. mockApi.getSlicerPresets.mockResolvedValue(makeColorAwarePresets());
  650. renderWithTracker({
  651. source: { kind: 'libraryFile', id: 100, filename: 'TwoColor.3mf' },
  652. onClose: vi.fn(),
  653. });
  654. await waitFor(() => expect(screen.getByText('X1C')).toBeDefined());
  655. // 1 printer + 1 process + 2 filament + 1 bed-type (#1337) = 5 dropdowns.
  656. expect(presetSelects()).toHaveLength(5);
  657. });
  658. it('pre-picks each filament slot by matching colour metadata', async () => {
  659. mockApi.getLibraryFilePlates.mockResolvedValue(makeMultiColorPlateResponse());
  660. mockApi.getLibraryFileFilamentRequirements.mockResolvedValue(makeMultiColorRequirementsResponse());
  661. mockApi.getSlicerPresets.mockResolvedValue(makeColorAwarePresets());
  662. mockApi.sliceLibraryFile.mockResolvedValue({
  663. job_id: 42,
  664. status: 'pending',
  665. status_url: '/api/v1/slice-jobs/42',
  666. });
  667. renderWithTracker({
  668. source: { kind: 'libraryFile', id: 100, filename: 'TwoColor.3mf' },
  669. onClose: vi.fn(),
  670. });
  671. await waitFor(() => expect(screen.getByText('X1C')).toBeDefined());
  672. const user = userEvent.setup();
  673. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  674. await waitFor(() => {
  675. const [, body] = mockApi.sliceLibraryFile.mock.calls[0];
  676. // Slot 1 was black plate → cloud black preset; slot 2 was white →
  677. // cloud white preset. Pre-pick aligns them by metadata so the user
  678. // doesn't have to swap them manually.
  679. expect(body.filament_presets).toEqual([
  680. { source: 'cloud', id: 'F-BLACK' },
  681. { source: 'cloud', id: 'F-WHITE' },
  682. ]);
  683. });
  684. });
  685. it('still sends the legacy filament_preset for single-color flows', async () => {
  686. // Backwards-compat with backends / proxies that read the singular field.
  687. mockApi.sliceLibraryFile.mockResolvedValue({
  688. job_id: 42,
  689. status: 'pending',
  690. status_url: '/api/v1/slice-jobs/42',
  691. });
  692. renderWithTracker({
  693. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  694. onClose: vi.fn(),
  695. });
  696. await waitFor(() => expect(screen.getByText('My Custom X1C')).toBeDefined());
  697. const user = userEvent.setup();
  698. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  699. await waitFor(() => {
  700. const [, body] = mockApi.sliceLibraryFile.mock.calls[0];
  701. // Single-color path mirrors the array's first entry into the legacy
  702. // singular so older backend clients that only know about
  703. // `filament_preset` still work.
  704. expect(body.filament_preset).toEqual(body.filament_presets[0]);
  705. expect(body.filament_presets).toHaveLength(1);
  706. });
  707. });
  708. it('lets the user override a pre-picked filament slot', async () => {
  709. mockApi.getLibraryFilePlates.mockResolvedValue(makeMultiColorPlateResponse());
  710. mockApi.getLibraryFileFilamentRequirements.mockResolvedValue(makeMultiColorRequirementsResponse());
  711. mockApi.getSlicerPresets.mockResolvedValue(makeColorAwarePresets());
  712. mockApi.sliceLibraryFile.mockResolvedValue({
  713. job_id: 42,
  714. status: 'pending',
  715. status_url: '/api/v1/slice-jobs/42',
  716. });
  717. renderWithTracker({
  718. source: { kind: 'libraryFile', id: 100, filename: 'TwoColor.3mf' },
  719. onClose: vi.fn(),
  720. });
  721. await waitFor(() => expect(screen.getByText('X1C')).toBeDefined());
  722. const user = userEvent.setup();
  723. const selects = presetSelects();
  724. // Order: 0 printer, 1 process, 2 bed-type, 3 filament-1, 4 filament-2
  725. // (#1337). Auto-picks land on printer/process/filaments; bed-type
  726. // defaults to "". Swap filament-1 (index 3) from the auto-picked black
  727. // to white.
  728. await user.selectOptions(selects[3], 'cloud:F-WHITE');
  729. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  730. await waitFor(() => {
  731. const [, body] = mockApi.sliceLibraryFile.mock.calls[0];
  732. expect(body.filament_presets[0]).toEqual({ source: 'cloud', id: 'F-WHITE' });
  733. // Slot 1 stayed at the auto-picked white.
  734. expect(body.filament_presets[1]).toEqual({ source: 'cloud', id: 'F-WHITE' });
  735. });
  736. });
  737. // Cross-printer re-slicing is a normal, supported operation as of
  738. // 2026-05-20 (Step 0 empirical test: sidecar overrides printer / process
  739. // / bed / kinematics from the picked profile triplet, producing valid
  740. // target-printer G-code). No banner, no warning — the picker UI already
  741. // shows which printer the user picked, and that's enough.
  742. it('does not surface any cross-printer banner and keeps Slice enabled when models differ', async () => {
  743. mockApi.getLibraryFilePlates.mockResolvedValue({
  744. file_id: 100,
  745. filename: 'A1Original.3mf',
  746. is_multi_plate: false,
  747. plates: [
  748. {
  749. index: 1,
  750. name: 'Plate 1',
  751. objects: [],
  752. has_thumbnail: false,
  753. thumbnail_url: null,
  754. print_time_seconds: null,
  755. filament_used_grams: null,
  756. filaments: [],
  757. },
  758. ],
  759. });
  760. // Standard tier offers an X1C profile — the user picks (auto-picks) it.
  761. mockApi.getSlicerPresets.mockResolvedValue(makeUnified({
  762. standard: {
  763. printer: [{ id: 'Bambu Lab X1 Carbon 0.4 nozzle', name: 'Bambu Lab X1 Carbon 0.4 nozzle', source: 'standard' }],
  764. process: [{ id: '0.20mm Standard', name: '0.20mm Standard', source: 'standard' }],
  765. filament: [{ id: 'Bambu PLA Basic', name: 'Bambu PLA Basic', source: 'standard' }],
  766. },
  767. }));
  768. renderWithTracker({
  769. source: { kind: 'libraryFile', id: 100, filename: 'A1Original.3mf' },
  770. onClose: vi.fn(),
  771. });
  772. await waitFor(() =>
  773. expect(screen.getByText('Bambu Lab X1 Carbon 0.4 nozzle')).toBeDefined(),
  774. );
  775. // No banner, no alert — re-slicing across printers is just a normal slice now.
  776. expect(screen.queryByRole('alert')).toBeNull();
  777. const sliceButton = screen.getByRole('button', { name: /^Slice$/ }) as HTMLButtonElement;
  778. expect(sliceButton.disabled).toBe(false);
  779. });
  780. // The `used_in_plate` flag tells the modal which AMS slots are
  781. // actually consumed by the picked plate. Slots flagged as unused
  782. // are still rendered (the slicer CLI needs a profile per project
  783. // slot, otherwise it silently fills the gap from embedded defaults
  784. // and unwanted colours leak into the output) but disabled in the UI
  785. // so the user only interacts with the dropdowns that matter.
  786. it('disables filament dropdowns for slots not used by the picked plate', async () => {
  787. mockApi.getLibraryFilePlates.mockResolvedValue({
  788. file_id: 100,
  789. filename: 'Helmet.3mf',
  790. is_multi_plate: false,
  791. plates: [
  792. {
  793. index: 1,
  794. name: 'Plate 1',
  795. objects: ['Helmet'],
  796. has_thumbnail: false,
  797. thumbnail_url: null,
  798. print_time_seconds: 1200,
  799. filament_used_grams: 80,
  800. filaments: [],
  801. },
  802. ],
  803. });
  804. // Project has 2 AMS slots configured (white + grey support), but
  805. // plate 1 only paints with white (slot 1). The backend now returns
  806. // BOTH slots with used_in_plate flagging the difference.
  807. mockApi.getLibraryFileFilamentRequirements.mockResolvedValue({
  808. file_id: 100,
  809. filename: 'Helmet.3mf',
  810. plate_id: 1,
  811. filaments: [
  812. { slot_id: 1, type: 'PLA', color: '#FFFFFF', used_grams: 80, used_meters: 27, used_in_plate: true },
  813. { slot_id: 2, type: 'PLA', color: '#808080', used_grams: 0, used_meters: 0, used_in_plate: false },
  814. ],
  815. });
  816. mockApi.getSlicerPresets.mockResolvedValue({
  817. cloud: {
  818. printer: [{ id: 'P1', name: 'X1C', source: 'cloud' }],
  819. process: [{ id: 'PR1', name: '0.20mm', source: 'cloud' }],
  820. filament: [
  821. { id: 'F-WHITE', name: 'Cloud PLA White', source: 'cloud', filament_type: 'PLA', filament_colour: '#FFFFFF' },
  822. { id: 'F-GREY', name: 'Cloud PLA Grey', source: 'cloud', filament_type: 'PLA', filament_colour: '#808080' },
  823. ],
  824. },
  825. local: { printer: [], process: [], filament: [] },
  826. standard: { printer: [], process: [], filament: [] },
  827. cloud_status: 'ok',
  828. orca_cloud: { printer: [], process: [], filament: [] },
  829. orca_cloud_status: 'ok',
  830. });
  831. renderWithTracker({
  832. source: { kind: 'libraryFile', id: 100, filename: 'Helmet.3mf' },
  833. onClose: vi.fn(),
  834. });
  835. await waitFor(() => expect(screen.getByText('X1C')).toBeDefined());
  836. // Both filament rows render — 1 printer + 1 process + 1 bed-type +
  837. // 2 filament (#1337) = 5. bed-type sits at index 2, filament slots
  838. // follow at 3 and 4.
  839. const selects = presetSelects();
  840. expect(selects).toHaveLength(5);
  841. // Slot 1 (used) is editable, slot 2 (not used) is disabled.
  842. expect(selects[3].disabled).toBe(false);
  843. expect(selects[4].disabled).toBe(true);
  844. // The disabled row's label calls out why it's disabled.
  845. expect(screen.getByText(/not used by this plate/i)).toBeDefined();
  846. });
  847. it('still sends both filaments to the backend even when one slot is disabled', async () => {
  848. // The auto-pick scoring fills the disabled slot from project
  849. // metadata — the slicer CLI requires a profile for every project
  850. // slot, otherwise it silently fills the gap. The disabled UI is
  851. // purely cosmetic; the wire format must include the full list.
  852. mockApi.getLibraryFilePlates.mockResolvedValue({
  853. file_id: 100,
  854. filename: 'Helmet.3mf',
  855. is_multi_plate: false,
  856. plates: [
  857. {
  858. index: 1,
  859. name: 'Plate 1',
  860. objects: ['Helmet'],
  861. has_thumbnail: false,
  862. thumbnail_url: null,
  863. print_time_seconds: 1200,
  864. filament_used_grams: 80,
  865. filaments: [],
  866. },
  867. ],
  868. });
  869. mockApi.getLibraryFileFilamentRequirements.mockResolvedValue({
  870. file_id: 100,
  871. filename: 'Helmet.3mf',
  872. plate_id: 1,
  873. filaments: [
  874. { slot_id: 1, type: 'PLA', color: '#FFFFFF', used_grams: 80, used_meters: 27, used_in_plate: true },
  875. { slot_id: 2, type: 'PLA', color: '#808080', used_grams: 0, used_meters: 0, used_in_plate: false },
  876. ],
  877. });
  878. mockApi.getSlicerPresets.mockResolvedValue({
  879. cloud: {
  880. printer: [{ id: 'P1', name: 'X1C', source: 'cloud' }],
  881. process: [{ id: 'PR1', name: '0.20mm', source: 'cloud' }],
  882. filament: [
  883. { id: 'F-WHITE', name: 'Cloud PLA White', source: 'cloud', filament_type: 'PLA', filament_colour: '#FFFFFF' },
  884. { id: 'F-GREY', name: 'Cloud PLA Grey', source: 'cloud', filament_type: 'PLA', filament_colour: '#808080' },
  885. ],
  886. },
  887. local: { printer: [], process: [], filament: [] },
  888. standard: { printer: [], process: [], filament: [] },
  889. cloud_status: 'ok',
  890. orca_cloud: { printer: [], process: [], filament: [] },
  891. orca_cloud_status: 'ok',
  892. });
  893. mockApi.sliceLibraryFile.mockResolvedValue({
  894. job_id: 50,
  895. status: 'pending',
  896. status_url: '/api/v1/slice-jobs/50',
  897. });
  898. renderWithTracker({
  899. source: { kind: 'libraryFile', id: 100, filename: 'Helmet.3mf' },
  900. onClose: vi.fn(),
  901. });
  902. await waitFor(() => expect(screen.getByText('X1C')).toBeDefined());
  903. const user = userEvent.setup();
  904. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  905. await waitFor(() => {
  906. const [, body] = mockApi.sliceLibraryFile.mock.calls[0];
  907. // Both slots populated: slot 1 with the user's white pick, slot
  908. // 2 auto-picked with grey from the colour-match scoring.
  909. expect(body.filament_presets).toHaveLength(2);
  910. expect(body.filament_presets[0]).toEqual({ source: 'cloud', id: 'F-WHITE' });
  911. expect(body.filament_presets[1]).toEqual({ source: 'cloud', id: 'F-GREY' });
  912. });
  913. });
  914. // ------------------------------------------------------------------
  915. // Slicer Pipelines (#1425) — Apply / Save integration in SliceModal
  916. // ------------------------------------------------------------------
  917. it('Apply pipeline dropdown is disabled and shows empty hint when no pipelines exist', async () => {
  918. mockApi.listSlicerPipelines.mockResolvedValue({ pipelines: [] });
  919. renderWithTracker({
  920. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  921. onClose: vi.fn(),
  922. });
  923. await waitFor(() => {
  924. const select = screen.getByLabelText(/Apply pipeline/i) as HTMLSelectElement;
  925. expect(select.disabled).toBe(true);
  926. expect(select.querySelector('option')?.textContent).toMatch(/No saved pipelines/i);
  927. });
  928. });
  929. it('applies a saved pipeline to printer, process, and bed_type slots on selection', async () => {
  930. mockApi.listSlicerPipelines.mockResolvedValue({
  931. pipelines: [
  932. {
  933. id: 7,
  934. name: 'Production Batch',
  935. description: null,
  936. printer_preset: { source: 'local', id: '1' },
  937. process_preset: { source: 'local', id: '2' },
  938. filament_presets: [{ source: 'local', id: '3' }],
  939. bed_type: 'Textured PEI Plate',
  940. target_kind: 'printer_class',
  941. target_printer_id: null,
  942. target_model_class: null,
  943. fanout_strategy: 'max_parallel',
  944. created_by: null,
  945. created_at: '2026-06-27T00:00:00Z',
  946. updated_at: '2026-06-27T00:00:00Z',
  947. },
  948. ],
  949. });
  950. renderWithTracker({
  951. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  952. onClose: vi.fn(),
  953. });
  954. // Wait for presets + pipelines listing to populate the modal.
  955. await waitFor(() => {
  956. const select = screen.getByLabelText(/Apply pipeline/i) as HTMLSelectElement;
  957. expect(select.disabled).toBe(false);
  958. expect(within(select).getByText('Production Batch')).toBeDefined();
  959. });
  960. const user = userEvent.setup();
  961. await user.selectOptions(screen.getByLabelText(/Apply pipeline/i), '7');
  962. // After applying, submitting the slice request should carry the
  963. // pipeline's preset refs end-to-end.
  964. mockApi.sliceLibraryFile.mockResolvedValue({
  965. job_id: 42,
  966. status: 'queued',
  967. status_url: '/api/v1/slice-jobs/42',
  968. });
  969. await user.click(screen.getByRole('button', { name: /^Slice$/ }));
  970. await waitFor(() => {
  971. expect(mockApi.sliceLibraryFile).toHaveBeenCalled();
  972. const [, body] = mockApi.sliceLibraryFile.mock.calls[0];
  973. expect(body.printer_preset).toEqual({ source: 'local', id: '1' });
  974. expect(body.process_preset).toEqual({ source: 'local', id: '2' });
  975. expect(body.filament_presets[0]).toEqual({ source: 'local', id: '3' });
  976. expect(body.bed_type).toBe('Textured PEI Plate');
  977. });
  978. });
  979. it('saves the current four-slot selection as a new pipeline when the user clicks Save as pipeline', async () => {
  980. mockApi.listSlicerPipelines.mockResolvedValue({ pipelines: [] });
  981. mockApi.createSlicerPipeline.mockResolvedValue({
  982. id: 99,
  983. name: 'My Default',
  984. description: null,
  985. printer_preset: { source: 'local', id: '1' },
  986. process_preset: { source: 'local', id: '2' },
  987. filament_presets: [{ source: 'local', id: '3' }],
  988. bed_type: null,
  989. target_kind: 'printer_class',
  990. target_printer_id: null,
  991. target_model_class: null,
  992. fanout_strategy: 'max_parallel',
  993. created_by: null,
  994. created_at: '2026-06-27T00:00:00Z',
  995. updated_at: '2026-06-27T00:00:00Z',
  996. });
  997. renderWithTracker({
  998. source: { kind: 'libraryFile', id: 100, filename: 'Cube.stl' },
  999. onClose: vi.fn(),
  1000. });
  1001. // Wait for auto-pick to populate all four slots from the fullThreeTier
  1002. // listing — then Save as pipeline becomes enabled.
  1003. const user = userEvent.setup();
  1004. let saveBtn: HTMLButtonElement;
  1005. await waitFor(() => {
  1006. saveBtn = screen.getByRole('button', { name: /^Save as pipeline$/ }) as HTMLButtonElement;
  1007. expect(saveBtn.disabled).toBe(false);
  1008. });
  1009. await user.click(saveBtn!);
  1010. const nameInput = screen.getByLabelText(/New pipeline name/i);
  1011. await user.type(nameInput, 'My Default');
  1012. await user.click(screen.getByRole('button', { name: /^Save$/ }));
  1013. await waitFor(() => {
  1014. expect(mockApi.createSlicerPipeline).toHaveBeenCalledTimes(1);
  1015. const body = mockApi.createSlicerPipeline.mock.calls[0][0];
  1016. expect(body.name).toBe('My Default');
  1017. // The four slots come from the auto-picked unified-presets listing —
  1018. // local tier wins per SLICE_MODAL_TIER_ORDER.
  1019. expect(body.printer_preset.source).toBe('local');
  1020. expect(body.process_preset.source).toBe('local');
  1021. expect(body.filament_presets[0].source).toBe('local');
  1022. });
  1023. });
  1024. });