Files
Genarrative/src/components/common/CopyCodeButton.test.tsx
T
kdletters 1ad25e30f8 收口前端平台组件库能力
新增 PlatformUiKit 通用弹窗、按钮、状态、空态、媒体、表单和标签等公共组件
迁移结果页、创作工作台、认证入口、RPG 暗色面板和运行态弹窗的重复 UI chrome
补充组件测试、页面回归测试、技术文档和 Hermes 共享决策记录
2026-06-10 10:24:18 +08:00

74 lines
2.1 KiB
TypeScript

/* @vitest-environment jsdom */
import { render, screen } from '@testing-library/react';
import { expect, test } from 'vitest';
import { CopyCodeButton } from './CopyCodeButton';
test('renders public work code with default accessible copy label', () => {
render(
<CopyCodeButton
state="idle"
code="PZ-001"
className="code-chip"
codeClassName="code-value"
/>,
);
const button = screen.getByRole('button', { name: '复制作品号 PZ-001' });
expect(button.className).toContain('code-chip');
expect(button.getAttribute('title')).toBe('复制作品号');
expect(screen.getByText('作品号')).toBeTruthy();
expect(screen.getByText('PZ-001').className).toContain('code-value');
});
test('renders copied and failed suffixes without business-side fragments', () => {
const { rerender } = render(<CopyCodeButton state="copied" code="CW-001" />);
expect(screen.getByText('已复制')).toBeTruthy();
rerender(<CopyCodeButton state="failed" code="CW-001" />);
expect(screen.getByText('复制失败')).toBeTruthy();
});
test('supports compact code-only chips', () => {
render(
<CopyCodeButton
state="copied"
code="PZ-001"
codeLabel={null}
showIcon={false}
accessibleLabel="复制作品号 PZ-001"
title="复制作品号"
/>,
);
const button = screen.getByRole('button', { name: '复制作品号 PZ-001' });
expect(button.textContent).toBe('PZ-001已复制');
expect(button.querySelector('svg')).toBeNull();
expect(button.getAttribute('title')).toBe('复制作品号');
});
test('can opt into shared pill action chrome for short codes', () => {
render(
<CopyCodeButton
state="idle"
code="RPG-001"
actionAppearance="pill"
actionPillSize="xxs"
className="tracking-[0.18em]"
/>,
);
const button = screen.getByRole('button', { name: '复制作品号 RPG-001' });
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');
});