From e800d97d33632dd8934b7d118f629a5b0e9d9101 Mon Sep 17 00:00:00 2001 From: Soldatova-Kristina Date: Tue, 9 Jun 2026 14:09:24 -0300 Subject: [PATCH] YH-2077: add test for AuthorInfo --- src/shared/ui/AuthorInfo/AuthorInfo.test.tsx | 66 ++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/shared/ui/AuthorInfo/AuthorInfo.test.tsx diff --git a/src/shared/ui/AuthorInfo/AuthorInfo.test.tsx b/src/shared/ui/AuthorInfo/AuthorInfo.test.tsx new file mode 100644 index 000000000..fdd053be8 --- /dev/null +++ b/src/shared/ui/AuthorInfo/AuthorInfo.test.tsx @@ -0,0 +1,66 @@ +import { screen } from '@testing-library/react'; + +import { Translation } from '@/shared/config'; +import { renderComponent } from '@/shared/libs'; + +import { AuthorInfo, Author } from './AuthorInfo'; + +type OverrideProps = { + createdBy?: Author; + isCenter?: boolean; +}; + +const defaultAuthor: Author = { + id: '123', + username: 'john_doe', +}; + +const renderAuthorInfo = (props: OverrideProps = {}, route = '/') => { + const { createdBy = defaultAuthor, ...rest } = props; + + renderComponent(, { route }); +}; + +describe('AuthorInfo', () => { + describe('Rendering', () => { + test('renders author label', () => { + renderAuthorInfo(); + + expect(screen.getByText(`${Translation.AUTHOR}:`)).toBeInTheDocument(); + }); + + test('renders username', () => { + renderAuthorInfo(); + + expect(screen.getByText(defaultAuthor.username)).toBeInTheDocument(); + }); + + test('renders with justify start by default', () => { + renderAuthorInfo(); + expect(screen.getByTestId('Flex')).not.toHaveClass('justify-center'); + }); + + test('renders with justify center when isCenter is true', () => { + renderAuthorInfo({ isCenter: true }); + expect(screen.getByTestId('Flex')).toHaveClass('justify-center'); + }); + }); + + describe('Navigation', () => { + test('renders admin user link when project is admin', () => { + renderAuthorInfo({}, '/admin'); + + const link = screen.getByRole('link', { name: defaultAuthor.username }); + + expect(link).toHaveAttribute('href', `/admin/users/${defaultAuthor.id}`); + }); + + test('renders platform user link when project is platform', () => { + renderAuthorInfo({}, '/'); + + const link = screen.getByRole('link', { name: defaultAuthor.username }); + + expect(link).toHaveAttribute('href', `/users/${defaultAuthor.id}`); + }); + }); +});