organizationRateLimits.spec.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import OrganizationRateLimits, {
  3. OrganizationRateLimitProps,
  4. } from 'sentry/views/settings/organizationRateLimits/organizationRateLimits';
  5. const ENDPOINT = '/organizations/org-slug/';
  6. describe('Organization Rate Limits', function () {
  7. const organization = {
  8. ...TestStubs.Organization(),
  9. quota: {
  10. projectLimit: 75,
  11. accountLimit: 70000,
  12. },
  13. };
  14. const renderComponent = (props?: Partial<OrganizationRateLimitProps>) =>
  15. render(
  16. <OrganizationRateLimits
  17. {...TestStubs.routeComponentProps()}
  18. organization={organization}
  19. {...props}
  20. />
  21. );
  22. beforeEach(function () {
  23. MockApiClient.clearMockResponses();
  24. });
  25. it('renders with initialData', function () {
  26. renderComponent();
  27. // XXX: Slider input values are associated to their step value
  28. // Step 16 is 70000
  29. expect(screen.getByRole('slider', {name: 'Account Limit'})).toHaveValue('16');
  30. expect(screen.getByRole('slider', {name: 'Per-Project Limit'})).toHaveValue('75');
  31. });
  32. it('renders with maxRate and maxRateInterval set', function () {
  33. const org = {
  34. ...organization,
  35. quota: {
  36. maxRate: 100,
  37. maxRateInterval: 60,
  38. },
  39. };
  40. renderComponent({organization: org});
  41. expect(screen.getByRole('slider')).toBeInTheDocument();
  42. });
  43. it('can change Account Rate Limit', async function () {
  44. const mock = MockApiClient.addMockResponse({
  45. url: ENDPOINT,
  46. method: 'PUT',
  47. statusCode: 200,
  48. });
  49. renderComponent();
  50. expect(mock).not.toHaveBeenCalled();
  51. // Change Account Limit
  52. screen.getByRole('slider', {name: 'Account Limit'}).focus();
  53. await userEvent.keyboard('{ArrowLeft>5}');
  54. await userEvent.tab();
  55. expect(mock).toHaveBeenCalledWith(
  56. ENDPOINT,
  57. expect.objectContaining({
  58. method: 'PUT',
  59. data: {
  60. accountRateLimit: 20000,
  61. },
  62. })
  63. );
  64. });
  65. it('can change Project Rate Limit', async function () {
  66. const mock = MockApiClient.addMockResponse({
  67. url: ENDPOINT,
  68. method: 'PUT',
  69. statusCode: 200,
  70. });
  71. renderComponent();
  72. expect(mock).not.toHaveBeenCalled();
  73. // Change Project Rate Limit
  74. screen.getByRole('slider', {name: 'Per-Project Limit'}).focus();
  75. await userEvent.keyboard('{ArrowRight>5}');
  76. await userEvent.tab();
  77. expect(mock).toHaveBeenCalledWith(
  78. ENDPOINT,
  79. expect.objectContaining({
  80. method: 'PUT',
  81. data: {
  82. projectRateLimit: 100,
  83. },
  84. })
  85. );
  86. });
  87. });