withSentryAppComponents.spec.jsx 1.5 KB

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