|
1 | 1 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
2 | 2 | import { |
3 | 3 | describeTrigger, |
| 4 | + loopFireBlockedMessage, |
| 5 | + loopPausedDescription, |
| 6 | + loopStatusColor, |
| 7 | + loopStatusLabel, |
4 | 8 | nextScheduleRun, |
5 | 9 | summarizeNotificationDestinations, |
6 | 10 | summarizeTrigger, |
7 | 11 | } from "./loopDisplay"; |
8 | 12 |
|
| 13 | +const statusFields = ( |
| 14 | + overrides: Partial<{ |
| 15 | + enabled: boolean; |
| 16 | + disabled_reason: string | null; |
| 17 | + last_run_status: string | null; |
| 18 | + }> = {}, |
| 19 | +) => ({ |
| 20 | + enabled: true, |
| 21 | + disabled_reason: null, |
| 22 | + last_run_status: null, |
| 23 | + ...overrides, |
| 24 | +}); |
| 25 | + |
| 26 | +describe("loopStatusLabel and loopStatusColor", () => { |
| 27 | + it.each([ |
| 28 | + [statusFields(), "Active", "green"], |
| 29 | + [statusFields({ last_run_status: "failed" }), "Failing", "red"], |
| 30 | + [statusFields({ enabled: false }), "Paused", "gray"], |
| 31 | + [ |
| 32 | + statusFields({ enabled: false, disabled_reason: "usage_limited" }), |
| 33 | + "Paused: usage limit", |
| 34 | + "red", |
| 35 | + ], |
| 36 | + [ |
| 37 | + statusFields({ enabled: false, disabled_reason: "repeated_failures" }), |
| 38 | + "Auto-paused", |
| 39 | + "red", |
| 40 | + ], |
| 41 | + [ |
| 42 | + statusFields({ enabled: false, disabled_reason: "owner_deactivated" }), |
| 43 | + "Auto-paused", |
| 44 | + "red", |
| 45 | + ], |
| 46 | + ])("derives label and color (%#)", (loop, label, color) => { |
| 47 | + expect(loopStatusLabel(loop)).toBe(label); |
| 48 | + expect(loopStatusColor(loop)).toBe(color); |
| 49 | + }); |
| 50 | + |
| 51 | + it("ignores disabled_reason while the loop is enabled", () => { |
| 52 | + const loop = statusFields({ disabled_reason: "usage_limited" }); |
| 53 | + expect(loopStatusLabel(loop)).toBe("Active"); |
| 54 | + expect(loopStatusColor(loop)).toBe("green"); |
| 55 | + }); |
| 56 | +}); |
| 57 | + |
| 58 | +describe("loopPausedDescription", () => { |
| 59 | + it.each([ |
| 60 | + ["usage_limited", "usage limit"], |
| 61 | + ["repeated_failures", "failed runs in a row"], |
| 62 | + ["owner_deactivated", "deactivated"], |
| 63 | + ["owner_removed_from_org", "left the organization"], |
| 64 | + ["github_integration_disconnected", "GitHub connection"], |
| 65 | + ])("explains a %s pause", (reason, expected) => { |
| 66 | + expect( |
| 67 | + loopPausedDescription( |
| 68 | + statusFields({ enabled: false, disabled_reason: reason }), |
| 69 | + ), |
| 70 | + ).toContain(expected); |
| 71 | + }); |
| 72 | + |
| 73 | + it("falls back to a generic sentence for unknown reasons", () => { |
| 74 | + expect( |
| 75 | + loopPausedDescription( |
| 76 | + statusFields({ enabled: false, disabled_reason: "something_new" }), |
| 77 | + ), |
| 78 | + ).toBe("Paused automatically."); |
| 79 | + }); |
| 80 | + |
| 81 | + it.each([ |
| 82 | + [statusFields()], |
| 83 | + [statusFields({ enabled: false })], |
| 84 | + [statusFields({ disabled_reason: "usage_limited" })], |
| 85 | + ])("returns null without a backend-driven pause (%#)", (loop) => { |
| 86 | + expect(loopPausedDescription(loop)).toBeNull(); |
| 87 | + }); |
| 88 | +}); |
| 89 | + |
| 90 | +describe("loopFireBlockedMessage", () => { |
| 91 | + it.each([ |
| 92 | + ["gate_blocked", "usage limit"], |
| 93 | + ["overlap_skipped", "still in progress"], |
| 94 | + ["rate_capped", "daily run cap"], |
| 95 | + ["team_rate_capped", "daily loop run cap"], |
| 96 | + ["deduped", "already started"], |
| 97 | + ["disabled", "disabled"], |
| 98 | + ["owner_inactive", "no longer start runs"], |
| 99 | + ["owner_changed", "owner changed"], |
| 100 | + ] as const)("describes %s", (reason, expected) => { |
| 101 | + expect(loopFireBlockedMessage(reason)).toContain(expected); |
| 102 | + }); |
| 103 | +}); |
| 104 | + |
9 | 105 | describe("describeTrigger", () => { |
10 | 106 | beforeEach(() => vi.useFakeTimers()); |
11 | 107 | afterEach(() => vi.useRealTimers()); |
|
0 commit comments