index.spec.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {TeamFixture} from 'sentry-fixture/team';
  4. import {UserFixture} from 'sentry-fixture/user';
  5. import {render, screen} from 'sentry-test/reactTestingLibrary';
  6. import IdBadge from 'sentry/components/idBadge';
  7. describe('IdBadge', function () {
  8. it('renders the correct component when `user` property is passed', function () {
  9. const user = UserFixture();
  10. render(<IdBadge user={user} />);
  11. expect(screen.getByTestId('letter_avatar-avatar')).toHaveTextContent('FB');
  12. expect(screen.getByText(user.email)).toBeInTheDocument();
  13. });
  14. it('renders the correct component when `team` property is passed', function () {
  15. render(<IdBadge team={TeamFixture()} />);
  16. expect(screen.getByTestId('letter_avatar-avatar')).toHaveTextContent('TS');
  17. expect(screen.getByTestId('badge-display-name')).toHaveTextContent('#team-slug');
  18. });
  19. it('renders the correct component when `project` property is passed', function () {
  20. render(<IdBadge project={ProjectFixture()} />);
  21. expect(screen.getByTestId('badge-display-name')).toHaveTextContent('project-slug');
  22. });
  23. it('renders the correct component when `organization` property is passed', function () {
  24. render(<IdBadge organization={OrganizationFixture()} />);
  25. expect(screen.getByTestId('default-avatar')).toHaveTextContent('OS');
  26. expect(screen.getByTestId('badge-display-name')).toHaveTextContent('org-slug');
  27. });
  28. it('throws when no valid properties are passed', function () {
  29. // Error is expected, do not fail when calling console.error
  30. jest.spyOn(console, 'error').mockImplementation();
  31. expect(() => render(<IdBadge />)).toThrow();
  32. });
  33. });