index.spec.tsx 1.5 KB

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