// @vitest-environment jsdom import '@testing-library/jest-dom/vitest'; import { render, screen } from '@testing-library/react'; import { describe, expect, it } from 'vitest'; import { RedditUsernameLink } from '../../apps/dashboard/src/components/reddit-username-link.js'; import { RedditUserText } from '../../apps/dashboard/src/components/reddit-user-text.js'; describe('RedditUsernameLink', () => { it('normalizes a username and opens its Reddit profile in a new tab', () => { render(); expect(screen.getByRole('link', { name: 'u/example user' })).toHaveAttribute( 'href', 'https://www.reddit.com/u/example%20user', ); expect(screen.getByRole('link', { name: 'u/example user' })).toHaveAttribute('target', '_blank'); expect(screen.getByRole('link', { name: 'u/example user' })).toHaveAttribute('rel', 'noreferrer'); }); it('can preserve an existing unprefixed display label', () => { render(); expect(screen.getByRole('link', { name: 'alice' })).toHaveAttribute( 'href', 'https://www.reddit.com/u/alice', ); }); it('never exposes or links an internal t2 identity', () => { const view = render(); expect(view.container).not.toHaveTextContent('t2_private123'); expect(view.container.querySelector('a')).toBeNull(); expect(view.container).toHaveTextContent('Unknown Reddit user'); }); it('links username mentions embedded in activity text and redacts raw ids', () => { render(Reply from u/alice after syncing t2_private123); expect(screen.getByRole('link', { name: 'u/alice' })).toHaveAttribute( 'href', 'https://www.reddit.com/u/alice', ); expect(screen.queryByText(/t2_private123/)).not.toBeInTheDocument(); expect(screen.getByText(/after syncing Reddit user/)).toBeInTheDocument(); }); });