organizationRateLimits.spec.tsx 2.9 KB

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