|
| 1 | +import { describe, it, expect, beforeEach } from "vitest"; |
| 2 | +import QueuePresenter from "../../src/presenters/QueuePresenter.js"; |
| 3 | + |
| 4 | +describe("QueuePresenter.formatQueueStatusMessage", () => { |
| 5 | + let qp: QueuePresenter; |
| 6 | + |
| 7 | + beforeEach(() => { |
| 8 | + qp = new QueuePresenter(); |
| 9 | + }); |
| 10 | + |
| 11 | + it("returns default message when no params provided", () => { |
| 12 | + const result = qp.formatQueueStatusMessage({}); |
| 13 | + expect(result).toBe("Queue status"); |
| 14 | + }); |
| 15 | + |
| 16 | + it("formats processing status", () => { |
| 17 | + const result = qp.formatQueueStatusMessage({ processing: true }); |
| 18 | + expect(result).toBe("🔄 Processing"); |
| 19 | + }); |
| 20 | + |
| 21 | + it("formats position only", () => { |
| 22 | + const result = qp.formatQueueStatusMessage({ position: 5 }); |
| 23 | + expect(result).toBe("Position 5"); |
| 24 | + }); |
| 25 | + |
| 26 | + it("formats position with total", () => { |
| 27 | + const result = qp.formatQueueStatusMessage({ position: 3, total: 10 }); |
| 28 | + expect(result).toBe("Position 3/10"); |
| 29 | + }); |
| 30 | + |
| 31 | + it("formats URL", () => { |
| 32 | + const result = qp.formatQueueStatusMessage({ url: "https://example.com" }); |
| 33 | + expect(result).toBe("URL: <https://example.com>"); |
| 34 | + }); |
| 35 | + |
| 36 | + it("formats note", () => { |
| 37 | + const result = qp.formatQueueStatusMessage({ note: "Custom note here" }); |
| 38 | + expect(result).toBe("Custom note here"); |
| 39 | + }); |
| 40 | + |
| 41 | + it("formats processing with position", () => { |
| 42 | + const result = qp.formatQueueStatusMessage({ processing: true, position: 2 }); |
| 43 | + expect(result).toBe("🔄 Processing — Position 2"); |
| 44 | + }); |
| 45 | + |
| 46 | + it("formats processing with position and total", () => { |
| 47 | + const result = qp.formatQueueStatusMessage({ processing: true, position: 2, total: 5 }); |
| 48 | + expect(result).toBe("🔄 Processing — Position 2/5"); |
| 49 | + }); |
| 50 | + |
| 51 | + it("formats all params together", () => { |
| 52 | + const result = qp.formatQueueStatusMessage({ |
| 53 | + processing: true, |
| 54 | + position: 1, |
| 55 | + total: 3, |
| 56 | + url: "https://example.com/page", |
| 57 | + note: "Almost done" |
| 58 | + }); |
| 59 | + expect(result).toBe("🔄 Processing — Position 1/3 — URL: <https://example.com/page> — Almost done"); |
| 60 | + }); |
| 61 | + |
| 62 | + it("handles zero position correctly", () => { |
| 63 | + const result = qp.formatQueueStatusMessage({ position: 0, total: 5 }); |
| 64 | + expect(result).toBe("Position 0/5"); |
| 65 | + }); |
| 66 | + |
| 67 | + it("handles position zero without total", () => { |
| 68 | + const result = qp.formatQueueStatusMessage({ position: 0 }); |
| 69 | + expect(result).toBe("Position 0"); |
| 70 | + }); |
| 71 | + |
| 72 | + it("ignores undefined optional params", () => { |
| 73 | + const result = qp.formatQueueStatusMessage({ |
| 74 | + processing: true, |
| 75 | + position: undefined, |
| 76 | + total: undefined, |
| 77 | + url: undefined, |
| 78 | + note: undefined |
| 79 | + }); |
| 80 | + expect(result).toBe("🔄 Processing"); |
| 81 | + }); |
| 82 | + |
| 83 | + it("handles URL with special characters", () => { |
| 84 | + const result = qp.formatQueueStatusMessage({ url: "https://example.com/path?query=value&other=test" }); |
| 85 | + expect(result).toBe("URL: <https://example.com/path?query=value&other=test>"); |
| 86 | + }); |
| 87 | + |
| 88 | + it("handles multiline note", () => { |
| 89 | + const result = qp.formatQueueStatusMessage({ note: "Line 1\nLine 2" }); |
| 90 | + expect(result).toBe("Line 1\nLine 2"); |
| 91 | + }); |
| 92 | +}); |
0 commit comments