hookOrDefault.spec.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import {Organization} from 'sentry-fixture/organization';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import HookStore from 'sentry/stores/hookStore';
  4. import HookOrDefault from './hookOrDefault';
  5. describe('HookOrDefault', () => {
  6. beforeEach(() => {
  7. HookStore.init();
  8. });
  9. it('should render default', () => {
  10. const Component = HookOrDefault({
  11. hookName: 'component:replay-onboarding-cta',
  12. defaultComponent: () => (
  13. <div data-test-id="default-component">Default Component</div>
  14. ),
  15. });
  16. render(<Component organization={Organization()}>Test</Component>);
  17. expect(screen.getByTestId('default-component')).toBeInTheDocument();
  18. expect(screen.getByText('Default Component')).toBeInTheDocument();
  19. });
  20. it('should render from HookStore', () => {
  21. HookStore.add(
  22. 'component:replay-onboarding-cta',
  23. () =>
  24. function ({organization}) {
  25. return <div data-test-id="hook-component">{organization.slug}</div>;
  26. }
  27. );
  28. const Component = HookOrDefault({
  29. hookName: 'component:replay-onboarding-cta',
  30. defaultComponent: () => (
  31. <div data-test-id="default-component">Default Component</div>
  32. ),
  33. });
  34. render(<Component organization={Organization()}>Test</Component>);
  35. expect(screen.getByTestId('hook-component')).toBeInTheDocument();
  36. expect(screen.queryByTestId('default-component')).not.toBeInTheDocument();
  37. expect(screen.getByText('org-slug')).toBeInTheDocument();
  38. });
  39. });