organizationRateLimits.spec.jsx 2.6 KB

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