waitingReason.test.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * The frontend half of the `waiting_reason` shape contract (#3074).
  3. *
  4. * The scheduler encodes "starts by itself" as a reason made only of `Busy: ...`
  5. * clauses, joined with ` | `, and decides notifications on that basis. The UI
  6. * reads the same bit to decide what still belongs on a forecast. These cases
  7. * are the exact strings both branches of the scheduler emit, so a reword on
  8. * either side lands here first.
  9. */
  10. import { describe, it, expect } from 'vitest';
  11. import { isBusyOnlyWaitingReason } from '../../utils/waitingReason';
  12. describe('isBusyOnlyWaitingReason', () => {
  13. it('treats nothing as not-busy rather than busy', () => {
  14. // An item with no reason is dispatchable, not "waiting its turn"; callers
  15. // check the reason's presence separately.
  16. expect(isBusyOnlyWaitingReason(null)).toBe(false);
  17. expect(isBusyOnlyWaitingReason(undefined)).toBe(false);
  18. expect(isBusyOnlyWaitingReason('')).toBe(false);
  19. });
  20. it.each([
  21. 'Busy: X1C-01',
  22. 'Busy: X1C-01 (drying)',
  23. 'Busy: X1C-01, X1C-02',
  24. 'Busy: X1C-01 | Busy: X1C-02',
  25. ])('reads %s as waiting its turn', reason => {
  26. expect(isBusyOnlyWaitingReason(reason)).toBe(true);
  27. });
  28. it.each([
  29. 'Waiting for plate confirmation: X1C-01',
  30. 'Offline, no Auto On smart plug: X1C-01',
  31. 'Offline: X1C-01 — the smart plug could not power it on',
  32. 'Waiting on Enclosure Door',
  33. 'Waiting for filament: X1C-01 (needs PETG)',
  34. 'No available X1C printers',
  35. 'Every file for this job has been deleted — add a file back or remove the item',
  36. ])('reads %s as waiting for the user', reason => {
  37. expect(isBusyOnlyWaitingReason(reason)).toBe(false);
  38. });
  39. it('needs every clause to be busy, not just the first', () => {
  40. // The scheduler only joins with " | " when every clause is busy, but the
  41. // reader must not assume that -- one clause needing the user makes the
  42. // whole reason need the user.
  43. expect(isBusyOnlyWaitingReason('Busy: X1C-01 | Offline: X1C-02')).toBe(false);
  44. });
  45. });