organizationRateLimits.spec.jsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {Client} from 'sentry/api';
  3. import OrganizationRateLimits from 'sentry/views/settings/organizationRateLimits/organizationRateLimits';
  4. const ENDPOINT = '/organizations/org-slug/';
  5. describe('Organization Rate Limits', function () {
  6. const organization = {
  7. ...TestStubs.Organization(),
  8. quota: {
  9. projectLimit: 75,
  10. accountLimit: 70000,
  11. },
  12. };
  13. const creator = props => (
  14. <OrganizationRateLimits organization={organization} {...props} />
  15. );
  16. beforeEach(function () {
  17. Client.clearMockResponses();
  18. });
  19. it('renders with initialData', function () {
  20. const wrapper = mountWithTheme(creator());
  21. expect(wrapper.find("RangeSlider[name='accountRateLimit']").prop('value')).toBe(
  22. 70000
  23. );
  24. expect(wrapper.find("RangeSlider[name='projectRateLimit']").prop('value')).toBe(75);
  25. });
  26. it('renders with maxRate and maxRateInterval set', function () {
  27. const org = {
  28. ...organization,
  29. quota: {
  30. maxRate: 100,
  31. maxRateInterval: 60,
  32. },
  33. };
  34. const wrapper = mountWithTheme(creator({organization: org}));
  35. expect(wrapper.find('RangeSlider')).toHaveLength(1);
  36. expect(wrapper.find('Form TextBlock')).toSnapshot();
  37. });
  38. it('can change Account Rate Limit', function () {
  39. const mock = Client.addMockResponse({
  40. url: ENDPOINT,
  41. method: 'PUT',
  42. statusCode: 200,
  43. });
  44. const wrapper = mountWithTheme(creator());
  45. expect(mock).not.toHaveBeenCalled();
  46. // Change Account Limit
  47. // Remember value needs to be an index of allowedValues for account limit
  48. wrapper
  49. .find('RangeSlider Slider')
  50. .first()
  51. .simulate('input', {target: {value: 11}})
  52. .simulate('mouseUp', {target: {value: 11}});
  53. expect(mock).toHaveBeenCalledWith(
  54. ENDPOINT,
  55. expect.objectContaining({
  56. method: 'PUT',
  57. data: {
  58. accountRateLimit: 20000,
  59. },
  60. })
  61. );
  62. });
  63. it('can change Project Rate Limit', function () {
  64. const mock = Client.addMockResponse({
  65. url: ENDPOINT,
  66. method: 'PUT',
  67. statusCode: 200,
  68. });
  69. const wrapper = mountWithTheme(creator());
  70. expect(mock).not.toHaveBeenCalled();
  71. // Change Project Rate Limit
  72. wrapper
  73. .find('RangeSlider Slider')
  74. .at(1)
  75. .simulate('input', {target: {value: 100}})
  76. .simulate('mouseUp', {target: {value: 100}});
  77. expect(mock).toHaveBeenCalledWith(
  78. ENDPOINT,
  79. expect.objectContaining({
  80. method: 'PUT',
  81. data: {
  82. projectRateLimit: 100,
  83. },
  84. })
  85. );
  86. });
  87. });