|
| 1 | +/** |
| 2 | + * Tests for LicenseBadge component |
| 3 | + * |
| 4 | + * Tests rendering of license badge for each tier state: |
| 5 | + * solo, team, trial, expired, and null (hidden). |
| 6 | + */ |
| 7 | +import { describe, it, expect } from "bun:test"; |
| 8 | +import React from "react"; |
| 9 | +import { renderToStaticMarkup } from "react-dom/server"; |
| 10 | +import { LicenseBadge } from "../../src/ui/viewer/components/LicenseBadge.js"; |
| 11 | +import type { LicenseResponse } from "../../src/services/worker/http/routes/LicenseRoutes.js"; |
| 12 | + |
| 13 | +function renderBadge(license: LicenseResponse | null, isLoading = false) { |
| 14 | + return renderToStaticMarkup( |
| 15 | + React.createElement(LicenseBadge, { license, isLoading }), |
| 16 | + ); |
| 17 | +} |
| 18 | + |
| 19 | +describe("LicenseBadge", () => { |
| 20 | + it("should render Solo badge with primary variant", () => { |
| 21 | + const html = renderBadge({ |
| 22 | + valid: true, |
| 23 | + tier: "solo", |
| 24 | + email: "user@example.com", |
| 25 | + daysRemaining: null, |
| 26 | + isExpired: false, |
| 27 | + }); |
| 28 | + |
| 29 | + expect(html).toContain("Solo"); |
| 30 | + expect(html).toContain("badge-primary"); |
| 31 | + }); |
| 32 | + |
| 33 | + it("should render Team badge with accent variant", () => { |
| 34 | + const html = renderBadge({ |
| 35 | + valid: true, |
| 36 | + tier: "team", |
| 37 | + email: "team@example.com", |
| 38 | + daysRemaining: null, |
| 39 | + isExpired: false, |
| 40 | + }); |
| 41 | + |
| 42 | + expect(html).toContain("Team"); |
| 43 | + expect(html).toContain("badge-accent"); |
| 44 | + }); |
| 45 | + |
| 46 | + it("should render Trial badge with warning variant and days remaining", () => { |
| 47 | + const html = renderBadge({ |
| 48 | + valid: true, |
| 49 | + tier: "trial", |
| 50 | + email: "trial@example.com", |
| 51 | + daysRemaining: 7, |
| 52 | + isExpired: false, |
| 53 | + }); |
| 54 | + |
| 55 | + expect(html).toContain("Trial"); |
| 56 | + expect(html).toContain("7d left"); |
| 57 | + expect(html).toContain("badge-warning"); |
| 58 | + }); |
| 59 | + |
| 60 | + it("should render expired badge with error variant", () => { |
| 61 | + const html = renderBadge({ |
| 62 | + valid: false, |
| 63 | + tier: "trial", |
| 64 | + email: "trial@example.com", |
| 65 | + daysRemaining: null, |
| 66 | + isExpired: true, |
| 67 | + }); |
| 68 | + |
| 69 | + expect(html).toContain("Expired"); |
| 70 | + expect(html).toContain("badge-error"); |
| 71 | + }); |
| 72 | + |
| 73 | + it("should render nothing when tier is null (no license or no binary)", () => { |
| 74 | + const html = renderBadge({ |
| 75 | + valid: false, |
| 76 | + tier: null, |
| 77 | + email: null, |
| 78 | + daysRemaining: null, |
| 79 | + isExpired: false, |
| 80 | + }); |
| 81 | + |
| 82 | + expect(html).toBe(""); |
| 83 | + }); |
| 84 | + |
| 85 | + it("should render nothing when license is null (loading state)", () => { |
| 86 | + const html = renderBadge(null); |
| 87 | + expect(html).toBe(""); |
| 88 | + }); |
| 89 | + |
| 90 | + it("should render nothing when isLoading is true", () => { |
| 91 | + const html = renderBadge( |
| 92 | + { valid: true, tier: "solo", email: "user@example.com", daysRemaining: null, isExpired: false }, |
| 93 | + true, |
| 94 | + ); |
| 95 | + expect(html).toBe(""); |
| 96 | + }); |
| 97 | + |
| 98 | + it("should include tooltip with tier and email", () => { |
| 99 | + const html = renderBadge({ |
| 100 | + valid: true, |
| 101 | + tier: "solo", |
| 102 | + email: "user@example.com", |
| 103 | + daysRemaining: null, |
| 104 | + isExpired: false, |
| 105 | + }); |
| 106 | + |
| 107 | + expect(html).toContain("tooltip"); |
| 108 | + expect(html).toContain("Solo"); |
| 109 | + expect(html).toContain("user@example.com"); |
| 110 | + }); |
| 111 | + |
| 112 | + it("should include days remaining in tooltip for trial tier", () => { |
| 113 | + const html = renderBadge({ |
| 114 | + valid: true, |
| 115 | + tier: "trial", |
| 116 | + email: "trial@example.com", |
| 117 | + daysRemaining: 5, |
| 118 | + isExpired: false, |
| 119 | + }); |
| 120 | + |
| 121 | + expect(html).toContain("5 days remaining"); |
| 122 | + }); |
| 123 | +}); |
0 commit comments