ams3h.test.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * The H3C's AMS 3H (unit 32, AMS type 6, global trays 28-36) and its
  3. * per-hotend external inputs 247-255 ("Ext-n") in the amsHelpers labels and
  4. * card layout.
  5. */
  6. import { describe, expect, it } from 'vitest';
  7. import {
  8. ams3hDryerGridColumns,
  9. ams3hSlotGridPlacement,
  10. amsHasLoadedTray,
  11. amsUnitSlotCount,
  12. formatAssignmentSlotLabel,
  13. formatSlotLabel,
  14. getAmsLabel,
  15. getGlobalTrayId,
  16. isAms3hUnit,
  17. preferLowestSortKey,
  18. rackExternalLabel,
  19. spoolBuddyAmsName,
  20. } from '../../utils/amsHelpers';
  21. const ams3h = { id: 32, ams_type: 6 };
  22. describe('the AMS 3H unit', () => {
  23. it('is told by its AMS type, or by its unit id 32 when the type is not at hand', () => {
  24. expect(isAms3hUnit(ams3h)).toBe(true);
  25. expect(isAms3hUnit({ id: 32 })).toBe(true);
  26. expect(isAms3hUnit({ id: 0, ams_type: 1 })).toBe(false);
  27. expect(isAms3hUnit({ id: 128 })).toBe(false);
  28. expect(isAms3hUnit(undefined)).toBe(false);
  29. });
  30. it('draws nine slots, a regular AMS four and an AMS-HT one', () => {
  31. expect(amsUnitSlotCount(ams3h)).toBe(9);
  32. expect(amsUnitSlotCount({ id: 1 })).toBe(4);
  33. expect(amsUnitSlotCount({ id: 129 })).toBe(1);
  34. });
  35. it('numbers its slots 28-36, clear of the AMS-HT range', () => {
  36. expect([0, 1, 2, 3, 4, 5, 6, 7, 8].map((slot) => getGlobalTrayId(32, slot, false, 6))).toEqual([28, 29, 30, 31, 32, 33, 34, 35, 36]);
  37. expect(getGlobalTrayId(32, 6, false)).toBe(34);
  38. // Every other kind keeps its numbers.
  39. expect(getGlobalTrayId(1, 2, false)).toBe(6);
  40. expect(getGlobalTrayId(129, 0, false)).toBe(129);
  41. expect(getGlobalTrayId(255, 0, true)).toBe(254);
  42. expect(getGlobalTrayId(255, 1, true)).toBe(255);
  43. });
  44. it('sees its slot on the toolhead', () => {
  45. const unit = { ...ams3h, tray: [{ id: 6 }, { id: 7 }] };
  46. expect(amsHasLoadedTray(unit, 34, undefined)).toBe(true);
  47. expect(amsHasLoadedTray(unit, 6, undefined)).toBe(false);
  48. });
  49. it('is labelled AMS 3H and its slots 3H-1..3H-9', () => {
  50. expect(getAmsLabel(32)).toBe('AMS 3H');
  51. expect(formatSlotLabel(32, 6, false, false)).toBe('3H-7');
  52. expect(formatSlotLabel(1, 2, false, false)).toBe('B3');
  53. expect(spoolBuddyAmsName(32)).toBe('AMS 3H');
  54. });
  55. it('follows the reported AMS type over the unit id', () => {
  56. expect(getAmsLabel(32, 7)).not.toBe('AMS 3H');
  57. expect(formatSlotLabel(32, 6, false, false, 7)).not.toBe('3H-7');
  58. expect(getAmsLabel(40, 6)).toBe('AMS 3H');
  59. expect(formatSlotLabel(40, 0, false, false, 6)).toBe('3H-1');
  60. expect(spoolBuddyAmsName(40, 6)).toBe('AMS 3H');
  61. });
  62. it('leaves the SpoolBuddy names of every other unit as they were', () => {
  63. expect(spoolBuddyAmsName(0)).toBe('AMS A');
  64. expect(spoolBuddyAmsName(3)).toBe('AMS D');
  65. expect(spoolBuddyAmsName(129)).toBe('AMS HT B');
  66. expect(spoolBuddyAmsName(6)).toBe('AMS 6');
  67. });
  68. it('sorts its slots by position for the prefer-lowest tie-break', () => {
  69. const key = (trayId: number) => preferLowestSortKey({ globalTrayId: 28 + trayId, amsId: 32, trayId }, undefined)[2];
  70. expect(key(0)).toBeLessThan(key(8));
  71. expect(key(8)).toBeLessThan(preferLowestSortKey({ globalTrayId: 128, amsId: 128, trayId: 0 }, undefined)[2]);
  72. });
  73. });
  74. describe('slot labels outside the printer card', () => {
  75. it('labels inventory assignments on an H3C by slot and by hotend input', () => {
  76. expect(formatAssignmentSlotLabel({ ams_id: 32, tray_id: 6, printer_model: 'H3C' })).toBe('3H-7');
  77. expect(formatAssignmentSlotLabel({ ams_id: 32, tray_id: 8 })).toBe('3H-9');
  78. expect(formatAssignmentSlotLabel({ ams_id: 1, tray_id: 2, printer_model: 'X1C' })).toBe('B3');
  79. // External inputs: (255, 1) = 255 feeds hotend 0 -> Ext-1, (255, 5) = 250 -> Ext-6.
  80. expect(formatAssignmentSlotLabel({ ams_id: 255, tray_id: 1, printer_model: 'H3C' })).toBe('Ext-1');
  81. expect(formatAssignmentSlotLabel({ ams_id: 255, tray_id: 5, printer_model: 'H3C' })).toBe('Ext-6');
  82. expect(formatAssignmentSlotLabel({ ams_id: 255, tray_id: 0, printer_model: 'X1C' })).toBe('Ext');
  83. expect(formatAssignmentSlotLabel({ ams_id: 255, tray_id: 1 })).toBe('Ext');
  84. expect(formatAssignmentSlotLabel({ ams_id: 255, tray_id: 8, printer_model: 'N10' })).toBe('Ext-3');
  85. expect(formatAssignmentSlotLabel({ ams_id: 129, tray_id: 0, printer_model: 'H3C' })).toBe('HT-B');
  86. });
  87. it('numbers a per-hotend input like Bambu Studio: Ext-n feeds PrintTool n', () => {
  88. expect(rackExternalLabel(255)).toBe('Ext-1');
  89. expect(rackExternalLabel(247)).toBe('Ext-9');
  90. });
  91. });
  92. describe('AMS 3H card layout', () => {
  93. it('puts 2, 4, 6, 8 in the back row and 1-9 odd in front, staggered, as on the unit', () => {
  94. const rows = [1, 2, 3, 4, 5, 6, 7, 8, 9].map((n) => [n, ams3hSlotGridPlacement(n)]);
  95. expect(rows.filter(([, p]) => (p as { gridRow: number }).gridRow === 1).map(([n]) => n)).toEqual([2, 4, 6, 8]);
  96. expect(rows.filter(([, p]) => (p as { gridRow: number }).gridRow === 2).map(([n]) => n)).toEqual([1, 3, 5, 7, 9]);
  97. // Each back slot starts half a slot after the front slot before it.
  98. expect(ams3hSlotGridPlacement(1).gridColumn).toBe('1 / span 2');
  99. expect(ams3hSlotGridPlacement(2).gridColumn).toBe('2 / span 2');
  100. expect(ams3hSlotGridPlacement(9).gridColumn).toBe('9 / span 2');
  101. });
  102. it('boxes the dryer around slots 6 and 8 with its readings in the free column after slot 8', () => {
  103. // As captured: zone_slots [5, 7] (tray ids 0-8) = slots 6 and 8.
  104. expect(ams3hDryerGridColumns([5, 7])).toEqual({ start: 6, end: 11, info: 10 });
  105. });
  106. it('draws no readings column when the dryer does not end at slot 8', () => {
  107. expect(ams3hDryerGridColumns([1, 3])).toEqual({ start: 2, end: 6, info: null });
  108. });
  109. it('draws no dryer for no slots or front-row slots', () => {
  110. expect(ams3hDryerGridColumns(undefined)).toBeNull();
  111. expect(ams3hDryerGridColumns([])).toBeNull();
  112. expect(ams3hDryerGridColumns([4, 6])).toBeNull(); // slots 5 and 7 are in front
  113. });
  114. });