slotPresetDescribesTray.test.ts 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * A stored slot preset must not outlive the spool it describes.
  3. *
  4. * `slot_preset_mappings` remembers what a slot was last configured with, and
  5. * the AMS slot card puts that name ahead of the filament id the printer is
  6. * reporting -- which is how a hand-picked name survives on the card. It also
  7. * meant that pulling a Bambu ABS Orange and inserting a PLA Matte Dark Blue
  8. * left "Bambu ABS" on the card against the new colour, because the row is
  9. * fetched over REST while everything else arrives on the socket.
  10. *
  11. * The check is deliberately narrow. Official Bambu presets differ between the
  12. * two id forms by one letter and can be compared; a user preset carries two
  13. * genuinely unrelated ids and a local preset has no printer-side id at all, so
  14. * neither can be judged here and both keep their name.
  15. */
  16. import { describe, it, expect } from 'vitest';
  17. import { slotPresetDescribesTray } from '../../utils/amsHelpers';
  18. describe('slotPresetDescribesTray', () => {
  19. describe('official Bambu presets, where the ids can be compared', () => {
  20. it('accepts the setting_id / filament_id pair for one filament', () => {
  21. expect(slotPresetDescribesTray('GFSA01', 'GFA01')).toBe(true);
  22. });
  23. it('rejects the row left behind by the previous spool', () => {
  24. // The reported swap: ABS Basic out, PLA Matte in.
  25. expect(slotPresetDescribesTray('GFSB00', 'GFA01')).toBe(false);
  26. });
  27. it('rejects a different filament in the same family', () => {
  28. // PLA Matte row, PLA Basic roll -- same GFA prefix, still not the same
  29. // filament, and the card would name the wrong one.
  30. expect(slotPresetDescribesTray('GFSA01', 'GFA00')).toBe(false);
  31. });
  32. it('ignores the version suffix on either side', () => {
  33. expect(slotPresetDescribesTray('GFSA01_07', 'GFA01')).toBe(true);
  34. expect(slotPresetDescribesTray('GFSA01', 'GFA01_07')).toBe(true);
  35. });
  36. it('is case-insensitive, since the printer is not consistent about it', () => {
  37. expect(slotPresetDescribesTray('gfsa01', 'GFA01')).toBe(true);
  38. });
  39. });
  40. describe('rows that cannot be judged keep their name', () => {
  41. it('a user preset, whose two ids are unrelated', () => {
  42. // Verbatim from a live slot: ams_filament_setting sent
  43. // setting_id=PFUSa3b8b0c664c142 and the tray reports tray_info_idx=P8a85d5a.
  44. // Comparing those would blank a correctly configured slot.
  45. expect(slotPresetDescribesTray('PFUSa3b8b0c664c142', 'P8a85d5a')).toBe(true);
  46. });
  47. it('a local preset, which has no printer-side id', () => {
  48. expect(slotPresetDescribesTray('local_68', 'GFA00')).toBe(true);
  49. });
  50. it('a slot reporting no filament id at all', () => {
  51. // Generic filament with no tag -- the case the stored row exists for.
  52. expect(slotPresetDescribesTray('GFSA01', '')).toBe(true);
  53. expect(slotPresetDescribesTray('GFSA01', null)).toBe(true);
  54. });
  55. it('no stored row', () => {
  56. expect(slotPresetDescribesTray(null, 'GFA01')).toBe(true);
  57. expect(slotPresetDescribesTray(undefined, undefined)).toBe(true);
  58. });
  59. });
  60. describe('with the filament id recorded alongside the row (#3216)', () => {
  61. it('keeps an Orca preset while the slot still holds its id', () => {
  62. expect(slotPresetDescribesTray('orca_34d8f588-860b-5be1-bcbe-c0d46d96324b', 'Pfc74047', 'Pfc74047')).toBe(true);
  63. });
  64. it('drops it once the slicer\'s Device tab re-configured the slot', () => {
  65. // The reporter's case: Bambuddy's row said Generic PVA while the slot
  66. // held the Orca filament OrcaSlicer had just written.
  67. expect(slotPresetDescribesTray('GFSS99', 'Pfc74047', 'GFS99')).toBe(false);
  68. expect(slotPresetDescribesTray('local_68', 'GFA00', 'P56e1be0')).toBe(false);
  69. });
  70. it('compares case-insensitively and without a version suffix', () => {
  71. expect(slotPresetDescribesTray('PFUSa3b8b0c664c142', 'P8A85D5A', 'p8a85d5a')).toBe(true);
  72. });
  73. it('cannot judge a slot reporting no id, so keeps the row', () => {
  74. expect(slotPresetDescribesTray('local_68', '', 'P56e1be0')).toBe(true);
  75. });
  76. });
  77. });