import { cleanup, render, screen } from '@testing-library/react'; import { beforeEach, describe, expect, it } from 'vitest'; import AuthErrorAlert from './AuthErrorAlert'; import AuthPageShell from './AuthPageShell'; import AuthSubmitButton from './AuthSubmitButton'; describe('AuthPageShell', () => { beforeEach(() => { cleanup(); }); it('renders the logo, tagline and children', () => { render(

Shell content

, ); expect(screen.getByAltText('daylog')).toBeInTheDocument(); expect(screen.getByText('The home for your ideas')).toBeInTheDocument(); expect(screen.getByText('Shell content')).toBeInTheDocument(); }); it('omits the tagline when not provided', () => { render(

Shell content

, ); expect(screen.queryByText('The home for your ideas')).toBeNull(); }); it('wraps the logo in a link when logoHref is provided', () => { render(

Shell content

, ); expect(screen.getByRole('link')).toHaveAttribute('href', '/'); }); }); describe('AuthErrorAlert', () => { beforeEach(() => { cleanup(); }); it('renders the title and message', () => { render(); expect(screen.getByText('Login failed')).toBeInTheDocument(); expect(screen.getByText('Bad credentials')).toBeInTheDocument(); }); it('renders nothing without a message', () => { const { container } = render(); expect(container).toBeEmptyDOMElement(); }); }); describe('AuthSubmitButton', () => { beforeEach(() => { cleanup(); }); it('shows the label when not pending', () => { render( , ); const button = screen.getByRole('button', { name: 'Save' }); expect(button).toBeEnabled(); expect(button).toHaveAttribute('type', 'submit'); }); it('shows the pending label and disables the button when pending', () => { render( , ); const button = screen.getByRole('button'); expect(button).toBeDisabled(); expect(screen.getByText('Saving...')).toBeInTheDocument(); }); });