| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399 |
- /**
- * Tests for the ConfigureAmsSlotModal component.
- */
- import { describe, it, expect, vi, beforeEach } from 'vitest';
- import { screen, fireEvent, waitFor } from '@testing-library/react';
- import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
- import { render } from '../utils';
- import { ConfigureAmsSlotModal } from '../../components/ConfigureAmsSlotModal';
- import { api } from '../../api/client';
- // Mock the API client
- vi.mock('../../api/client', () => ({
- api: {
- getCloudSettings: vi.fn(),
- getKProfiles: vi.fn(),
- configureAmsSlot: vi.fn(),
- getCloudSettingDetail: vi.fn(),
- saveSlotPreset: vi.fn(),
- getSettings: vi.fn().mockResolvedValue({}),
- // Queried by the modal for the @BBL short-code matcher. Omitted, it is
- // undefined here, so the query runs with no queryFn and rejects -- a
- // stray render at an unpredictable moment in every one of these tests.
- getSlicerPrinterModels: vi.fn().mockResolvedValue({}),
- updateSettings: vi.fn().mockResolvedValue({}),
- getLocalPresets: vi.fn(),
- getBuiltinFilaments: vi.fn(),
- orcaCloudListProfiles: vi.fn(),
- orcaCloudGetProfile: vi.fn(),
- searchColors: vi.fn(),
- getColorCatalog: vi.fn(),
- resetAmsSlot: vi.fn(),
- // The fitted nozzle's flow; none reported unless a test sets one.
- getPrinterStatus: vi.fn().mockResolvedValue({}),
- },
- }));
- const mockCloudSettings = {
- filament: [
- {
- setting_id: 'GFSL05_09',
- name: 'Bambu PLA Basic @BBL X1C',
- filament_id: 'GFL05',
- },
- {
- setting_id: 'PFUScd84f663d2c2ef',
- name: '# Overture Matte PLA @BBL H2D',
- filament_id: null,
- },
- ],
- };
- const mockKProfiles = {
- profiles: [
- {
- id: 1,
- name: 'PLA Basic',
- k_value: '0.020',
- filament_id: 'GFL05',
- setting_id: '',
- extruder_id: 1,
- cali_idx: 1,
- },
- ],
- };
- const defaultProps = {
- isOpen: true,
- onClose: vi.fn(),
- printerId: 1,
- slotInfo: {
- amsId: 0,
- trayId: 0,
- trayType: 'PLA',
- trayColor: 'FFFFFF',
- traySubBrands: 'PLA Basic',
- },
- nozzleDiameter: '0.4',
- onSuccess: vi.fn(),
- };
- describe('ConfigureAmsSlotModal', () => {
- beforeEach(() => {
- vi.clearAllMocks();
- (api.getPrinterStatus as ReturnType<typeof vi.fn>).mockResolvedValue({});
- // Mock scrollIntoView which is not available in jsdom
- Element.prototype.scrollIntoView = vi.fn();
- (api.getCloudSettings as ReturnType<typeof vi.fn>).mockResolvedValue(mockCloudSettings);
- (api.getKProfiles as ReturnType<typeof vi.fn>).mockResolvedValue(mockKProfiles);
- (api.configureAmsSlot as ReturnType<typeof vi.fn>).mockResolvedValue({ success: true });
- (api.saveSlotPreset as ReturnType<typeof vi.fn>).mockResolvedValue({ success: true });
- (api.getLocalPresets as ReturnType<typeof vi.fn>).mockResolvedValue({ filament: [] });
- (api.orcaCloudListProfiles as ReturnType<typeof vi.fn>).mockResolvedValue({
- filament: [], printer: [], process: [],
- });
- (api.getBuiltinFilaments as ReturnType<typeof vi.fn>).mockResolvedValue([]);
- (api.searchColors as ReturnType<typeof vi.fn>).mockResolvedValue([]);
- (api.getColorCatalog as ReturnType<typeof vi.fn>).mockResolvedValue([]);
- (api.resetAmsSlot as ReturnType<typeof vi.fn>).mockResolvedValue({ success: true, message: 'ok' });
- });
- it('renders nothing visible when closed', () => {
- render(<ConfigureAmsSlotModal {...defaultProps} isOpen={false} />);
- expect(screen.queryByText('Configure AMS Slot')).not.toBeInTheDocument();
- });
- it('renders a clear tray as the transparency checkerboard rather than solid black (#2912)', () => {
- render(
- <ConfigureAmsSlotModal
- {...defaultProps}
- slotInfo={{ ...defaultProps.slotInfo, trayType: 'PETG', trayColor: '00000000' }}
- />,
- );
- const styled = Array.from(document.querySelectorAll<HTMLElement>('[style]'));
- expect(
- styled.some((el) => el.style.backgroundImage.includes('repeating-conic-gradient')),
- ).toBe(true);
- // The regression this pins: the alpha byte was sliced off before painting,
- // so a clear tray rendered as opaque black — the reported symptom, in the UI.
- expect(styled.some((el) => el.style.backgroundColor === 'rgb(0, 0, 0)')).toBe(false);
- });
- it('renders modal when open', async () => {
- render(<ConfigureAmsSlotModal {...defaultProps} />);
- await waitFor(() => {
- expect(screen.getByText(/Configure AMS/)).toBeInTheDocument();
- });
- });
- it('displays basic color buttons', async () => {
- render(<ConfigureAmsSlotModal {...defaultProps} />);
- await waitFor(() => {
- // Check for basic color buttons by their title attribute
- expect(screen.getByTitle('White')).toBeInTheDocument();
- expect(screen.getByTitle('Black')).toBeInTheDocument();
- expect(screen.getByTitle('Red')).toBeInTheDocument();
- expect(screen.getByTitle('Blue')).toBeInTheDocument();
- expect(screen.getByTitle('Green')).toBeInTheDocument();
- expect(screen.getByTitle('Yellow')).toBeInTheDocument();
- expect(screen.getByTitle('Orange')).toBeInTheDocument();
- expect(screen.getByTitle('Gray')).toBeInTheDocument();
- });
- });
- it('does not show extended colors by default', async () => {
- render(<ConfigureAmsSlotModal {...defaultProps} />);
- await waitFor(() => {
- expect(screen.getByTitle('White')).toBeInTheDocument();
- });
- // Extended colors should not be visible initially
- expect(screen.queryByTitle('Cyan')).not.toBeInTheDocument();
- expect(screen.queryByTitle('Purple')).not.toBeInTheDocument();
- expect(screen.queryByTitle('Coral')).not.toBeInTheDocument();
- });
- it('shows extended colors when expand button is clicked', async () => {
- render(<ConfigureAmsSlotModal {...defaultProps} />);
- await waitFor(() => {
- expect(screen.getByTitle('White')).toBeInTheDocument();
- });
- // Click the expand button (+ button)
- const expandButton = screen.getByTitle('Show more colors');
- fireEvent.click(expandButton);
- // Extended colors should now be visible
- await waitFor(() => {
- expect(screen.getByTitle('Cyan')).toBeInTheDocument();
- expect(screen.getByTitle('Purple')).toBeInTheDocument();
- expect(screen.getByTitle('Pink')).toBeInTheDocument();
- expect(screen.getByTitle('Brown')).toBeInTheDocument();
- expect(screen.getByTitle('Coral')).toBeInTheDocument();
- });
- });
- it('hides extended colors when collapse button is clicked', async () => {
- render(<ConfigureAmsSlotModal {...defaultProps} />);
- await waitFor(() => {
- expect(screen.getByTitle('White')).toBeInTheDocument();
- });
- // Click the expand button
- const expandButton = screen.getByTitle('Show more colors');
- fireEvent.click(expandButton);
- // Wait for extended colors to appear
- await waitFor(() => {
- expect(screen.getByTitle('Cyan')).toBeInTheDocument();
- });
- // Click the collapse button
- const collapseButton = screen.getByTitle('Show less colors');
- fireEvent.click(collapseButton);
- // Extended colors should be hidden again
- await waitFor(() => {
- expect(screen.queryByTitle('Cyan')).not.toBeInTheDocument();
- });
- });
- it('selects a color when color button is clicked', async () => {
- render(<ConfigureAmsSlotModal {...defaultProps} />);
- await waitFor(() => {
- expect(screen.getByTitle('Red')).toBeInTheDocument();
- });
- // Click the red color button
- const redButton = screen.getByTitle('Red');
- fireEvent.click(redButton);
- // The color input should now show "Red"
- const colorInput = screen.getByPlaceholderText(/Color name or hex/);
- expect(colorInput).toHaveValue('Red');
- });
- it('sends no tray_info_idx when cloud detail has filament_id: null (#3003)', async () => {
- // Cloud returns a user preset that inherits from a generic Bambu base and
- // has no distinct filament_id of its own — this is how Bambu Cloud responds
- // for custom presets built on top of "Generic ABS @BBL H2D" etc.
- (api.getCloudSettingDetail as ReturnType<typeof vi.fn>).mockResolvedValue({
- filament_id: null,
- base_id: 'GFSB99_07',
- name: '# Overture Matte PLA @BBL H2D',
- });
- const slotInfo = {
- ...defaultProps.slotInfo,
- savedPresetId: 'PFUScd84f663d2c2ef',
- };
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={slotInfo} />);
- await waitFor(() => {
- expect(screen.getByText('# Overture Matte PLA @BBL H2D')).toBeInTheDocument();
- });
- fireEvent.click(screen.getByRole('button', { name: /Configure Slot/i }));
- await waitFor(() => {
- expect(api.configureAmsSlot).toHaveBeenCalled();
- });
- const payload = (api.configureAmsSlot as ReturnType<typeof vi.fn>).mock.calls[0][3];
- // #1053 sent the PFUS here instead, to stop the slot collapsing to
- // "Generic ABS" in the slicer. The A1 capture in #3003 showed that does not
- // work: tray_info_idx is 8 characters on the printer, so an 18-character
- // PFUS is stored truncated (PFUScd84 here) and acknowledged as a success.
- // The slot then resolves to nothing — "Generic" anyway, plus a calibration
- // table keyed by an id that does not exist. Sending nothing lets the
- // backend pick a filament id the printer can actually hold; setting_id
- // still carries the preset.
- expect(payload.tray_info_idx).toBe('');
- expect(payload.setting_id).toBe('PFUScd84f663d2c2ef');
- });
- it('has the backend resolve an Orca Cloud profile\'s own filament_id (#3003, #3216)', async () => {
- // OrcaSlicer's "Sync filaments" matches a slot by filament_id alone, so a
- // generic here turns the profile into "Generic PLA" in the slicer. The
- // lookup used to run here and fall back silently; it now runs in configure,
- // which logs the outcome and reports a fallback.
- const ORCA_ID = '3f2a9c1e-4b7d-4a02-9f61-8c5e2d1a7b30';
- (api.orcaCloudListProfiles as ReturnType<typeof vi.fn>).mockResolvedValue({
- filament: [{ setting_id: ORCA_ID, name: 'Overture Matte PLA @Orca', type: 'filament', is_custom: true }],
- printer: [],
- process: [],
- });
- (api.configureAmsSlot as ReturnType<typeof vi.fn>).mockResolvedValue({
- success: true, tray_info_idx: 'P56e1be0', orca_fallback_reason: '',
- });
- const slotInfo = { ...defaultProps.slotInfo, savedPresetId: ORCA_ID };
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={slotInfo} />);
- await waitFor(() => {
- expect(screen.getByText('Overture Matte PLA @Orca')).toBeInTheDocument();
- });
- fireEvent.click(screen.getByRole('button', { name: /Configure Slot/i }));
- await waitFor(() => {
- expect(api.saveSlotPreset).toHaveBeenCalled();
- });
- const payload = (api.configureAmsSlot as ReturnType<typeof vi.fn>).mock.calls[0][3];
- expect(payload.orca_profile_id).toBe(ORCA_ID);
- expect(payload.tray_info_idx).toBe('');
- // The UUID is what the slicer cannot resolve; it goes in neither field.
- expect(payload.setting_id).toBe('');
- expect(api.orcaCloudGetProfile).not.toHaveBeenCalled();
- // The slot preset row records the id the slot was actually given, so the
- // slot card notices when the Device tab re-configures the slot.
- const saveArgs = (api.saveSlotPreset as ReturnType<typeof vi.fn>).mock.calls[0];
- expect(saveArgs[5]).toBe('orca_cloud');
- expect(saveArgs[6]).toBe('P56e1be0');
- expect(screen.queryByText(/OrcaSlicer will see this slot as Generic/)).not.toBeInTheDocument();
- });
- it('warns when an Orca profile went into the slot as a generic (#3216)', async () => {
- const ORCA_ID = '3f2a9c1e-4b7d-4a02-9f61-8c5e2d1a7b30';
- (api.orcaCloudListProfiles as ReturnType<typeof vi.fn>).mockResolvedValue({
- filament: [{ setting_id: ORCA_ID, name: 'Homebrew PLA @Orca', type: 'filament', is_custom: true }],
- printer: [],
- process: [],
- });
- (api.configureAmsSlot as ReturnType<typeof vi.fn>).mockResolvedValue({
- success: true, tray_info_idx: 'GFL99', orca_fallback_reason: 'no_filament_id',
- });
- const slotInfo = { ...defaultProps.slotInfo, savedPresetId: ORCA_ID };
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={slotInfo} />);
- await waitFor(() => {
- expect(screen.getByText('Homebrew PLA @Orca')).toBeInTheDocument();
- });
- fireEvent.click(screen.getByRole('button', { name: /Configure Slot/i }));
- expect(
- await screen.findByText(
- 'This Orca profile has no filament ID of its own, so OrcaSlicer will see this slot as Generic PLA.',
- ),
- ).toBeInTheDocument();
- });
- it('warns when a manual K value could not be sent (FW-C5)', async () => {
- // The route used to report the slot configured either way.
- const ORCA_ID = '3f2a9c1e-4b7d-4a02-9f61-8c5e2d1a7b30';
- (api.orcaCloudListProfiles as ReturnType<typeof vi.fn>).mockResolvedValue({
- filament: [{ setting_id: ORCA_ID, name: 'Homebrew PLA @Orca', type: 'filament', is_custom: true }],
- printer: [],
- process: [],
- });
- (api.configureAmsSlot as ReturnType<typeof vi.fn>).mockResolvedValue({
- success: true, tray_info_idx: 'P56e1be0', orca_fallback_reason: '', k_value_unsent: true,
- });
- const slotInfo = { ...defaultProps.slotInfo, savedPresetId: ORCA_ID };
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={slotInfo} />);
- await waitFor(() => {
- expect(screen.getByText('Homebrew PLA @Orca')).toBeInTheDocument();
- });
- fireEvent.click(screen.getByRole('button', { name: /Configure Slot/i }));
- expect(
- await screen.findByText('The filament was set, but the K value could not be sent to the printer.'),
- ).toBeInTheDocument();
- });
- it('uses the filament_id nested under setting when the envelope has none (#3003)', async () => {
- // Bambu Cloud returns a custom preset's own filament_id on the envelope for
- // some presets and inside the preset JSON for others. Only the envelope was
- // read, so presets of the second shape reached the slot as their inherited
- // base — the "Bambu profile instead of my profile" half of #3003.
- (api.getCloudSettingDetail as ReturnType<typeof vi.fn>).mockResolvedValue({
- filament_id: null,
- base_id: 'GFSB99_07',
- name: '# Overture Matte PLA @BBL H2D',
- setting: { filament_id: 'P4d64437' },
- });
- const slotInfo = {
- ...defaultProps.slotInfo,
- savedPresetId: 'PFUScd84f663d2c2ef',
- };
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={slotInfo} />);
- await waitFor(() => {
- expect(screen.getByText('# Overture Matte PLA @BBL H2D')).toBeInTheDocument();
- });
- fireEvent.click(screen.getByRole('button', { name: /Configure Slot/i }));
- await waitFor(() => {
- expect(api.configureAmsSlot).toHaveBeenCalled();
- });
- const payload = (api.configureAmsSlot as ReturnType<typeof vi.fn>).mock.calls[0][3];
- // 8 characters, so the printer stores it whole and the slicer matches it.
- expect(payload.tray_info_idx).toBe('P4d64437');
- expect(payload.setting_id).toBe('PFUScd84f663d2c2ef');
- });
- it('uses cloud detail filament_id when present', async () => {
- (api.getCloudSettingDetail as ReturnType<typeof vi.fn>).mockResolvedValue({
- filament_id: 'P285e239',
- base_id: 'GFSB99_07',
- name: '# Overture Matte PLA @BBL H2D',
- });
- const slotInfo = {
- ...defaultProps.slotInfo,
- savedPresetId: 'PFUScd84f663d2c2ef',
- };
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={slotInfo} />);
- await waitFor(() => {
- expect(screen.getByText('# Overture Matte PLA @BBL H2D')).toBeInTheDocument();
- });
- fireEvent.click(screen.getByRole('button', { name: /Configure Slot/i }));
- await waitFor(() => {
- expect(api.configureAmsSlot).toHaveBeenCalled();
- });
- const payload = (api.configureAmsSlot as ReturnType<typeof vi.fn>).mock.calls[0][3];
- expect(payload.tray_info_idx).toBe('P285e239');
- expect(payload.setting_id).toBe('PFUScd84f663d2c2ef');
- });
- it('sends short GF filament_id for Bambu GFS* presets (cloud detail not consulted)', async () => {
- // Bambu-provided presets (GFS*) convert the setting_id → filament_id locally.
- // The cloud detail endpoint must NOT be consulted for them; the rewrite that
- // fixed #1053 preserves this pre-existing shortcut.
- const slotInfo = {
- ...defaultProps.slotInfo,
- savedPresetId: 'GFSL05_09',
- };
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={slotInfo} />);
- await waitFor(() => {
- expect(screen.getByText('Bambu PLA Basic @BBL X1C')).toBeInTheDocument();
- });
- fireEvent.click(screen.getByRole('button', { name: /Configure Slot/i }));
- await waitFor(() => {
- expect(api.configureAmsSlot).toHaveBeenCalled();
- });
- const payload = (api.configureAmsSlot as ReturnType<typeof vi.fn>).mock.calls[0][3];
- expect(payload.tray_info_idx).toBe('GFL05');
- expect(payload.setting_id).toBe('GFSL05_09');
- expect(api.getCloudSettingDetail).not.toHaveBeenCalled();
- });
- it.each([
- // Bambu's list carries the preset's own id; a new preset needs no rule.
- ['from Bambu\'s list', 'GFSX01_02', 'New Filament @BBL A1', 'GFX07', 'GFX07'],
- // An older backend sends no filament_id; the rule knows SUNLU's shape and
- // the presets that carry another filament's id.
- ['without one in the list', 'GFSNLS03_04', 'SUNLU PLA+ @BBL A1', null, 'GFSNL03'],
- ['without one in the list', 'GFSA05_10', 'Bambu PLA Matte @BBL P1P', undefined, 'GFA01'],
- ])('sends a GFS* preset\'s own filament_id %s (#3387)', async (_how, settingId, name, listed, expected) => {
- (api.getCloudSettings as ReturnType<typeof vi.fn>).mockResolvedValue({
- filament: [{ setting_id: settingId, name, filament_id: listed }],
- });
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={{ ...defaultProps.slotInfo, savedPresetId: settingId }} />);
- await waitFor(() => {
- expect(screen.getByText(name)).toBeInTheDocument();
- });
- fireEvent.click(screen.getByRole('button', { name: /Configure Slot/i }));
- await waitFor(() => {
- expect(api.configureAmsSlot).toHaveBeenCalled();
- });
- const payload = (api.configureAmsSlot as ReturnType<typeof vi.fn>).mock.calls[0][3];
- expect(payload.tray_info_idx).toBe(expected);
- expect(payload.setting_id).toBe(settingId);
- });
- // "GFSR99" is Generic TPU (GFU99) in Bambu's list, and the id Bambuddy
- // itself saves for a Generic EVA (GFR99) slot; "GFSA05" likewise is Bambu
- // PLA Matte @BBL X1 (GFA01) and Bambuddy's id for Bambu PLA Silk (GFA05).
- const BARE = [
- { setting_id: 'GFSR99', name: 'Generic TPU', filament_id: 'GFU99' },
- { setting_id: 'GFSA05', name: 'Bambu PLA Matte @BBL X1', filament_id: 'GFA01' },
- ];
- it('sends the list\'s filament_id for a bare preset picked from the list (#3387)', async () => {
- (api.getCloudSettings as ReturnType<typeof vi.fn>).mockResolvedValue({ filament: BARE });
- render(<ConfigureAmsSlotModal {...defaultProps} />);
- await waitFor(() => {
- expect(screen.getByText('Generic TPU')).toBeInTheDocument();
- });
- fireEvent.click(screen.getByText('Generic TPU'));
- await waitFor(() => {
- expect(screen.getByRole('button', { name: /Configure Slot/i })).not.toBeDisabled();
- });
- fireEvent.click(screen.getByRole('button', { name: /Configure Slot/i }));
- await waitFor(() => {
- expect(api.configureAmsSlot).toHaveBeenCalled();
- });
- expect((api.configureAmsSlot as ReturnType<typeof vi.fn>).mock.calls[0][3].tray_info_idx).toBe('GFU99');
- });
- it.each([
- ['a Silk slot Bambuddy saved', 'GFSA05', 'GFA05', 'GFA05'],
- ['a Generic TPU slot picked from the list', 'GFSR99', 'GFU99', 'GFU99'],
- ['a slot reporting neither', 'GFSR99', undefined, 'GFR99'],
- ])('keeps the filament of %s when it is saved again (#3387)', async (_what, saved, tray, expected) => {
- (api.getCloudSettings as ReturnType<typeof vi.fn>).mockResolvedValue({ filament: BARE });
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={{ ...defaultProps.slotInfo, savedPresetId: saved, trayInfoIdx: tray }} />);
- await waitFor(() => {
- expect(screen.getByText(BARE.find(p => p.setting_id === saved)!.name)).toBeInTheDocument();
- expect(screen.getByRole('button', { name: /Configure Slot/i })).not.toBeDisabled();
- });
- fireEvent.click(screen.getByRole('button', { name: /Configure Slot/i }));
- await waitFor(() => {
- expect(api.configureAmsSlot).toHaveBeenCalled();
- });
- expect((api.configureAmsSlot as ReturnType<typeof vi.fn>).mock.calls[0][3].tray_info_idx).toBe(expected);
- });
- it('pre-selects a SUNLU preset from the id the slot reports (#3387)', async () => {
- (api.getCloudSettings as ReturnType<typeof vi.fn>).mockResolvedValue({
- filament: [{ setting_id: 'GFSNLS03_04', name: 'SUNLU PLA+ @BBL A1', filament_id: 'GFSNL03' }],
- });
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={{ ...defaultProps.slotInfo, trayInfoIdx: 'GFSNL03' }} />);
- await waitFor(() => {
- expect(screen.getByText('SUNLU PLA+ @BBL A1')).toBeInTheDocument();
- });
- await waitFor(() => {
- expect(screen.getByRole('button', { name: /Configure Slot/i })).not.toBeDisabled();
- });
- fireEvent.click(screen.getByRole('button', { name: /Configure Slot/i }));
- await waitFor(() => {
- expect(api.configureAmsSlot).toHaveBeenCalled();
- });
- expect((api.configureAmsSlot as ReturnType<typeof vi.fn>).mock.calls[0][3].setting_id).toBe('GFSNLS03_04');
- });
- it('sends no tray_info_idx when the cloud detail fetch fails (#3003)', async () => {
- // Network/5xx from /cloud/settings/{id} must not abort the configure flow.
- // It leaves no filament_id to send, and the PFUS default is not a usable
- // stand-in (see the filament_id: null case above), so the field goes out
- // empty and the backend resolves it.
- (api.getCloudSettingDetail as ReturnType<typeof vi.fn>).mockRejectedValue(
- new Error('cloud unreachable')
- );
- const slotInfo = {
- ...defaultProps.slotInfo,
- savedPresetId: 'PFUScd84f663d2c2ef',
- };
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={slotInfo} />);
- await waitFor(() => {
- expect(screen.getByText('# Overture Matte PLA @BBL H2D')).toBeInTheDocument();
- });
- fireEvent.click(screen.getByRole('button', { name: /Configure Slot/i }));
- await waitFor(() => {
- expect(api.configureAmsSlot).toHaveBeenCalled();
- });
- const payload = (api.configureAmsSlot as ReturnType<typeof vi.fn>).mock.calls[0][3];
- expect(payload.tray_info_idx).toBe('');
- expect(payload.setting_id).toBe('PFUScd84f663d2c2ef');
- });
- it('renders configure slot button', async () => {
- render(<ConfigureAmsSlotModal {...defaultProps} />);
- await waitFor(() => {
- expect(screen.getByText(/Configure AMS/)).toBeInTheDocument();
- });
- // Find the Configure Slot button
- const configureButton = screen.getByRole('button', { name: /Configure Slot/i });
- expect(configureButton).toBeInTheDocument();
- });
- it('filters presets by printer model', async () => {
- // Render with printerModel="H2D"
- render(<ConfigureAmsSlotModal {...defaultProps} printerModel="H2D" />);
- // Wait for presets to load - the H2D preset should be visible
- await waitFor(() => {
- expect(screen.getByText(/Overture Matte PLA/)).toBeInTheDocument();
- });
- // The X1C preset should NOT be visible (filtered out by model)
- expect(screen.queryByText(/Bambu PLA Basic @BBL X1C/)).not.toBeInTheDocument();
- });
- it('treats Bambu cloud rename @BBL A1M as a match for A1 Mini (#1649)', async () => {
- // Bambu cloud shifted A1 Mini filament profiles from
- // "Bambu PLA Basic @BBL A1 Mini ..." to the terse "@BBL A1M" mid-2026.
- // Without an alias-aware compare, the model filter strips every cloud
- // profile from the picker when the user selects an A1 Mini printer.
- (api.getCloudSettings as ReturnType<typeof vi.fn>).mockResolvedValue({
- filament: [
- { setting_id: 'GFA00_A1M', name: 'Bambu PLA Basic @BBL A1M', filament_id: 'GFA00' },
- { setting_id: 'GFA00_A1', name: 'Bambu PLA Basic @BBL A1', filament_id: 'GFA00' },
- ],
- });
- render(<ConfigureAmsSlotModal {...defaultProps} printerModel="A1 Mini" />);
- await waitFor(() => {
- expect(screen.getByText('Bambu PLA Basic @BBL A1M')).toBeInTheDocument();
- });
- // The A1 (non-mini) preset must still be filtered out — the alias
- // table must not collapse two physically distinct printers.
- expect(screen.queryByText('Bambu PLA Basic @BBL A1')).not.toBeInTheDocument();
- });
- it('still filters cross-model cloud profiles when the printer is A1 Mini', async () => {
- // Sanity check that the alias addition didn't accidentally widen the
- // matcher: an X1C cloud preset stays hidden when the picker is for an
- // A1 Mini printer.
- render(<ConfigureAmsSlotModal {...defaultProps} printerModel="A1 Mini" />);
- await waitFor(() => {
- expect(screen.getByText(/Configure AMS/)).toBeInTheDocument();
- });
- expect(screen.queryByText('Bambu PLA Basic @BBL X1C')).not.toBeInTheDocument();
- });
- it('shows current preset even when it does not match model filter', async () => {
- // Render with printerModel="H2D" but savedPresetId pointing to the X1C preset
- const slotInfo = {
- ...defaultProps.slotInfo,
- savedPresetId: 'GFSL05_09', // X1C preset
- };
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={slotInfo} printerModel="H2D" />);
- await waitFor(() => {
- // Both should be visible - H2D matches model, X1C is saved preset
- // Use the full preset name to match the list item (not the "Filtering for" label)
- expect(screen.getByText('Bambu PLA Basic @BBL X1C')).toBeInTheDocument();
- expect(screen.getByText(/Overture Matte PLA/)).toBeInTheDocument();
- });
- });
- it('preset row expands inline on hover so the full name is readable (#1237)', async () => {
- // Long preset names (e.g. "SUNLU PETG GLOW IN THE DARK GEN2 @Bambu Lab H2C 0.4 nozzle")
- // get visually truncated; the row un-truncates on hover via group-hover so the
- // nozzle suffix is readable without waiting on the browser's title-tooltip delay,
- // and the title attribute remains as a fallback for assistive tech / touch.
- render(<ConfigureAmsSlotModal {...defaultProps} />);
- await waitFor(() => {
- const fullName = 'Bambu PLA Basic @BBL X1C';
- const span = screen.getByText(fullName);
- expect(span).toHaveAttribute('title', fullName);
- expect(span).toHaveClass('truncate');
- expect(span).toHaveClass('group-hover:whitespace-normal');
- expect(span).toHaveClass('group-hover:break-all');
- expect(span.closest('button')).toHaveClass('group');
- });
- });
- it('pre-selects saved preset when opening configured slot', async () => {
- const slotInfo = {
- ...defaultProps.slotInfo,
- savedPresetId: 'GFSL05_09',
- };
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={slotInfo} />);
- await waitFor(() => {
- // The saved preset should have the selected style (green border)
- // Use the full preset name to avoid matching the "Filtering for" label
- const presetButton = screen.getByText('Bambu PLA Basic @BBL X1C').closest('button');
- expect(presetButton).toHaveClass('bg-bambu-green/20');
- });
- });
- it('pre-populates color from trayColor', async () => {
- const slotInfo = {
- ...defaultProps.slotInfo,
- trayColor: 'FF0000FF', // Red with alpha
- };
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={slotInfo} />);
- await waitFor(() => {
- expect(screen.getByTitle('White')).toBeInTheDocument();
- });
- // The hex display should show the pre-populated color
- expect(screen.getByText('Hex: #FF0000', { exact: false })).toBeInTheDocument();
- });
- it('uses translated text for modal elements', async () => {
- render(<ConfigureAmsSlotModal {...defaultProps} />);
- await waitFor(() => {
- expect(screen.getByText('Configure AMS Slot')).toBeInTheDocument();
- expect(screen.getByText('Filament Profile')).toBeInTheDocument();
- });
- // Check footer buttons
- expect(screen.getByRole('button', { name: /Configure Slot/i })).toBeInTheDocument();
- expect(screen.getByRole('button', { name: /Cancel/i })).toBeInTheDocument();
- expect(screen.getByRole('button', { name: /Reset Slot/i })).toBeInTheDocument();
- });
- it('says the K-profiles could not be read when the printer did not answer (#3404)', async () => {
- (api.getKProfiles as ReturnType<typeof vi.fn>).mockRejectedValue(
- new Error('The printer did not answer the K-profile request'),
- );
- const slotInfo = { ...defaultProps.slotInfo, savedPresetId: 'GFSL05_09' };
- // Retrying the way the app's client does: the dialog must not ask again,
- // the backend has already asked the printer three times.
- const retrying = new QueryClient({ defaultOptions: { queries: { retry: 1, retryDelay: 0 } } });
- render(
- <QueryClientProvider client={retrying}>
- <ConfigureAmsSlotModal {...defaultProps} slotInfo={slotInfo} />
- </QueryClientProvider>,
- );
- await waitFor(() => {
- expect(screen.getAllByText(/The printer did not answer, so its K-profiles could not be read/).length).toBeGreaterThan(0);
- });
- expect(screen.queryByText(/No matching K profiles found/)).not.toBeInTheDocument();
- expect(api.getKProfiles).toHaveBeenCalledTimes(1);
- });
- it('opened again after a failed read, it loads instead of saying the printer did not answer (#3404)', async () => {
- // A read without data goes back to pending when it runs again, so the
- // dialog shows its loading state, not the failed read's hint.
- let answer: (v: unknown) => void = () => {};
- (api.getKProfiles as ReturnType<typeof vi.fn>)
- .mockRejectedValueOnce(new Error('The printer did not answer the K-profile request'))
- .mockReturnValueOnce(new Promise((resolve) => { answer = resolve; }));
- const slotInfo = { ...defaultProps.slotInfo, savedPresetId: 'GFSL05_09' };
- const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
- const modal = (open: boolean) => (
- <QueryClientProvider client={client}>
- <ConfigureAmsSlotModal {...defaultProps} isOpen={open} slotInfo={slotInfo} />
- </QueryClientProvider>
- );
- const unread = /The printer did not answer, so its K-profiles could not be read/;
- const { rerender } = render(modal(true));
- await waitFor(() => expect(screen.getAllByText(unread).length).toBeGreaterThan(0));
- rerender(modal(false));
- rerender(modal(true));
- await waitFor(() => expect(api.getKProfiles).toHaveBeenCalledTimes(2));
- expect(screen.queryByText(unread)).not.toBeInTheDocument();
- answer(mockKProfiles);
- await waitFor(() => expect(screen.getByRole('option', { name: /PLA Basic \(K=0.020\)/ })).toBeInTheDocument());
- });
- it('surfaces a K-profile whose name does not match the preset when filament_id agrees (#1688)', async () => {
- // Spool was edited with slicer_filament = "GFSL05_09" (the setting_id form
- // for Bambu PLA Basic). The printer has a *custom* K-profile saved on the
- // same filament_id, but the user named it something that doesn't include
- // "PLA". Pre-fix, the name-only filter dropped it; the id-match path now
- // surfaces it because both sides normalise to "GFL05".
- (api.getKProfiles as ReturnType<typeof vi.fn>).mockResolvedValue({
- profiles: [
- {
- slot_id: 3,
- extruder_id: 0,
- nozzle_id: 'HH00-0.4',
- nozzle_diameter: '0.4',
- filament_id: 'GFL05',
- name: 'my-custom-tune',
- k_value: '0.025',
- n_coef: '0',
- ams_id: 0,
- tray_id: 0,
- setting_id: '',
- },
- ],
- });
- const slotInfo = {
- ...defaultProps.slotInfo,
- savedPresetId: 'GFSL05_09', // setting_id form for Bambu PLA Basic
- };
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={slotInfo} />);
- await waitFor(() => {
- // Renders as an <option> on the K-profile select even though
- // "my-custom-tune" doesn't contain "PLA" anywhere.
- expect(screen.getByRole('option', { name: /my-custom-tune/ })).toBeInTheDocument();
- });
- });
- it("always includes the slot's currently-active K-profile when name and id don't match (#1689)", async () => {
- // Reporter scenario: spool assigned under "Generic PLA" but the slot has
- // a custom K-profile (filament_id "GFG98" = PETG-something) actively
- // selected via cali_idx. Pre-fix the modal showed "default 0.020"; the
- // safety net now surfaces the active profile so Configure Slot reflects
- // what the printer is actually using.
- (api.getKProfiles as ReturnType<typeof vi.fn>).mockResolvedValue({
- profiles: [
- {
- slot_id: 7, // matches caliIdx below
- extruder_id: 0,
- nozzle_id: 'HH00-0.4',
- nozzle_diameter: '0.4',
- filament_id: 'GFG98', // unrelated to "Generic PLA"
- name: 'unrelated-petg-tune',
- k_value: '0.030',
- n_coef: '0',
- ams_id: 0,
- tray_id: 0,
- setting_id: '',
- },
- ],
- });
- const slotInfo = {
- ...defaultProps.slotInfo,
- savedPresetId: 'GFSL05_09', // Generic PLA preset
- caliIdx: 7,
- extruderId: 0,
- };
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={slotInfo} />);
- await waitFor(() => {
- expect(screen.getByRole('option', { name: /unrelated-petg-tune/ })).toBeInTheDocument();
- });
- });
- it("does not carry the slot's K-profile over to a different filament (#3216)", async () => {
- // X1C slot on Devil Design PLA with its K-profile active, re-configured for
- // Azurefilm PLA Wood. The active profile used to join Azurefilm's list and
- // win the auto-select; the backend then realigned the slot to that
- // profile's filament, so the printer -- and OrcaSlicer -- stayed on Devil
- // Design. Only a slot reset first made it work.
- const DEVIL = '0ed901cd-6700-5772-80b2-25ed659df0d1';
- const AZURE = '2161df52-3d0e-579a-b4b6-dfbc62b93b76';
- (api.orcaCloudListProfiles as ReturnType<typeof vi.fn>).mockResolvedValue({
- filament: [
- { setting_id: DEVIL, name: 'Devil Design PLA @Orca', type: 'filament', is_custom: true },
- { setting_id: AZURE, name: 'Azurefilm PLA Wood @Orca', type: 'filament', is_custom: true },
- ],
- printer: [],
- process: [],
- });
- const kp = (slot_id: number, name: string, filament_id: string, setting_id: string) => ({
- slot_id, extruder_id: 0, nozzle_id: 'HS00-0.4', nozzle_diameter: '0.4', filament_id, name,
- k_value: '0.020', n_coef: '0', ams_id: 0, tray_id: 0, setting_id,
- });
- (api.getKProfiles as ReturnType<typeof vi.fn>).mockResolvedValue({
- profiles: [
- kp(7, 'Devil Design PLA', 'P4d64437', 'PFUSedbf16b803ff3e'),
- kp(9, 'Azurefilm PLA Wood', 'P285e239', 'PFUS220b72bdc39f90'),
- ],
- });
- const slotInfo = {
- ...defaultProps.slotInfo,
- savedPresetId: `orca_${DEVIL}`,
- trayInfoIdx: 'P4d64437',
- caliIdx: 7,
- extruderId: 0,
- };
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={slotInfo} />);
- // Reopening on the slot's own filament still shows its active profile.
- await waitFor(() => {
- expect(screen.getByRole('option', { name: /Devil Design PLA/ })).toBeInTheDocument();
- });
- fireEvent.click(screen.getByText('Azurefilm PLA Wood @Orca'));
- // Azurefilm's own profile is offered and picked; Devil Design's is not.
- await waitFor(() => {
- expect(screen.getByRole('option', { name: /Azurefilm PLA Wood/ })).toBeInTheDocument();
- });
- fireEvent.click(screen.getByRole('button', { name: /Configure Slot/i }));
- await waitFor(() => {
- expect(api.configureAmsSlot).toHaveBeenCalled();
- });
- const payload = (api.configureAmsSlot as ReturnType<typeof vi.fn>).mock.calls[0][3];
- expect(payload.orca_profile_id).toBe(AZURE);
- expect(payload.kprofile_filament_id).toBe('P285e239');
- expect(payload.cali_idx).toBe(9);
- });
- it("surfaces the slot's active K-profile when no preset is resolvable (#1689 follow-up)", async () => {
- // Repro from Spionkiller01: slot is physically loaded but unconfigured —
- // tray_type='', tray_info_idx='', no slot_preset_mappings row — so
- // selectedPresetInfo resolves to null. Before the patch the main matcher's
- // early return on !selectedPresetInfo skipped past the cali_idx safety net
- // entirely; on reopen the dropdown went back to default 0.020 even though
- // the printer still holds the active profile at cali_idx=6.
- (api.getKProfiles as ReturnType<typeof vi.fn>).mockResolvedValue({
- profiles: [
- {
- slot_id: 6,
- extruder_id: 0,
- nozzle_id: 'HH00-0.4',
- nozzle_diameter: '0.4',
- filament_id: 'GFG98',
- name: 'active-on-unconfigured-slot',
- k_value: '0.030',
- n_coef: '0',
- ams_id: 0,
- tray_id: 0,
- setting_id: '',
- },
- ],
- });
- const slotInfo = {
- ...defaultProps.slotInfo,
- trayType: '',
- traySubBrands: '',
- caliIdx: 6,
- extruderId: 0,
- // savedPresetId intentionally omitted — no preset bound yet
- };
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={slotInfo} />);
- await waitFor(() => {
- expect(screen.getByRole('option', { name: /active-on-unconfigured-slot/ })).toBeInTheDocument();
- });
- });
- describe('Generic presets and the K-profile picker (#2710)', () => {
- // Reporter's printer: nine Flow-Dynamics entries, every one of them
- // calibrated against Generic PLA (filament_id GFL99) and named after the
- // spool's colour rather than its material. Bambu Studio lists all nine for
- // a Generic PLA slot; Bambuddy showed only the one already bound to the
- // slot via cali_idx.
- const genericPlaProfiles = [
- 'Black PLA+', 'Dark Brown', 'Glow', 'Gray', 'Lt Brown',
- 'Marble', 'Orange PLA', 'Sunlu White PLA+', 'White PLA+ Duramic',
- ].map((name, i) => ({
- slot_id: i + 1,
- extruder_id: 0,
- nozzle_id: 'HH00-0.4',
- nozzle_diameter: '0.4',
- filament_id: 'GFL99',
- name,
- k_value: `0.0${30 + i}`,
- n_coef: '0',
- ams_id: 0,
- tray_id: 0,
- setting_id: '',
- }));
- const genericPlaSlot = {
- ...defaultProps.slotInfo,
- savedPresetId: 'builtin_GFL99',
- extruderId: 0,
- };
- beforeEach(() => {
- (api.getBuiltinFilaments as ReturnType<typeof vi.fn>).mockResolvedValue([
- { filament_id: 'GFL99', name: 'Generic PLA', filament_type: 'PLA' },
- ]);
- (api.getKProfiles as ReturnType<typeof vi.fn>).mockResolvedValue({
- profiles: genericPlaProfiles,
- });
- });
- it('offers every Generic PLA profile when the slot preset is Generic PLA', async () => {
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={genericPlaSlot} />);
- await waitFor(() => {
- expect(screen.getByRole('option', { name: /Dark Brown/ })).toBeInTheDocument();
- });
- // All nine, not just the one bound via cali_idx — matching the printer's
- // own calibration table for GFL99.
- for (const profile of genericPlaProfiles) {
- expect(
- screen.getByRole('option', { name: `[HF] ${profile.name} (K=${profile.k_value})` }),
- ).toBeInTheDocument();
- }
- });
- it('offers them on a freshly reset slot with no active cali_idx', async () => {
- // "When I reset the AMS slot, the generic PLA shows no k-values at all."
- // With no cali_idx the #1689 safety net has nothing to surface, so the
- // list came back empty; the id match has to stand on its own.
- render(
- <ConfigureAmsSlotModal
- {...defaultProps}
- slotInfo={{ ...genericPlaSlot, caliIdx: 0 }}
- />
- );
- await waitFor(() => {
- expect(screen.getByRole('option', { name: /Marble/ })).toBeInTheDocument();
- });
- expect(screen.getByRole('option', { name: /Glow/ })).toBeInTheDocument();
- });
- it('matches on name when the profile carries no filament_id at all', async () => {
- // Not every firmware fills filament_id in extrusion_cali_get. "Generic"
- // is not a brand, so the name path must fall back to the material
- // instead of demanding "GENERIC" in the profile name.
- (api.getKProfiles as ReturnType<typeof vi.fn>).mockResolvedValue({
- profiles: [
- { ...genericPlaProfiles[0], filament_id: '', name: 'Orange PLA' },
- { ...genericPlaProfiles[1], filament_id: '', name: 'Dark Brown' },
- ],
- });
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={genericPlaSlot} />);
- await waitFor(() => {
- expect(screen.getByRole('option', { name: /Orange PLA/ })).toBeInTheDocument();
- });
- });
- it('does not sweep generic profiles into a brand preset', async () => {
- // Guard against the id path widening: "Bambu PLA Basic" is GFL05, so
- // GFL99 profiles must still be filtered out of the matching group and
- // only reachable through the explicit "other profiles" group.
- render(
- <ConfigureAmsSlotModal
- {...defaultProps}
- slotInfo={{ ...defaultProps.slotInfo, savedPresetId: 'GFSL05_09', extruderId: 0 }}
- />
- );
- await waitFor(() => {
- expect(screen.getByText('Bambu PLA Basic @BBL X1C')).toBeInTheDocument();
- });
- // Every GFL99 profile is demoted to the other group: the brand gate on
- // "Bambu" still applies, and none of these names carry it.
- for (const profile of genericPlaProfiles) {
- const option = screen.getByRole('option', { name: `[HF] ${profile.name} (K=${profile.k_value})` });
- expect(option.closest('optgroup')).toHaveAttribute(
- 'label',
- 'Other K profiles on this printer',
- );
- }
- });
- it("offers the printer's other profiles even when nothing matches the preset", async () => {
- // The escape hatch: a PETG preset matches none of the PLA profiles, but
- // the user can still reach every profile the printer holds instead of
- // being sent to the slicer.
- (api.getBuiltinFilaments as ReturnType<typeof vi.fn>).mockResolvedValue([
- { filament_id: 'GFG99', name: 'Generic PETG', filament_type: 'PETG' },
- ]);
- render(
- <ConfigureAmsSlotModal
- {...defaultProps}
- slotInfo={{ ...genericPlaSlot, savedPresetId: 'builtin_GFG99', caliIdx: 0 }}
- />
- );
- await waitFor(() => {
- expect(screen.getByRole('option', { name: /Dark Brown/ })).toBeInTheDocument();
- });
- expect(screen.getByRole('option', { name: /Dark Brown/ }).closest('optgroup')).toHaveAttribute(
- 'label',
- 'Other K profiles on this printer',
- );
- });
- it('sends the cali_idx of a profile picked from the other-profiles group', async () => {
- (api.getBuiltinFilaments as ReturnType<typeof vi.fn>).mockResolvedValue([
- { filament_id: 'GFG99', name: 'Generic PETG', filament_type: 'PETG' },
- ]);
- render(
- <ConfigureAmsSlotModal
- {...defaultProps}
- slotInfo={{ ...genericPlaSlot, savedPresetId: 'builtin_GFG99', caliIdx: 0 }}
- />
- );
- await waitFor(() => {
- expect(screen.getByRole('option', { name: /Marble/ })).toBeInTheDocument();
- });
- const marble = genericPlaProfiles.find(p => p.name === 'Marble')!;
- // Option identity carries the extruder, so a filament calibrated on both
- // hotends yields two distinguishable entries rather than one.
- fireEvent.change(screen.getByRole('combobox'), {
- target: { value: `${marble.extruder_id}|${marble.name}|${marble.k_value}` },
- });
- fireEvent.click(screen.getByRole('button', { name: /Configure Slot/i }));
- await waitFor(() => {
- expect(api.configureAmsSlot).toHaveBeenCalled();
- });
- const payload = (api.configureAmsSlot as ReturnType<typeof vi.fn>).mock.calls[0][3];
- expect(payload.cali_idx).toBe(marble.slot_id);
- expect(payload.kprofile_filament_id).toBe('GFL99');
- });
- it('distinguishes two profiles that share a name but differ in K', async () => {
- // The picker used to key options by name alone, so same-named profiles
- // were indistinguishable and the first always won. The key now also
- // carries the extruder, for the same reason one step further out: the
- // printer numbers its calibration table per hotend.
- (api.getKProfiles as ReturnType<typeof vi.fn>).mockResolvedValue({
- profiles: [
- { ...genericPlaProfiles[0], slot_id: 1, name: 'PLA', k_value: '0.020' },
- { ...genericPlaProfiles[1], slot_id: 2, name: 'PLA', k_value: '0.045' },
- ],
- });
- render(
- <ConfigureAmsSlotModal
- {...defaultProps}
- slotInfo={{ ...genericPlaSlot, caliIdx: 0 }}
- />
- );
- await waitFor(() => {
- expect(screen.getByRole('option', { name: /K=0.045/ })).toBeInTheDocument();
- });
- fireEvent.change(screen.getByRole('combobox'), { target: { value: '0|PLA|0.045' } });
- fireEvent.click(screen.getByRole('button', { name: /Configure Slot/i }));
- await waitFor(() => {
- expect(api.configureAmsSlot).toHaveBeenCalled();
- });
- expect((api.configureAmsSlot as ReturnType<typeof vi.fn>).mock.calls[0][3].cali_idx).toBe(2);
- });
- });
- describe('A slot whose extruder claims no profile (#3044)', () => {
- // Reporter's X2D: two AMS 2 Pro, one per hotend, the same filaments in
- // both. The printer files one profile per filament rather than one per
- // hotend, so the second AMS's slots point at entries tagged extruder 0.
- // Scoping the picker to the slot's own extruder left it with nothing:
- // the slot read as unconfigured and choosing a profile changed nothing
- // the user could see.
- const sharedProfiles = [
- { name: 'PLA', k_value: '0.021', slot_id: 1 },
- { name: 'PETG', k_value: '0.026', slot_id: 4 },
- ].map(p => ({
- ...p,
- extruder_id: 0,
- nozzle_id: 'HH00-0.4',
- nozzle_diameter: '0.4',
- filament_id: 'GFL99',
- n_coef: '0',
- ams_id: 0,
- tray_id: 0,
- setting_id: '',
- }));
- // AMS-B, right-hand hotend, already bound to the PLA profile the A-side
- // slots use.
- const rightHandSlot = {
- ...defaultProps.slotInfo,
- amsId: 1,
- savedPresetId: 'builtin_GFL99',
- extruderId: 1,
- caliIdx: 1,
- };
- beforeEach(() => {
- (api.getBuiltinFilaments as ReturnType<typeof vi.fn>).mockResolvedValue([
- { filament_id: 'GFL99', name: 'Generic PLA', filament_type: 'PLA' },
- ]);
- (api.getKProfiles as ReturnType<typeof vi.fn>).mockResolvedValue({ profiles: sharedProfiles });
- });
- it('offers the profiles as matches rather than an empty picker', async () => {
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={rightHandSlot} />);
- await waitFor(() => {
- expect(screen.getByRole('option', { name: /PLA \(K=0.021\)/ })).toBeInTheDocument();
- });
- // Matches are the select's direct children; anything demoted to the
- // "Other K profiles" group sits inside an optgroup instead. Being merely
- // present is what the slot already had, and it read as unconfigured.
- const matches = Array.from(screen.getByRole('combobox').querySelectorAll(':scope > option'))
- .map(o => (o as HTMLOptionElement).value)
- .filter(Boolean);
- expect(matches).toEqual(['0|PLA|0.021', '0|PETG|0.026']);
- });
- it('shows the slot as already bound to its active profile', async () => {
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={rightHandSlot} />);
- await waitFor(() => {
- expect(screen.getByRole('option', { name: /PLA \(K=0.021\)/ })).toBeInTheDocument();
- });
- // Not the "no K profile" placeholder, which is what the slot showed while
- // the active profile could not be found on this extruder.
- expect((screen.getByRole('combobox') as HTMLSelectElement).value).toBe('0|PLA|0.021');
- });
- it('still scopes to the slot own hotend when that hotend has its own profiles', async () => {
- // The H2C case behind the scoping: one filament calibrated on both
- // hotends, two profiles, one right answer per slot. The fallback is a
- // last resort and must not reopen this.
- (api.getKProfiles as ReturnType<typeof vi.fn>).mockResolvedValue({
- profiles: [
- { ...sharedProfiles[0], extruder_id: 0, k_value: '0.020', slot_id: 1 },
- { ...sharedProfiles[0], extruder_id: 1, k_value: '0.018', slot_id: 2 },
- ],
- });
- render(
- <ConfigureAmsSlotModal
- {...defaultProps}
- slotInfo={{ ...rightHandSlot, caliIdx: 2 }}
- />
- );
- await waitFor(() => {
- expect(screen.getByRole('option', { name: /K=0.018/ })).toBeInTheDocument();
- });
- expect((screen.getByRole('combobox') as HTMLSelectElement).value).toBe('1|PLA|0.018');
- // The left hotend's copy is still reachable, but under "Other".
- const other = screen.getByRole('option', { name: /K=0.020/ });
- expect(other.parentElement?.tagName).toBe('OPTGROUP');
- });
- it('offers the profiles of the fitted nozzle flow, the others under Other with their flow', async () => {
- // H2D with a standard nozzle fitted: the high-flow copy of the same
- // filament is not applied at assign time, so it must not be the match
- // the picker selects (FD-16).
- (api.getPrinterStatus as ReturnType<typeof vi.fn>).mockResolvedValue({
- nozzles: [{ nozzle_type: 'HS01', nozzle_diameter: '0.4' }],
- });
- (api.getKProfiles as ReturnType<typeof vi.fn>).mockResolvedValue({
- profiles: [
- { ...sharedProfiles[0], extruder_id: 0, nozzle_id: 'HH00-0.4', k_value: '0.030', slot_id: 1 },
- { ...sharedProfiles[0], extruder_id: 0, nozzle_id: 'HS00-0.4', k_value: '0.020', slot_id: 2 },
- ],
- });
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={{ ...rightHandSlot, extruderId: 0, caliIdx: null }} />);
- await waitFor(() => {
- expect(screen.getByRole('option', { name: /\[S\] PLA \(K=0.020\)/ })).toBeInTheDocument();
- });
- const matches = Array.from(screen.getByRole('combobox').querySelectorAll(':scope > option'))
- .map(o => (o as HTMLOptionElement).value)
- .filter(Boolean);
- expect(matches).toEqual(['0|PLA|0.020']);
- const highFlow = screen.getByRole('option', { name: /\[HF\] PLA \(K=0.030\)/ });
- expect(highFlow.parentElement?.tagName).toBe('OPTGROUP');
- });
- it('names each hotend once, not two or three times', async () => {
- // The label rendered kProfileNozzleSuffix twice in the matching group and
- // three times under "Other", so every option on a dual-nozzle printer
- // read "... . Left . Left".
- (api.getKProfiles as ReturnType<typeof vi.fn>).mockResolvedValue({
- profiles: [
- { ...sharedProfiles[0], extruder_id: 0, k_value: '0.020', slot_id: 1 },
- { ...sharedProfiles[0], extruder_id: 1, k_value: '0.018', slot_id: 2 },
- ],
- });
- render(
- <ConfigureAmsSlotModal
- {...defaultProps}
- slotInfo={{ ...rightHandSlot, caliIdx: 2 }}
- />
- );
- await waitFor(() => {
- expect(screen.getByRole('option', { name: /K=0.018/ })).toBeInTheDocument();
- });
- for (const option of screen.getAllByRole('option')) {
- // The suffix is the only thing that puts a middot in an option label,
- // so counting separators counts how many times the hotend was named.
- const separators = (option.textContent ?? '').match(/\u00b7/g) ?? [];
- expect(separators.length).toBeLessThanOrEqual(1);
- }
- });
- });
- it('does not include the active K-profile when caliIdx is 0 or null (#1689 guard)', async () => {
- // cali_idx == 0 / null means no profile is active (printer default 0.020).
- // The safety net only triggers for activeIdx > 0 — otherwise unrelated
- // profiles whose slot_id happens to equal 0 would leak in.
- (api.getKProfiles as ReturnType<typeof vi.fn>).mockResolvedValue({
- profiles: [
- {
- slot_id: 0,
- extruder_id: 0,
- nozzle_id: 'HH00-0.4',
- nozzle_diameter: '0.4',
- filament_id: 'GFG98',
- name: 'should-not-appear',
- k_value: '0.030',
- n_coef: '0',
- ams_id: 0,
- tray_id: 0,
- setting_id: '',
- },
- ],
- });
- const slotInfo = {
- ...defaultProps.slotInfo,
- savedPresetId: 'GFSL05_09',
- caliIdx: 0,
- extruderId: 0,
- };
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={slotInfo} />);
- await waitFor(() => {
- expect(screen.getByText(/Configure AMS/)).toBeInTheDocument();
- });
- expect(screen.queryByRole('option', { name: /should-not-appear/ })).not.toBeInTheDocument();
- });
- });
- describe('ConfigureAmsSlotModal — per-nozzle K-profiles', () => {
- /**
- * K-profiles are per-nozzle and the printer numbers its calibration table per
- * nozzle too, so one filament calibrated on both hotends gives two profiles
- * with the same name and the same index space. Measured on the maintainer's
- * H2C: "HF Bambu PLA Matte Black" is K=0.018 at index 16 on the left hotend
- * and K=0.020 at index 15 on the right.
- *
- * A tray holds exactly one cali_idx, so the picker has to resolve it against
- * the slot's own nozzle. It used to match on the index alone and, failing
- * that, take the first profile in the list — which on a Filament Track Switch
- * machine (where no AMS reports an extruder at all) was arbitrary.
- */
- const matteBlack = (extruder: number, caliIdx: number, k: string) => ({
- slot_id: caliIdx,
- extruder_id: extruder,
- nozzle_id: 'HH00-0.4',
- nozzle_diameter: '0.4',
- filament_id: 'GFL99',
- name: 'HF Bambu PLA Matte Black',
- k_value: k,
- n_coef: '0',
- ams_id: 0,
- tray_id: 0,
- setting_id: '',
- });
- const bothNozzles = [matteBlack(1, 16, '0.018'), matteBlack(0, 15, '0.020')];
- beforeEach(() => {
- vi.clearAllMocks();
- (api.getPrinterStatus as ReturnType<typeof vi.fn>).mockResolvedValue({});
- Element.prototype.scrollIntoView = vi.fn();
- (api.getCloudSettings as ReturnType<typeof vi.fn>).mockResolvedValue(mockCloudSettings);
- (api.getBuiltinFilaments as ReturnType<typeof vi.fn>).mockResolvedValue([
- { filament_id: 'GFL99', name: 'Generic PLA', filament_type: 'PLA' },
- ]);
- (api.getKProfiles as ReturnType<typeof vi.fn>).mockResolvedValue({ profiles: bothNozzles });
- (api.configureAmsSlot as ReturnType<typeof vi.fn>).mockResolvedValue({ success: true });
- });
- const slot = (extruderId: number | undefined, caliIdx: number) => ({
- ...defaultProps.slotInfo,
- savedPresetId: 'builtin_GFL99',
- extruderId,
- caliIdx,
- });
- it('preselects the right hotend profile for a slot on the right hotend', async () => {
- // The reported bug, from the other side: the slot is bound to cali_idx 16,
- // which is the LEFT hotend's entry. On a right-hotend slot the picker must
- // land on 15, not follow the index into the wrong table.
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={slot(0, 16)} />);
- await waitFor(() => {
- expect(screen.getByRole('combobox')).toBeInTheDocument();
- });
- expect((screen.getByRole('combobox') as HTMLSelectElement).value).toBe('0|HF Bambu PLA Matte Black|0.020');
- });
- it('preselects the left hotend profile for a slot on the left hotend', async () => {
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={slot(1, 16)} />);
- await waitFor(() => {
- expect(screen.getByRole('combobox')).toBeInTheDocument();
- });
- expect((screen.getByRole('combobox') as HTMLSelectElement).value).toBe('1|HF Bambu PLA Matte Black|0.018');
- });
- it('does not offer the other hotend profile as a match', async () => {
- // Both are still reachable — the other lands in the "Other K profiles"
- // group — but only one is a match for this slot.
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={slot(0, 15)} />);
- await waitFor(() => {
- expect(screen.getByRole('option', { name: /K=0.020/ })).toBeInTheDocument();
- });
- const matchGroup = screen.getByRole('combobox').querySelectorAll(':scope > option');
- const matchValues = Array.from(matchGroup).map(o => (o as HTMLOptionElement).value).filter(Boolean);
- expect(matchValues).toEqual(['0|HF Bambu PLA Matte Black|0.020']);
- });
- it('names the hotend on each option when the printer has two', async () => {
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={slot(0, 15)} />);
- await waitFor(() => {
- expect(screen.getByRole('option', { name: /K=0.020/ })).toBeInTheDocument();
- });
- expect(screen.getByRole('option', { name: /K=0\.020.*Right/ })).toBeInTheDocument();
- expect(screen.getByRole('option', { name: /K=0\.018.*Left/ })).toBeInTheDocument();
- });
- it('leaves single-nozzle printers unlabelled', async () => {
- (api.getKProfiles as ReturnType<typeof vi.fn>).mockResolvedValue({
- profiles: [matteBlack(0, 15, '0.020')],
- });
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={slot(0, 15)} />);
- await waitFor(() => {
- expect(screen.getByRole('option', { name: /K=0.020/ })).toBeInTheDocument();
- });
- expect(screen.queryByRole('option', { name: /Right/ })).not.toBeInTheDocument();
- });
- it('sends the cali_idx of the nozzle-correct profile', async () => {
- render(<ConfigureAmsSlotModal {...defaultProps} slotInfo={slot(0, 16)} />);
- // Wait for the preselect to settle, not merely for the control to mount —
- // the submit reads the selected profile, which lands an effect later.
- await waitFor(() => {
- expect((screen.getByRole('combobox') as HTMLSelectElement).value).toBe(
- '0|HF Bambu PLA Matte Black|0.020'
- );
- });
- fireEvent.click(screen.getByRole('button', { name: /Configure Slot/i }));
- await waitFor(() => {
- expect(api.configureAmsSlot).toHaveBeenCalled();
- });
- expect((api.configureAmsSlot as ReturnType<typeof vi.fn>).mock.calls[0][3].cali_idx).toBe(15);
- });
- });
|