organizationRateLimits.spec.tsx 2.8 KB

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