import {render, screen} from 'sentry-test/reactTestingLibrary';
import UserBadge from 'sentry/components/idBadge/userBadge';
import {AvatarUser} from 'sentry/types';
describe('UserBadge', function () {
const user: AvatarUser = TestStubs.User();
it('renders with no link when user is supplied', function () {
render();
expect(screen.getByText('Foo Bar')).toBeInTheDocument();
expect(screen.getByText('foo@example.com')).toBeInTheDocument();
});
it('can display alternate display names/emails', function () {
render(
);
expect(screen.getByText('Other Display Name')).toBeInTheDocument();
expect(screen.getByText('Other Display Email')).toBeInTheDocument();
});
it('can coalesce using username', function () {
const username = TestStubs.User({
name: null,
email: null,
username: 'the-batman',
});
render();
expect(screen.getByText(username.username)).toBeInTheDocument();
});
it('can coalesce using ipaddress', function () {
const ipUser = TestStubs.User({
name: null,
email: null,
username: null,
ipAddress: '127.0.0.1',
});
render();
expect(screen.getByText(ipUser.ipAddress)).toBeInTheDocument();
});
it('can coalesce using id', function () {
const idUser = TestStubs.User({
id: '99',
name: null,
email: null,
username: null,
ipAddress: null,
});
render();
expect(screen.getByText(idUser.id)).toBeInTheDocument();
});
it('can hide email address', function () {
render();
expect(screen.queryByText(user.email)).not.toBeInTheDocument();
});
});