organizationRateLimits.spec.jsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import {mount} from 'enzyme';
  2. import React from 'react';
  3. import {Client} from 'app/api';
  4. import OrganizationRateLimits from 'app/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 creator = props => (
  15. <OrganizationRateLimits organization={organization} {...props} />
  16. );
  17. beforeEach(function() {
  18. Client.clearMockResponses();
  19. });
  20. it('renders with initialData', function() {
  21. const wrapper = mount(creator(), TestStubs.routerContext());
  22. expect(
  23. wrapper
  24. .find('RangeSlider')
  25. .first()
  26. .prop('value')
  27. ).toBe(70000);
  28. expect(
  29. wrapper
  30. .find('RangeSlider')
  31. .at(1)
  32. .prop('value')
  33. ).toBe(75);
  34. });
  35. it('renders with maxRate and maxRateInterval set', function() {
  36. const org = {
  37. ...organization,
  38. quota: {
  39. maxRate: 100,
  40. maxRateInterval: 60,
  41. },
  42. };
  43. const wrapper = mount(creator({organization: org}), TestStubs.routerContext());
  44. expect(wrapper.find('RangeSlider')).toHaveLength(1);
  45. expect(wrapper.find('Form TextBlock')).toMatchSnapshot();
  46. });
  47. it('can change Account Rate Limit', function() {
  48. const mock = Client.addMockResponse({
  49. url: ENDPOINT,
  50. method: 'PUT',
  51. statusCode: 200,
  52. });
  53. const wrapper = mount(creator(), TestStubs.routerContext());
  54. expect(mock).not.toHaveBeenCalled();
  55. // Change Account Limit
  56. // Remember value needs to be an index of allowedValues for account limit
  57. wrapper
  58. .find('RangeSlider Slider')
  59. .first()
  60. .simulate('input', {target: {value: 11}})
  61. .simulate('mouseUp', {target: {value: 11}});
  62. expect(mock).toHaveBeenCalledWith(
  63. ENDPOINT,
  64. expect.objectContaining({
  65. method: 'PUT',
  66. data: {
  67. accountRateLimit: 20000,
  68. },
  69. })
  70. );
  71. });
  72. it('can change Project Rate Limit', function() {
  73. const mock = Client.addMockResponse({
  74. url: ENDPOINT,
  75. method: 'PUT',
  76. statusCode: 200,
  77. });
  78. const wrapper = mount(creator(), TestStubs.routerContext());
  79. expect(mock).not.toHaveBeenCalled();
  80. // Change Project Rate Limit
  81. wrapper
  82. .find('RangeSlider Slider')
  83. .at(1)
  84. .simulate('input', {target: {value: 100}})
  85. .simulate('mouseUp', {target: {value: 100}});
  86. expect(mock).toHaveBeenCalledWith(
  87. ENDPOINT,
  88. expect.objectContaining({
  89. method: 'PUT',
  90. data: {
  91. projectRateLimit: 100,
  92. },
  93. })
  94. );
  95. });
  96. });