trialSubscriptionAction.spec.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. import moment from 'moment-timezone';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {SubscriptionFixture} from 'getsentry-test/fixtures/subscription';
  4. import {
  5. renderGlobalModal,
  6. screen,
  7. userEvent,
  8. within,
  9. } from 'sentry-test/reactTestingLibrary';
  10. import {openAdminConfirmModal} from 'admin/components/adminConfirmationModal';
  11. import TrialSubscriptionAction from 'admin/components/trialSubscriptionAction';
  12. import {PlanTier} from 'getsentry/types';
  13. describe('TrialSubscriptionAction', function () {
  14. const organization = OrganizationFixture();
  15. const onConfirm = jest.fn();
  16. const now = moment();
  17. const formattedNow = now.format('MMMM Do YYYY');
  18. const trialEnd = now.add(14, 'days');
  19. const formattedTrialEnd = trialEnd.format('MMMM Do YYYY');
  20. async function confirmTrialDays(days: any) {
  21. const daysInput = screen.getByRole('spinbutton', {name: 'Number of Days'});
  22. await userEvent.clear(daysInput);
  23. await userEvent.type(daysInput, days);
  24. await userEvent.click(screen.getByTestId('confirm-button'));
  25. }
  26. it('can pass trialDays onConfirm', async function () {
  27. openAdminConfirmModal({
  28. onConfirm,
  29. renderModalSpecificContent: deps => (
  30. <TrialSubscriptionAction
  31. subscription={SubscriptionFixture({organization})}
  32. {...deps}
  33. />
  34. ),
  35. });
  36. renderGlobalModal();
  37. await confirmTrialDays('30');
  38. expect(onConfirm).toHaveBeenCalledWith({trialDays: 30});
  39. });
  40. it('can pass trialDays and enterprise plan onConfirm', async function () {
  41. jest.mock('sentry/components/core/alert');
  42. openAdminConfirmModal({
  43. onConfirm,
  44. renderModalSpecificContent: deps => (
  45. <TrialSubscriptionAction
  46. subscription={SubscriptionFixture({
  47. organization,
  48. plan: 'mm2_f',
  49. isFree: true,
  50. })}
  51. startEnterpriseTrial
  52. {...deps}
  53. />
  54. ),
  55. });
  56. renderGlobalModal();
  57. expect(
  58. screen.getByText('Spike protection will need to be manually disabled.')
  59. ).toBeInTheDocument();
  60. await confirmTrialDays('45');
  61. expect(onConfirm).toHaveBeenCalledWith({
  62. trialDays: 45,
  63. startEnterpriseTrial: true,
  64. trialTier: PlanTier.AM3,
  65. });
  66. });
  67. it('can pass trialDays and extend enterprise plan onConfirm', async function () {
  68. jest.mock('sentry/components/core/alert');
  69. openAdminConfirmModal({
  70. onConfirm,
  71. renderModalSpecificContent: deps => (
  72. <TrialSubscriptionAction
  73. subscription={SubscriptionFixture({
  74. organization,
  75. plan: 'mm2_a_500k',
  76. isFree: false,
  77. isEnterpriseTrial: true,
  78. })}
  79. {...deps}
  80. />
  81. ),
  82. });
  83. renderGlobalModal();
  84. await confirmTrialDays('21');
  85. expect(onConfirm).toHaveBeenCalledWith({trialDays: 21});
  86. });
  87. it('can pass trialDays and trialPlanOverride onConfirm', async function () {
  88. jest.mock('sentry/components/core/alert');
  89. openAdminConfirmModal({
  90. onConfirm,
  91. renderModalSpecificContent: deps => (
  92. <TrialSubscriptionAction
  93. subscription={SubscriptionFixture({
  94. organization,
  95. plan: 'am3_f',
  96. isFree: true,
  97. })}
  98. startEnterpriseTrial
  99. canUseTrialOverride
  100. {...deps}
  101. />
  102. ),
  103. });
  104. renderGlobalModal();
  105. await userEvent.click(screen.getByTestId('trial-plan-tier-choices'));
  106. const trialTierInputs = within(screen.getByRole('dialog')).getAllByRole('textbox');
  107. await userEvent.click(trialTierInputs[0]!);
  108. await userEvent.click(screen.getByText('am3 with Dynamic Sampling'));
  109. await confirmTrialDays('14');
  110. expect(onConfirm).toHaveBeenCalledWith({
  111. trialDays: 14,
  112. startEnterpriseTrial: true,
  113. trialTier: PlanTier.AM3,
  114. trialPlanOverride: 'am3_t_ent_ds',
  115. });
  116. });
  117. it('cannot use trialPlanOverride if disabled', async function () {
  118. jest.mock('sentry/components/core/alert');
  119. openAdminConfirmModal({
  120. onConfirm,
  121. renderModalSpecificContent: deps => (
  122. <TrialSubscriptionAction
  123. subscription={SubscriptionFixture({
  124. organization,
  125. plan: 'am3_f',
  126. isFree: true,
  127. })}
  128. startEnterpriseTrial
  129. {...deps}
  130. />
  131. ),
  132. });
  133. renderGlobalModal();
  134. await userEvent.click(screen.getByTestId('trial-plan-tier-choices'));
  135. const trialTierInputs = within(screen.getByRole('dialog')).getAllByRole('textbox');
  136. await userEvent.click(trialTierInputs[0]!);
  137. expect(screen.queryByText('am3 with Dynamic Sampling')).not.toBeInTheDocument();
  138. });
  139. it('displays correct trial end date when starting trial', async function () {
  140. jest.mock('sentry/components/core/alert');
  141. openAdminConfirmModal({
  142. onConfirm,
  143. renderModalSpecificContent: deps => (
  144. <TrialSubscriptionAction
  145. subscription={SubscriptionFixture({
  146. organization,
  147. plan: 'mm2_f',
  148. isFree: true,
  149. })}
  150. {...deps}
  151. />
  152. ),
  153. });
  154. renderGlobalModal();
  155. const daysInput = screen.getByRole('spinbutton', {name: 'Number of Days'});
  156. await userEvent.clear(daysInput);
  157. await userEvent.type(daysInput, '0');
  158. expect(daysInput).toHaveAccessibleDescription(
  159. `Their trial will end on ${formattedNow}`
  160. );
  161. });
  162. it('displays correct trial end date when starting enterprise trial', async function () {
  163. jest.mock('sentry/components/core/alert');
  164. openAdminConfirmModal({
  165. onConfirm,
  166. renderModalSpecificContent: deps => (
  167. <TrialSubscriptionAction
  168. subscription={SubscriptionFixture({
  169. organization,
  170. plan: 'mm2_f',
  171. isFree: true,
  172. })}
  173. startEnterpriseTrial
  174. {...deps}
  175. />
  176. ),
  177. });
  178. renderGlobalModal();
  179. const daysInput = screen.getByRole('spinbutton', {name: 'Number of Days'});
  180. await userEvent.clear(daysInput);
  181. await userEvent.type(daysInput, '0');
  182. expect(daysInput).toHaveAccessibleDescription(
  183. `Their trial will end on ${formattedNow}`
  184. );
  185. });
  186. it('displays correct trial end date when extending trial', async function () {
  187. jest.mock('sentry/components/core/alert');
  188. openAdminConfirmModal({
  189. onConfirm,
  190. renderModalSpecificContent: deps => (
  191. <TrialSubscriptionAction
  192. subscription={SubscriptionFixture({
  193. organization,
  194. trialEnd: trialEnd.toString(),
  195. plan: 'am1_t',
  196. isFree: true,
  197. })}
  198. {...deps}
  199. />
  200. ),
  201. });
  202. renderGlobalModal();
  203. const daysInput = screen.getByRole('spinbutton', {name: 'Number of Days'});
  204. await userEvent.clear(daysInput);
  205. await userEvent.type(daysInput, '0');
  206. expect(daysInput).toHaveAccessibleDescription(
  207. `Their trial will end on ${formattedTrialEnd}`
  208. );
  209. });
  210. it('displays correct trial end date when converting from trial to enterprise trial', async function () {
  211. jest.mock('sentry/components/core/alert');
  212. openAdminConfirmModal({
  213. onConfirm,
  214. renderModalSpecificContent: deps => (
  215. <TrialSubscriptionAction
  216. subscription={SubscriptionFixture({
  217. organization,
  218. trialEnd: trialEnd.toString(),
  219. plan: 'am1_t',
  220. isFree: true,
  221. })}
  222. startEnterpriseTrial
  223. {...deps}
  224. />
  225. ),
  226. });
  227. renderGlobalModal();
  228. const daysInput = screen.getByRole('spinbutton', {name: 'Number of Days'});
  229. await userEvent.clear(daysInput);
  230. await userEvent.type(daysInput, '0');
  231. expect(daysInput).toHaveAccessibleDescription(
  232. `Their trial will end on ${formattedNow}`
  233. );
  234. });
  235. it('displays am3 trial tier option when free plan', async function () {
  236. jest.mock('sentry/components/core/alert');
  237. openAdminConfirmModal({
  238. onConfirm,
  239. renderModalSpecificContent: deps => (
  240. <TrialSubscriptionAction
  241. subscription={SubscriptionFixture({
  242. organization,
  243. plan: 'am2_f',
  244. isFree: true,
  245. planTier: PlanTier.AM2,
  246. })}
  247. startEnterpriseTrial
  248. {...deps}
  249. />
  250. ),
  251. });
  252. renderGlobalModal();
  253. await userEvent.click(screen.getByTestId('trial-plan-tier-choices'));
  254. const trialTierInputs = within(screen.getByRole('dialog')).getAllByRole('textbox');
  255. await userEvent.click(trialTierInputs[1]!);
  256. expect(screen.getByText('am3')).toBeInTheDocument();
  257. });
  258. it('displays am3 trial tier option when am3 plan', async function () {
  259. jest.mock('sentry/components/core/alert');
  260. openAdminConfirmModal({
  261. onConfirm,
  262. renderModalSpecificContent: deps => (
  263. <TrialSubscriptionAction
  264. subscription={SubscriptionFixture({
  265. organization,
  266. plan: 'am3_team',
  267. isFree: false,
  268. planTier: PlanTier.AM3,
  269. })}
  270. startEnterpriseTrial
  271. {...deps}
  272. />
  273. ),
  274. });
  275. renderGlobalModal();
  276. await userEvent.click(screen.getByTestId('trial-plan-tier-choices'));
  277. const trialTierInputs = within(screen.getByRole('dialog')).getAllByRole('textbox');
  278. await userEvent.click(trialTierInputs[1]!);
  279. expect(screen.getByText('am3')).toBeInTheDocument();
  280. });
  281. it('displays am3 trial tier option when am2 plan', async function () {
  282. jest.mock('sentry/components/core/alert');
  283. openAdminConfirmModal({
  284. onConfirm,
  285. renderModalSpecificContent: deps => (
  286. <TrialSubscriptionAction
  287. subscription={SubscriptionFixture({
  288. organization,
  289. plan: 'am2_team',
  290. isFree: false,
  291. planTier: PlanTier.AM2,
  292. })}
  293. startEnterpriseTrial
  294. {...deps}
  295. />
  296. ),
  297. });
  298. renderGlobalModal();
  299. await userEvent.click(screen.getByTestId('trial-plan-tier-choices'));
  300. const trialTierInputs = within(screen.getByRole('dialog')).getAllByRole('textbox');
  301. await userEvent.click(trialTierInputs[1]!);
  302. expect(screen.getByText('am3')).toBeInTheDocument();
  303. });
  304. });