/* @vitest-environment jsdom */ import { render, screen, within } from '@testing-library/react'; import { expect, test } from 'vitest'; import { CopyFeedbackButton } from './CopyFeedbackButton'; test('renders idle copy label and icon by default', () => { render( , ); const button = screen.getByRole('button', { name: '分享' }); expect(button.className).toContain('platform-button'); expect(within(button).getByText('分享')).toBeTruthy(); expect(button.querySelector('svg')).toBeTruthy(); }); test('switches copied and failed feedback labels', () => { const { rerender } = render( , ); expect(screen.getByRole('button', { name: '作品号已复制' })).toBeTruthy(); rerender( , ); expect(screen.getByRole('button', { name: '作品号复制失败' })).toBeTruthy(); }); test('keeps custom accessible label for compact buttons', () => { render( , ); const button = screen.getByRole('button', { name: '复制作品号 PZ-001' }); expect(button.textContent).toBe('已复制'); expect(button.getAttribute('title')).toBe('复制作品号'); }); test('supports icon-only buttons with feedback labels kept in accessibility', () => { render( , ); const button = screen.getByRole('button', { name: '分享内容已复制' }); expect(button.textContent).toBe(''); expect(button.querySelector('svg')).toBeTruthy(); }); test('allows overriding accessible label without business-side state branches', () => { render( , ); const button = screen.getByRole('button', { name: '分享内容复制失败', }); expect(button.getAttribute('title')).toBe('分享内容复制失败'); }); test('can opt into platform action button chrome', () => { render( , ); const button = screen.getByRole('button', { name: '复制报错' }); expect(button.className).toContain('platform-button--primary'); expect(button.className).toContain('w-full'); expect(button.className).toContain('disabled:cursor-not-allowed'); }); test('can opt into shared pill action chrome', () => { render( , ); const button = screen.getByRole('button', { name: '分享作品' }); expect(button.className).toContain('rounded-full'); expect(button.className).toContain('bg-white/72'); expect(button.className).toContain('text-[10px]'); expect(button.className).toContain('tracking-[0.18em]'); expect(button.className).not.toContain('platform-pill'); });