withSentryAppComponents.spec.jsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import React from 'react';
  2. import {mount} from 'enzyme';
  3. import SentryAppComponentsStore from 'app/stores/sentryAppComponentsStore';
  4. import withSentryAppComponents from 'app/utils/withSentryAppComponents';
  5. describe('withSentryAppComponents HoC', function() {
  6. beforeEach(() => {
  7. SentryAppComponentsStore.init();
  8. });
  9. it('handles components without a type', function() {
  10. const MyComponent = () => null;
  11. const Container = withSentryAppComponents(MyComponent);
  12. const wrapper = mount(<Container />);
  13. expect(wrapper.find('MyComponent').prop('components')).toEqual([]);
  14. SentryAppComponentsStore.onLoadComponents([
  15. {type: 'some-type'},
  16. {type: 'another-type'},
  17. ]);
  18. wrapper.update();
  19. expect(wrapper.find('MyComponent').prop('components')).toEqual([
  20. {type: 'some-type'},
  21. {type: 'another-type'},
  22. ]);
  23. });
  24. it('handles components of a certain type', function() {
  25. const MyComponent = () => null;
  26. const Container = withSentryAppComponents(MyComponent, {componentType: 'some-type'});
  27. const wrapper = mount(<Container />);
  28. expect(wrapper.find('MyComponent').prop('components')).toEqual([]);
  29. SentryAppComponentsStore.onLoadComponents([
  30. {type: 'some-type'},
  31. {type: 'another-type'},
  32. ]);
  33. wrapper.update();
  34. expect(wrapper.find('MyComponent').prop('components')).toEqual([{type: 'some-type'}]);
  35. });
  36. });