Files
Genarrative/src/components/common/PlatformNavigableListItem.test.tsx
T
kdletters de0f0c1399 继续收口首页可导航扁平行
新增 PlatformNavigableListItem 统一 desktop flat row 的交互骨架
接入首页搜索结果与桌面最近作品最近浏览入口
补充组件测试首页回归测试并更新收口计划和共享决策记录
2026-06-11 03:13:00 +08:00

49 lines
1.6 KiB
TypeScript

/* @vitest-environment jsdom */
import { fireEvent, render, screen } from '@testing-library/react';
import { describe, expect, test, vi } from 'vitest';
import { PlatformNavigableListItem } from './PlatformNavigableListItem';
describe('PlatformNavigableListItem', () => {
test('renders shared navigable row structure with leading and trailing slots', () => {
render(
<PlatformNavigableListItem
align="start"
leading={<span data-testid="leading">L</span>}
trailing={<span data-testid="trailing">R</span>}
>
<span>行内容</span>
</PlatformNavigableListItem>,
);
const button = screen.getByRole('button', { name: /L\s+行内容\s+R/u });
expect(button.className).toContain('platform-navigable-list-item');
expect(button.className).toContain('items-start');
expect(button.className).toContain('gap-4');
expect(screen.getByTestId('leading').parentElement?.className).toContain(
'platform-navigable-list-item__leading',
);
expect(screen.getByTestId('trailing').parentElement?.className).toContain(
'platform-navigable-list-item__trailing',
);
});
test('defaults to type button and forwards click handlers', () => {
const onClick = vi.fn();
render(
<PlatformNavigableListItem onClick={onClick}>
<span>打开详情</span>
</PlatformNavigableListItem>,
);
const button = screen.getByRole('button', { name: '打开详情' });
expect(button.getAttribute('type')).toBe('button');
fireEvent.click(button);
expect(onClick).toHaveBeenCalledTimes(1);
});
});