withSentryAppComponents.spec.jsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import {render} from 'sentry-test/reactTestingLibrary';
  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 = jest.fn(() => null);
  10. const Container = withSentryAppComponents(MyComponent);
  11. render(<Container />);
  12. expect(MyComponent).toHaveBeenCalledWith({components: []}, {});
  13. MyComponent.mockClear();
  14. SentryAppComponentsStore.loadComponents([
  15. {type: 'some-type'},
  16. {type: 'another-type'},
  17. ]);
  18. expect(MyComponent).toHaveBeenCalledWith(
  19. {components: [{type: 'some-type'}, {type: 'another-type'}]},
  20. {}
  21. );
  22. });
  23. it('handles components of a certain type', function () {
  24. const MyComponent = jest.fn(() => null);
  25. const Container = withSentryAppComponents(MyComponent, {componentType: 'some-type'});
  26. render(<Container />);
  27. expect(MyComponent).toHaveBeenCalledWith({components: []}, {});
  28. SentryAppComponentsStore.loadComponents([
  29. {type: 'some-type'},
  30. {type: 'another-type'},
  31. ]);
  32. expect(MyComponent).toHaveBeenCalledWith({components: [{type: 'some-type'}]}, {});
  33. });
  34. });