disabledSelectorItems.spec.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {SubscriptionFixture} from 'getsentry-test/fixtures/subscription';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import DropdownAutoComplete from 'sentry/components/dropdownAutoComplete';
  5. import {PlanFixture} from 'getsentry/__fixtures__/plan';
  6. import DisabledSelectorItems from 'getsentry/components/features/disabledSelectorItems';
  7. import SubscriptionStore from 'getsentry/stores/subscriptionStore';
  8. describe('DisabledSelectorItems', function () {
  9. const handleSelectRelative = jest.fn();
  10. it('renders extended relative periods without sub', function () {
  11. const organization = OrganizationFixture();
  12. SubscriptionStore.set(organization.slug, {});
  13. render(
  14. <DisabledSelectorItems
  15. shouldShowRelative
  16. shouldShowAbsolute
  17. handleSelectRelative={handleSelectRelative}
  18. >
  19. {items => (
  20. <DropdownAutoComplete isOpen items={items}>
  21. {() => null}
  22. </DropdownAutoComplete>
  23. )}
  24. </DisabledSelectorItems>
  25. );
  26. expect(screen.getByText('Last hour')).toBeInTheDocument();
  27. expect(screen.getByText('Last 14 days')).toBeInTheDocument();
  28. expect(screen.getByText('Last 30 days')).toBeInTheDocument();
  29. expect(screen.getByText('Last 90 days')).toBeInTheDocument();
  30. expect(screen.queryByText(/Start Trial/)).not.toBeInTheDocument();
  31. });
  32. it('renders extended relative periods for paid plan', function () {
  33. const organization = OrganizationFixture({slug: 'paid'});
  34. SubscriptionStore.set(
  35. organization.slug,
  36. SubscriptionFixture({
  37. organization,
  38. plan: 'mm2_b_100k',
  39. planDetails: PlanFixture({
  40. retentionDays: 90,
  41. }),
  42. })
  43. );
  44. render(
  45. <DisabledSelectorItems
  46. shouldShowRelative
  47. shouldShowAbsolute
  48. handleSelectRelative={handleSelectRelative}
  49. >
  50. {items => (
  51. <DropdownAutoComplete isOpen items={items}>
  52. {() => null}
  53. </DropdownAutoComplete>
  54. )}
  55. </DisabledSelectorItems>,
  56. {organization}
  57. );
  58. expect(screen.getByText('Last hour')).toBeInTheDocument();
  59. expect(screen.getByText('Last 14 days')).toBeInTheDocument();
  60. expect(screen.getByText('Last 30 days')).toBeInTheDocument();
  61. expect(screen.getByText('Last 90 days')).toBeInTheDocument();
  62. expect(screen.queryByText(/Start Trial/)).not.toBeInTheDocument();
  63. });
  64. it('renders upsell and not extended relative periods for free plan', function () {
  65. const organization = OrganizationFixture({slug: 'free'});
  66. SubscriptionStore.set(
  67. organization.slug,
  68. SubscriptionFixture({
  69. organization,
  70. plan: 'mm2_f',
  71. planDetails: PlanFixture({
  72. retentionDays: 30,
  73. }),
  74. })
  75. );
  76. render(
  77. <DisabledSelectorItems
  78. shouldShowRelative
  79. shouldShowAbsolute
  80. handleSelectRelative={handleSelectRelative}
  81. >
  82. {items => (
  83. <DropdownAutoComplete isOpen items={items}>
  84. {() => null}
  85. </DropdownAutoComplete>
  86. )}
  87. </DisabledSelectorItems>,
  88. {organization}
  89. );
  90. expect(screen.getByText('Last hour')).toBeInTheDocument();
  91. expect(screen.getByText('Last 14 days')).toBeInTheDocument();
  92. expect(screen.getByText('Last 30 days')).toBeInTheDocument();
  93. expect(screen.getByText('Last 90 days')).toBeInTheDocument();
  94. expect(screen.getByText(/Start Trial/)).toBeInTheDocument();
  95. });
  96. it('does not render upsell when 90 day is not a relative option for free plan', function () {
  97. const organization = OrganizationFixture({slug: 'free'});
  98. SubscriptionStore.set(
  99. organization.slug,
  100. SubscriptionFixture({
  101. organization,
  102. plan: 'mm2_f',
  103. planDetails: PlanFixture({
  104. retentionDays: 30,
  105. }),
  106. })
  107. );
  108. render(
  109. <DisabledSelectorItems
  110. shouldShowRelative
  111. shouldShowAbsolute
  112. handleSelectRelative={handleSelectRelative}
  113. relativePeriods={{
  114. '1h': 'Last hour',
  115. '24h': 'Last 24 hours',
  116. '7d': 'Last 7 days',
  117. '14d': 'Last 14 days',
  118. '30d': 'Last 30 days',
  119. }}
  120. >
  121. {items => (
  122. <DropdownAutoComplete isOpen items={items}>
  123. {() => null}
  124. </DropdownAutoComplete>
  125. )}
  126. </DisabledSelectorItems>,
  127. {organization}
  128. );
  129. expect(screen.getByText('Last hour')).toBeInTheDocument();
  130. expect(screen.getByText('Last 24 hours')).toBeInTheDocument();
  131. expect(screen.getByText('Last 7 days')).toBeInTheDocument();
  132. expect(screen.getByText('Last 14 days')).toBeInTheDocument();
  133. expect(screen.getByText('Last 30 days')).toBeInTheDocument();
  134. // 90 days is not provided as an option so do not include the upsell
  135. expect(screen.queryByText('Last 90 days')).not.toBeInTheDocument();
  136. expect(screen.queryByText(/Start Trial/)).not.toBeInTheDocument();
  137. });
  138. });