withSentryAppComponents.spec.jsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. it('handles components without a type', function () {
  9. const MyComponent = () => null;
  10. const Container = withSentryAppComponents(MyComponent);
  11. const wrapper = mountWithTheme(<Container />);
  12. expect(wrapper.find('MyComponent').prop('components')).toEqual([]);
  13. SentryAppComponentsStore.loadComponents([
  14. {type: 'some-type'},
  15. {type: 'another-type'},
  16. ]);
  17. wrapper.update();
  18. expect(wrapper.find('MyComponent').prop('components')).toEqual([
  19. {type: 'some-type'},
  20. {type: 'another-type'},
  21. ]);
  22. });
  23. it('handles components of a certain type', function () {
  24. const MyComponent = () => null;
  25. const Container = withSentryAppComponents(MyComponent, {componentType: 'some-type'});
  26. const wrapper = mountWithTheme(<Container />);
  27. expect(wrapper.find('MyComponent').prop('components')).toEqual([]);
  28. SentryAppComponentsStore.loadComponents([
  29. {type: 'some-type'},
  30. {type: 'another-type'},
  31. ]);
  32. wrapper.update();
  33. expect(wrapper.find('MyComponent').prop('components')).toEqual([{type: 'some-type'}]);
  34. });
  35. });