organizationRateLimits.spec.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. const {container} = renderComponent({organization: org});
  41. expect(screen.getByRole('slider')).toBeInTheDocument();
  42. expect(container).toSnapshot();
  43. });
  44. it('can change Account Rate Limit', async function () {
  45. const mock = MockApiClient.addMockResponse({
  46. url: ENDPOINT,
  47. method: 'PUT',
  48. statusCode: 200,
  49. });
  50. renderComponent();
  51. expect(mock).not.toHaveBeenCalled();
  52. // Change Account Limit
  53. screen.getByRole('slider', {name: 'Account Limit'}).focus();
  54. await userEvent.keyboard('{ArrowLeft>5}');
  55. await userEvent.tab();
  56. expect(mock).toHaveBeenCalledWith(
  57. ENDPOINT,
  58. expect.objectContaining({
  59. method: 'PUT',
  60. data: {
  61. accountRateLimit: 20000,
  62. },
  63. })
  64. );
  65. });
  66. it('can change Project Rate Limit', async function () {
  67. const mock = MockApiClient.addMockResponse({
  68. url: ENDPOINT,
  69. method: 'PUT',
  70. statusCode: 200,
  71. });
  72. renderComponent();
  73. expect(mock).not.toHaveBeenCalled();
  74. // Change Project Rate Limit
  75. screen.getByRole('slider', {name: 'Per-Project Limit'}).focus();
  76. await userEvent.keyboard('{ArrowRight>5}');
  77. await userEvent.tab();
  78. expect(mock).toHaveBeenCalledWith(
  79. ENDPOINT,
  80. expect.objectContaining({
  81. method: 'PUT',
  82. data: {
  83. projectRateLimit: 100,
  84. },
  85. })
  86. );
  87. });
  88. });