withSentryAppComponents.spec.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import {act, 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. act(() =>
  15. SentryAppComponentsStore.loadComponents([
  16. {
  17. type: 'issue-link',
  18. sentryApp: {uuid: 'uuid', name: '', slug: '', avatars: []},
  19. uuid: '',
  20. schema: {uri: '', url: '', type: 'stacktrace-link'},
  21. },
  22. {
  23. type: 'stacktrace-link',
  24. sentryApp: {uuid: 'uuid', name: '', slug: '', avatars: []},
  25. uuid: '',
  26. schema: {uri: '', url: '', type: 'stacktrace-link'},
  27. },
  28. ])
  29. );
  30. expect(MyComponent).toHaveBeenCalledWith(
  31. {
  32. components: [
  33. expect.objectContaining({type: 'issue-link'}),
  34. expect.objectContaining({type: 'stacktrace-link'}),
  35. ],
  36. },
  37. {}
  38. );
  39. });
  40. it('handles components of a certain type', function () {
  41. const MyComponent = jest.fn(() => null);
  42. const Container = withSentryAppComponents(MyComponent, {
  43. componentType: 'issue-link',
  44. });
  45. render(<Container />);
  46. expect(MyComponent).toHaveBeenCalledWith({components: []}, {});
  47. act(() =>
  48. SentryAppComponentsStore.loadComponents([
  49. {
  50. type: 'issue-link',
  51. sentryApp: {uuid: 'uuid', name: '', slug: '', avatars: []},
  52. uuid: '',
  53. schema: {uri: '', url: '', type: 'stacktrace-link'},
  54. },
  55. {
  56. type: 'stacktrace-link',
  57. sentryApp: {uuid: 'uuid', name: '', slug: '', avatars: []},
  58. uuid: '',
  59. schema: {uri: '', url: '', type: 'stacktrace-link'},
  60. },
  61. ])
  62. );
  63. expect(MyComponent).toHaveBeenCalledWith(
  64. {
  65. components: [
  66. {
  67. type: 'issue-link',
  68. sentryApp: {uuid: 'uuid', name: '', slug: '', avatars: []},
  69. uuid: '',
  70. schema: {uri: '', url: '', type: 'stacktrace-link'},
  71. },
  72. ],
  73. },
  74. {}
  75. );
  76. });
  77. });