|
| 1 | +import { createElement } from 'react' |
| 2 | +import { renderToStaticMarkup } from 'react-dom/server' |
| 3 | +import { describe, expect, it, vi } from 'vitest' |
| 4 | + |
| 5 | +import type { BudgetSimulationResult } from '../utils/budgetSimulation' |
| 6 | +import { EMPTY_BUDGET_VALUES, type BudgetValues } from '../utils/costManagementBudgets' |
| 7 | +import { CostManagementView } from './CostManagementView' |
| 8 | + |
| 9 | +const baseBudgetValues: BudgetValues = { |
| 10 | + ...EMPTY_BUDGET_VALUES, |
| 11 | + account: '1', |
| 12 | +} |
| 13 | + |
| 14 | +const baseBudgetSimulation: BudgetSimulationResult = { |
| 15 | + totalBill: 0.4, |
| 16 | + blockedUsers: 1, |
| 17 | + blockedRequests: 7, |
| 18 | + blockedIncludedCreditsAic: 0, |
| 19 | + allowedAicQuantity: 40, |
| 20 | + budgetExhausted: true, |
| 21 | + firstUserBlockedDate: null, |
| 22 | + accountBlockedDate: '2026-06-01', |
| 23 | + productBlockedDates: {}, |
| 24 | + adjustedDailyNetCostByDate: [], |
| 25 | + adjustedDailyGrossCostByDate: [], |
| 26 | +} |
| 27 | + |
| 28 | +function renderCostManagementView(overrides: Partial<Parameters<typeof CostManagementView>[0]> = {}): string { |
| 29 | + return renderToStaticMarkup(createElement(CostManagementView, { |
| 30 | + budgetValues: baseBudgetValues, |
| 31 | + isIndividualReport: false, |
| 32 | + currentPruBill: 0, |
| 33 | + currentPruGrossAmount: 0, |
| 34 | + currentPruDiscountAmount: 0, |
| 35 | + currentPruQuantity: 0, |
| 36 | + currentAicBill: 1, |
| 37 | + currentAicGrossAmount: 1, |
| 38 | + currentAicDiscountAmount: 0, |
| 39 | + currentAicQuantity: 100, |
| 40 | + includedAicPoolSize: 0, |
| 41 | + dailyUsageData: [], |
| 42 | + budgetSimulation: null, |
| 43 | + budgetSimulationError: null, |
| 44 | + isApplyingBudgetSimulation: false, |
| 45 | + onBudgetValueChange: vi.fn(), |
| 46 | + onApplyBudgetSimulation: vi.fn(), |
| 47 | + showOrganizationPromotionalDataDisclaimer: false, |
| 48 | + ...overrides, |
| 49 | + })) |
| 50 | +} |
| 51 | + |
| 52 | +describe('CostManagementView', () => { |
| 53 | + it('shows budget controls for native usage-based billing reports', () => { |
| 54 | + const html = renderCostManagementView({ |
| 55 | + reportMode: 'native-ai-credits', |
| 56 | + }) |
| 57 | + |
| 58 | + expect(html).toContain('Set USD budgets and preview how they would affect usage-based billing for this report.') |
| 59 | + expect(html).toContain('Account-level budget') |
| 60 | + expect(html).toContain('Apply') |
| 61 | + expect(html).not.toContain('Budget simulation is not available') |
| 62 | + expect(html).not.toContain('native AI Credits reports yet') |
| 63 | + expect(html).not.toContain('PRU') |
| 64 | + }) |
| 65 | + |
| 66 | + it('uses AI Credits result labels instead of PRU labels for native reports', () => { |
| 67 | + const html = renderCostManagementView({ |
| 68 | + reportMode: 'native-ai-credits', |
| 69 | + budgetSimulation: baseBudgetSimulation, |
| 70 | + }) |
| 71 | + |
| 72 | + expect(html).toContain('Blocked AI Credits') |
| 73 | + expect(html).toContain('60') |
| 74 | + expect(html).toContain('Simulated AI Credits additional usage spend') |
| 75 | + expect(html).not.toContain('Blocked PRUs') |
| 76 | + expect(html).not.toContain('later requests') |
| 77 | + }) |
| 78 | + |
| 79 | + it('keeps PRU blocked-usage labeling for transition-period reports', () => { |
| 80 | + const html = renderCostManagementView({ |
| 81 | + reportMode: 'transition-period-billing-preview', |
| 82 | + budgetSimulation: baseBudgetSimulation, |
| 83 | + }) |
| 84 | + |
| 85 | + expect(html).toContain('Blocked PRUs') |
| 86 | + expect(html).toContain('later requests') |
| 87 | + expect(html).not.toContain('Blocked AI Credits') |
| 88 | + }) |
| 89 | +}) |
0 commit comments