SliceModal.test.tsx 41 KB

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