usageCard.spec.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {MetricHistoryFixture} from 'getsentry-test/fixtures/metricHistory';
  3. import {SubscriptionFixture} from 'getsentry-test/fixtures/subscription';
  4. import {render, screen} from 'sentry-test/reactTestingLibrary';
  5. import {OnDemandBudgetMode} from 'getsentry/types';
  6. import {UsageCard} from './usageCard';
  7. describe('UsageCard', () => {
  8. const organization = OrganizationFixture({features: ['ondemand-budgets']});
  9. it('should render amount used and max available', () => {
  10. const subscription = SubscriptionFixture({
  11. organization,
  12. planTier: 'am2',
  13. plan: 'am2_team',
  14. });
  15. const prepaid = 100_000;
  16. subscription.categories.errors = MetricHistoryFixture({
  17. prepaid,
  18. reserved: prepaid,
  19. });
  20. render(<UsageCard organization={organization} subscription={subscription} />);
  21. expect(screen.getByText('Included in Subscription').parentElement).toHaveTextContent(
  22. '0% of $15'
  23. );
  24. expect(screen.getByTestId('current-monthly-spend')).toHaveTextContent('$44');
  25. });
  26. it('should render on demand max spend and prepaid', () => {
  27. const subscription = SubscriptionFixture({
  28. organization,
  29. planTier: 'am2',
  30. plan: 'am2_team',
  31. onDemandMaxSpend: 1000,
  32. });
  33. const prepaid = 100_000;
  34. subscription.categories.errors = MetricHistoryFixture({
  35. prepaid,
  36. reserved: prepaid,
  37. });
  38. render(<UsageCard organization={organization} subscription={subscription} />);
  39. expect(screen.getByText('Included in Subscription').parentElement).toHaveTextContent(
  40. '0% of $15'
  41. );
  42. expect(screen.getByText('On-Demand').parentElement).toHaveTextContent('$0 of $10');
  43. expect(screen.getByText('On-Demand Spent')).toBeInTheDocument();
  44. expect(screen.getByTestId('current-monthly-spend')).toHaveTextContent('$44');
  45. });
  46. it('should render PAYG spend for am3', () => {
  47. const subscription = SubscriptionFixture({
  48. organization,
  49. planTier: 'am3',
  50. plan: 'am3_team',
  51. onDemandMaxSpend: 1000,
  52. onDemandBudgets: {
  53. budgetMode: OnDemandBudgetMode.SHARED,
  54. enabled: true,
  55. sharedMaxBudget: 1000,
  56. onDemandSpendUsed: 0,
  57. },
  58. });
  59. render(<UsageCard organization={organization} subscription={subscription} />);
  60. expect(screen.getByText('Pay-as-you-go Spent')).toBeInTheDocument();
  61. expect(screen.getByTestId('current-monthly-spend')).toHaveTextContent('$29');
  62. });
  63. it('should not render prepaid usage if org has no reserved spend', () => {
  64. const subscription = SubscriptionFixture({
  65. organization,
  66. planTier: 'am2',
  67. plan: 'am2_business_auf',
  68. onDemandMaxSpend: 1000,
  69. });
  70. render(<UsageCard organization={organization} subscription={subscription} />);
  71. expect(screen.queryByText('Reserved')).not.toBeInTheDocument();
  72. expect(screen.getByText('On-Demand')).toBeInTheDocument();
  73. expect(screen.queryByText('Included In Subscription')).not.toBeInTheDocument();
  74. expect(screen.getByTestId('current-monthly-spend')).toHaveTextContent('$960');
  75. });
  76. it('should not render anything for orgs with no spend', () => {
  77. const subscription = SubscriptionFixture({
  78. organization,
  79. planTier: 'am2',
  80. plan: 'am2_team',
  81. });
  82. const {container} = render(
  83. <UsageCard organization={organization} subscription={subscription} />
  84. );
  85. expect(container).toBeEmptyDOMElement();
  86. });
  87. it('should not render anything for free orgs', () => {
  88. const subscription = SubscriptionFixture({
  89. organization,
  90. planTier: 'am2',
  91. plan: 'am2_f',
  92. });
  93. const {container} = render(
  94. <UsageCard organization={organization} subscription={subscription} />
  95. );
  96. expect(container).toBeEmptyDOMElement();
  97. });
  98. });