legacyPlanToggle.spec.tsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {PlanMigrationFixture} from 'getsentry-test/fixtures/planMigration';
  3. import {SubscriptionFixture} from 'getsentry-test/fixtures/subscription';
  4. import {
  5. cleanup,
  6. render,
  7. screen,
  8. waitForElementToBeRemoved,
  9. } from 'sentry-test/reactTestingLibrary';
  10. import SubscriptionStore from 'getsentry/stores/subscriptionStore';
  11. import {CohortId} from 'getsentry/types';
  12. import LegacyPlanToggle from 'getsentry/views/amCheckout/legacyPlanToggle';
  13. describe('LegacyPlanToggle', function () {
  14. const organization = OrganizationFixture();
  15. beforeEach(function () {
  16. MockApiClient.addMockResponse({
  17. url: `/customers/${organization.slug}/plan-migrations/?applied=0`,
  18. body: [],
  19. });
  20. });
  21. afterEach(function () {
  22. cleanup();
  23. SubscriptionStore.set(organization.slug, {});
  24. MockApiClient.clearMockResponses();
  25. });
  26. describe('AMCheckout', function () {
  27. it('renders for am1 paid plan', async function () {
  28. const org = OrganizationFixture();
  29. const subscription = SubscriptionFixture({
  30. organization: org,
  31. planTier: 'am1',
  32. plan: 'am1_team',
  33. });
  34. SubscriptionStore.set(org.slug, subscription);
  35. render(
  36. <LegacyPlanToggle organization={org} checkoutTier="am2" onClick={jest.fn()} />
  37. );
  38. await waitForElementToBeRemoved(screen.queryByTestId('loading-indicator'));
  39. expect(
  40. await screen.findByRole('button', {name: 'Show previous plans'})
  41. ).toBeInTheDocument();
  42. });
  43. it('renders for am1 paid plan in previous checkout', async function () {
  44. const org = OrganizationFixture();
  45. const subscription = SubscriptionFixture({
  46. organization: org,
  47. planTier: 'am1',
  48. plan: 'am1_team',
  49. });
  50. SubscriptionStore.set(org.slug, subscription);
  51. render(
  52. <LegacyPlanToggle organization={org} checkoutTier="am1" onClick={jest.fn()} />
  53. );
  54. await waitForElementToBeRemoved(screen.queryByTestId('loading-indicator'));
  55. expect(screen.getByRole('button', {name: 'Show latest plans'})).toBeInTheDocument();
  56. });
  57. it('does not render for am1 free plan', async function () {
  58. const org = OrganizationFixture();
  59. const subscription = SubscriptionFixture({
  60. organization: org,
  61. planTier: 'am1',
  62. plan: 'am1_f',
  63. });
  64. SubscriptionStore.set(org.slug, subscription);
  65. const {container} = render(
  66. <LegacyPlanToggle organization={org} checkoutTier="am2" onClick={jest.fn()} />
  67. );
  68. await waitForElementToBeRemoved(screen.queryByTestId('loading-indicator'));
  69. expect(container).toBeEmptyDOMElement();
  70. });
  71. it('does not render for am2 free plan', async function () {
  72. const org = OrganizationFixture();
  73. const subscription = SubscriptionFixture({
  74. organization: org,
  75. planTier: 'am2',
  76. plan: 'am2_f',
  77. });
  78. SubscriptionStore.set(org.slug, subscription);
  79. const {container} = render(
  80. <LegacyPlanToggle organization={org} checkoutTier="am2" onClick={jest.fn()} />
  81. );
  82. await waitForElementToBeRemoved(screen.queryByTestId('loading-indicator'));
  83. expect(container).toBeEmptyDOMElement();
  84. });
  85. it('does not render for am2 paid plan', async function () {
  86. const org = OrganizationFixture();
  87. const subscription = SubscriptionFixture({
  88. organization: org,
  89. planTier: 'am2',
  90. plan: 'am2_team',
  91. });
  92. SubscriptionStore.set(org.slug, subscription);
  93. const {container} = render(
  94. <LegacyPlanToggle organization={org} checkoutTier="am2" onClick={jest.fn()} />
  95. );
  96. await waitForElementToBeRemoved(screen.queryByTestId('loading-indicator'));
  97. expect(container).toBeEmptyDOMElement();
  98. });
  99. it('does not render for am3 free plan', function () {
  100. const org = OrganizationFixture();
  101. const subscription = SubscriptionFixture({
  102. organization: org,
  103. planTier: 'am3',
  104. plan: 'am3_f',
  105. });
  106. SubscriptionStore.set(org.slug, subscription);
  107. const {container} = render(
  108. <LegacyPlanToggle organization={org} checkoutTier="am3" onClick={jest.fn()} />
  109. );
  110. expect(container).toBeEmptyDOMElement();
  111. });
  112. it('does not render for am3 paid plan', function () {
  113. const org = OrganizationFixture();
  114. const subscription = SubscriptionFixture({
  115. organization: org,
  116. planTier: 'am3',
  117. plan: 'am3_team',
  118. });
  119. SubscriptionStore.set(org.slug, subscription);
  120. const {container} = render(
  121. <LegacyPlanToggle organization={org} checkoutTier="am3" onClick={jest.fn()} />
  122. );
  123. expect(container).toBeEmptyDOMElement();
  124. });
  125. it('does not render with mm2 paid plan', async function () {
  126. const subscription = SubscriptionFixture({
  127. organization,
  128. planTier: 'mm2',
  129. plan: 'mm2_b_100k',
  130. });
  131. SubscriptionStore.set(organization.slug, subscription);
  132. const {container} = render(
  133. <LegacyPlanToggle
  134. organization={organization}
  135. checkoutTier="am2"
  136. onClick={jest.fn()}
  137. />
  138. );
  139. await waitForElementToBeRemoved(screen.queryByTestId('loading-indicator'));
  140. expect(container).toBeEmptyDOMElement();
  141. });
  142. it('does not render with mm2 paid plan and pending plan migration', async function () {
  143. MockApiClient.addMockResponse({
  144. url: `/customers/${organization.slug}/plan-migrations/?applied=0`,
  145. body: PlanMigrationFixture({cohortId: CohortId.SECOND}),
  146. });
  147. const subscription = SubscriptionFixture({
  148. organization,
  149. planTier: 'mm2',
  150. plan: 'mm2_b_100k',
  151. });
  152. SubscriptionStore.set(organization.slug, subscription);
  153. const {container} = render(
  154. <LegacyPlanToggle
  155. organization={organization}
  156. checkoutTier="am2"
  157. onClick={jest.fn()}
  158. />
  159. );
  160. await waitForElementToBeRemoved(screen.queryByTestId('loading-indicator'));
  161. expect(container).toBeEmptyDOMElement();
  162. });
  163. it('does not render with mm2 free plan', async function () {
  164. const subscription = SubscriptionFixture({
  165. organization,
  166. planTier: 'mm2',
  167. plan: 'mm2_f',
  168. });
  169. SubscriptionStore.set(organization.slug, subscription);
  170. const {container} = render(
  171. <LegacyPlanToggle
  172. organization={organization}
  173. checkoutTier="am2"
  174. onClick={jest.fn()}
  175. />
  176. );
  177. await waitForElementToBeRemoved(screen.queryByTestId('loading-indicator'));
  178. expect(container).toBeEmptyDOMElement();
  179. });
  180. it('does not render with mm1 free plan', async function () {
  181. const subscription = SubscriptionFixture({
  182. organization,
  183. planTier: 'mm1',
  184. plan: 'f1',
  185. });
  186. SubscriptionStore.set(organization.slug, subscription);
  187. const {container} = render(
  188. <LegacyPlanToggle
  189. organization={organization}
  190. checkoutTier="am2"
  191. onClick={jest.fn()}
  192. />
  193. );
  194. await waitForElementToBeRemoved(screen.queryByTestId('loading-indicator'));
  195. expect(container).toBeEmptyDOMElement();
  196. });
  197. it('does not render with mm1 paid plan', async function () {
  198. const subscription = SubscriptionFixture({
  199. organization,
  200. planTier: 'mm1',
  201. plan: 'm1',
  202. });
  203. SubscriptionStore.set(organization.slug, subscription);
  204. const {container} = render(
  205. <LegacyPlanToggle
  206. organization={organization}
  207. checkoutTier="am2"
  208. onClick={jest.fn()}
  209. />
  210. );
  211. await waitForElementToBeRemoved(screen.queryByTestId('loading-indicator'));
  212. expect(container).toBeEmptyDOMElement();
  213. });
  214. });
  215. });