addGiftEventsAction.spec.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {SubscriptionFixture} from 'getsentry-test/fixtures/subscription';
  3. import {renderGlobalModal, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import {DataCategory} from 'sentry/types/core';
  5. import AddGiftEventsAction from 'admin/components/addGiftEventsAction';
  6. import {openAdminConfirmModal} from 'admin/components/adminConfirmationModal';
  7. import {MAX_ADMIN_CATEGORY_GIFTS} from 'getsentry/constants';
  8. describe('Gift', function () {
  9. const mockOrg = OrganizationFixture();
  10. const mockSub = SubscriptionFixture({organization: mockOrg});
  11. describe('Errors', function () {
  12. const triggerGiftModal = () => {
  13. openAdminConfirmModal({
  14. renderModalSpecificContent: deps => (
  15. <AddGiftEventsAction
  16. subscription={mockSub}
  17. dataCategory={DataCategory.ERRORS}
  18. {...deps}
  19. />
  20. ),
  21. });
  22. };
  23. function getErrorInput() {
  24. return screen.getByRole('textbox', {
  25. name: 'How many errors in multiples of 1,000s? (50 is 50,000 errors)',
  26. });
  27. }
  28. async function setNumEvents(numEvents: string) {
  29. await userEvent.clear(getErrorInput());
  30. await userEvent.type(getErrorInput(), numEvents);
  31. }
  32. it('has valid event volume', async function () {
  33. const maxValue = MAX_ADMIN_CATEGORY_GIFTS[DataCategory.ERRORS] / 1000;
  34. triggerGiftModal();
  35. renderGlobalModal();
  36. const errorInput = getErrorInput();
  37. await setNumEvents('1');
  38. expect(errorInput).toHaveValue('1');
  39. expect(errorInput).toHaveAccessibleDescription('Total: 1,000');
  40. await setNumEvents('-50');
  41. expect(errorInput).toHaveValue('50');
  42. expect(errorInput).toHaveAccessibleDescription('Total: 50,000');
  43. await setNumEvents(`${maxValue + 5}`);
  44. expect(errorInput).toHaveValue('10000');
  45. expect(errorInput).toHaveAccessibleDescription('Total: 10,000,000');
  46. await setNumEvents('10,');
  47. expect(errorInput).toHaveValue('10');
  48. expect(errorInput).toHaveAccessibleDescription('Total: 10,000');
  49. await setNumEvents('5.');
  50. expect(errorInput).toHaveValue('5');
  51. expect(errorInput).toHaveAccessibleDescription('Total: 5,000');
  52. });
  53. it('disables confirm button when no number is entered', function () {
  54. triggerGiftModal();
  55. renderGlobalModal();
  56. expect(screen.getByTestId('confirm-button')).toBeDisabled();
  57. });
  58. });
  59. describe('Attachments', function () {
  60. const triggerGiftModal = () => {
  61. openAdminConfirmModal({
  62. renderModalSpecificContent: deps => (
  63. <AddGiftEventsAction
  64. subscription={mockSub}
  65. dataCategory={DataCategory.ATTACHMENTS}
  66. {...deps}
  67. />
  68. ),
  69. });
  70. };
  71. function getAttachmentsInput() {
  72. return screen.getByRole('textbox', {
  73. name: 'How many attachments in GB?',
  74. });
  75. }
  76. async function setNumAttachments(numAttachments: string) {
  77. await userEvent.clear(getAttachmentsInput());
  78. await userEvent.type(getAttachmentsInput(), numAttachments);
  79. }
  80. it('has valid event volume', async function () {
  81. const maxValue = MAX_ADMIN_CATEGORY_GIFTS[DataCategory.ATTACHMENTS];
  82. triggerGiftModal();
  83. renderGlobalModal();
  84. const attachmentsInput = getAttachmentsInput();
  85. await setNumAttachments('1');
  86. expect(attachmentsInput).toHaveValue('1');
  87. expect(attachmentsInput).toHaveAccessibleDescription('Total: 1 GB');
  88. await setNumAttachments('-50');
  89. expect(attachmentsInput).toHaveValue('50');
  90. expect(attachmentsInput).toHaveAccessibleDescription('Total: 50 GB');
  91. await setNumAttachments(`${maxValue + 5}`);
  92. expect(attachmentsInput).toHaveValue('10000');
  93. expect(attachmentsInput).toHaveAccessibleDescription('Total: 10,000 GB');
  94. await setNumAttachments('10,');
  95. expect(attachmentsInput).toHaveValue('10');
  96. expect(attachmentsInput).toHaveAccessibleDescription('Total: 10 GB');
  97. await setNumAttachments('5.');
  98. expect(attachmentsInput).toHaveValue('5');
  99. expect(attachmentsInput).toHaveAccessibleDescription('Total: 5 GB');
  100. });
  101. it('disables confirm button when no number is entered', function () {
  102. triggerGiftModal();
  103. renderGlobalModal();
  104. expect(screen.getByTestId('confirm-button')).toBeDisabled();
  105. });
  106. });
  107. describe('Profile Duration', function () {
  108. const triggerGiftModal = () => {
  109. openAdminConfirmModal({
  110. renderModalSpecificContent: deps => (
  111. <AddGiftEventsAction
  112. subscription={mockSub}
  113. dataCategory={DataCategory.PROFILE_DURATION}
  114. {...deps}
  115. />
  116. ),
  117. });
  118. };
  119. function getProfileDurationInput() {
  120. return screen.getByRole('textbox', {
  121. name: 'How many profile hours?',
  122. });
  123. }
  124. async function setProfileDuration(duration: string) {
  125. await userEvent.clear(getProfileDurationInput());
  126. await userEvent.type(getProfileDurationInput(), duration);
  127. }
  128. it('has valid profile duration input', async function () {
  129. const maxValue = MAX_ADMIN_CATEGORY_GIFTS[DataCategory.PROFILE_DURATION];
  130. triggerGiftModal();
  131. renderGlobalModal();
  132. const profileDurationInput = getProfileDurationInput();
  133. await setProfileDuration('1');
  134. expect(profileDurationInput).toHaveValue('1');
  135. expect(profileDurationInput).toHaveAccessibleDescription('Total: 1 hour');
  136. await setProfileDuration('-50');
  137. expect(profileDurationInput).toHaveValue('50');
  138. expect(profileDurationInput).toHaveAccessibleDescription('Total: 50 hours');
  139. await setProfileDuration(`${maxValue + 5}`);
  140. expect(profileDurationInput).toHaveValue('10000');
  141. expect(profileDurationInput).toHaveAccessibleDescription('Total: 10,000 hours');
  142. await setProfileDuration('10,');
  143. expect(profileDurationInput).toHaveValue('10');
  144. expect(profileDurationInput).toHaveAccessibleDescription('Total: 10 hours');
  145. await setProfileDuration('5.');
  146. expect(profileDurationInput).toHaveValue('5');
  147. expect(profileDurationInput).toHaveAccessibleDescription('Total: 5 hours');
  148. });
  149. it('disables confirm button when no number is entered', function () {
  150. triggerGiftModal();
  151. renderGlobalModal();
  152. expect(screen.getByTestId('confirm-button')).toBeDisabled();
  153. });
  154. });
  155. describe('Replays', function () {
  156. const triggerGiftModal = () => {
  157. openAdminConfirmModal({
  158. renderModalSpecificContent: deps => (
  159. <AddGiftEventsAction
  160. subscription={mockSub}
  161. dataCategory={DataCategory.REPLAYS}
  162. {...deps}
  163. />
  164. ),
  165. });
  166. };
  167. function getReplayInput() {
  168. return screen.getByRole('textbox', {
  169. name: 'How many replays? (50 is 50 replays)',
  170. });
  171. }
  172. async function setNumReplays(numReplays: string) {
  173. await userEvent.clear(getReplayInput());
  174. await userEvent.type(getReplayInput(), numReplays);
  175. }
  176. it('has valid replay input', async function () {
  177. const maxValue = MAX_ADMIN_CATEGORY_GIFTS[DataCategory.REPLAYS];
  178. triggerGiftModal();
  179. renderGlobalModal();
  180. const replayInput = getReplayInput();
  181. await setNumReplays('1');
  182. expect(replayInput).toHaveValue('1');
  183. expect(replayInput).toHaveAccessibleDescription('Total: 1');
  184. await setNumReplays('-50');
  185. expect(replayInput).toHaveValue('50');
  186. expect(replayInput).toHaveAccessibleDescription('Total: 50');
  187. await setNumReplays(`${maxValue + 5}`);
  188. expect(replayInput).toHaveValue('1000000');
  189. expect(replayInput).toHaveAccessibleDescription('Total: 1,000,000');
  190. await setNumReplays('10,');
  191. expect(replayInput).toHaveValue('10');
  192. expect(replayInput).toHaveAccessibleDescription('Total: 10');
  193. await setNumReplays('5.');
  194. expect(replayInput).toHaveValue('5');
  195. expect(replayInput).toHaveAccessibleDescription('Total: 5');
  196. });
  197. it('disables confirm button when no number is entered', function () {
  198. triggerGiftModal();
  199. renderGlobalModal();
  200. expect(screen.getByTestId('confirm-button')).toBeDisabled();
  201. });
  202. });
  203. describe('Monitors', function () {
  204. const triggerGiftModal = () => {
  205. openAdminConfirmModal({
  206. renderModalSpecificContent: deps => (
  207. <AddGiftEventsAction
  208. subscription={mockSub}
  209. dataCategory={DataCategory.MONITOR_SEATS}
  210. {...deps}
  211. />
  212. ),
  213. });
  214. };
  215. function getMonitorInput() {
  216. return screen.getByRole('textbox', {
  217. name: 'How many cron monitors? (50 is 50 cron monitors)',
  218. });
  219. }
  220. async function setNumMonitors(numMonitors: string) {
  221. await userEvent.clear(getMonitorInput());
  222. await userEvent.type(getMonitorInput(), numMonitors);
  223. }
  224. it('has valid monitor input', async function () {
  225. const maxValue = MAX_ADMIN_CATEGORY_GIFTS[DataCategory.MONITOR_SEATS];
  226. triggerGiftModal();
  227. renderGlobalModal();
  228. const monitorInput = getMonitorInput();
  229. await setNumMonitors('1');
  230. expect(monitorInput).toHaveValue('1');
  231. expect(monitorInput).toHaveAccessibleDescription('Total: 1');
  232. await setNumMonitors('-50');
  233. expect(monitorInput).toHaveValue('50');
  234. expect(monitorInput).toHaveAccessibleDescription('Total: 50');
  235. await setNumMonitors(`${maxValue + 5}`);
  236. expect(monitorInput).toHaveValue('10000');
  237. expect(monitorInput).toHaveAccessibleDescription('Total: 10,000');
  238. await setNumMonitors('10,');
  239. expect(monitorInput).toHaveValue('10');
  240. expect(monitorInput).toHaveAccessibleDescription('Total: 10');
  241. await setNumMonitors('5.');
  242. expect(monitorInput).toHaveValue('5');
  243. expect(monitorInput).toHaveAccessibleDescription('Total: 5');
  244. });
  245. it('disables confirm button when no number is entered', function () {
  246. triggerGiftModal();
  247. renderGlobalModal();
  248. expect(screen.getByTestId('confirm-button')).toBeDisabled();
  249. });
  250. });
  251. describe('Uptime Monitors', function () {
  252. const triggerGiftModal = () => {
  253. openAdminConfirmModal({
  254. renderModalSpecificContent: deps => (
  255. <AddGiftEventsAction
  256. subscription={mockSub}
  257. dataCategory={DataCategory.UPTIME}
  258. {...deps}
  259. />
  260. ),
  261. });
  262. };
  263. function getMonitorInput() {
  264. return screen.getByRole('textbox', {
  265. name: 'How many uptime monitors? (50 is 50 uptime monitors)',
  266. });
  267. }
  268. async function setNumMonitors(numMonitors: string) {
  269. await userEvent.clear(getMonitorInput());
  270. await userEvent.type(getMonitorInput(), numMonitors);
  271. }
  272. it('has valid monitor input', async function () {
  273. const maxValue = MAX_ADMIN_CATEGORY_GIFTS[DataCategory.UPTIME];
  274. triggerGiftModal();
  275. renderGlobalModal();
  276. const monitorInput = getMonitorInput();
  277. await setNumMonitors('1');
  278. expect(monitorInput).toHaveValue('1');
  279. expect(monitorInput).toHaveAccessibleDescription('Total: 1');
  280. await setNumMonitors('-50');
  281. expect(monitorInput).toHaveValue('50');
  282. expect(monitorInput).toHaveAccessibleDescription('Total: 50');
  283. await setNumMonitors(`${maxValue + 5}`);
  284. expect(monitorInput).toHaveValue('10000');
  285. expect(monitorInput).toHaveAccessibleDescription('Total: 10,000');
  286. await setNumMonitors('10,');
  287. expect(monitorInput).toHaveValue('10');
  288. expect(monitorInput).toHaveAccessibleDescription('Total: 10');
  289. await setNumMonitors('5.');
  290. expect(monitorInput).toHaveValue('5');
  291. expect(monitorInput).toHaveAccessibleDescription('Total: 5');
  292. });
  293. it('disables confirm button when no number is entered', function () {
  294. triggerGiftModal();
  295. renderGlobalModal();
  296. expect(screen.getByTestId('confirm-button')).toBeDisabled();
  297. });
  298. });
  299. });