import { render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import { expect, test, vi } from 'vitest' import { Button } from '../Button' import { PageTitle } from '../PageTitle' import { TextField } from '../TextField' import { ShareCode } from '../ShareCode' import { Notice } from '../Notice' test('busy button is disabled and announces busy', () => { render() const b = screen.getByRole('button', { name: 'Сохранить' }) expect(b).toBeDisabled() expect(b).toHaveAttribute('aria-busy', 'true') }) test('text field links label and error', () => { render() const input = screen.getByLabelText('Почта') expect(input).toHaveAttribute('aria-invalid', 'true') expect(input).toHaveAccessibleDescription('Введи почту') }) test('share code copies to clipboard and confirms', async () => { const user = userEvent.setup() const writeText = vi.spyOn(navigator.clipboard, 'writeText').mockResolvedValue() render() expect(screen.getByText('7KQ3M9XA')).toBeInTheDocument() await user.click(screen.getByRole('button', { name: 'Скопировать' })) expect(writeText).toHaveBeenCalledWith('7KQ3M9XA') expect(await screen.findByText('Скопировано')).toBeInTheDocument() }) test('error notice is an alert', () => { render(Неверный код) expect(screen.getByRole('alert')).toHaveTextContent('Неверный код') }) test('page title renders one h1 with an optional lead', () => { render( Мои конфиги, ) expect(screen.getByRole('heading', { level: 1, name: 'Мои конфиги' })).toBeInTheDocument() expect(screen.getByText('Короткое описание')).toBeInTheDocument() })