94122583ac
新增 PlatformAsyncStatePanel 统一 profile 异步状态骨架 扩展 PlatformSegmentedTabs 支持滚动 tab 并接入创作入口与发现页 统一 PixelCloseButton 复用 PlatformModalCloseButton 像素关闭能力 抽取平台入口泥点前置提示弹层并收紧阻断语义 补充组件收口文档与共享决策记录
62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
/* @vitest-environment jsdom */
|
|
|
|
import { render, screen } from '@testing-library/react';
|
|
import { describe, expect, test } from 'vitest';
|
|
|
|
import { PlatformAsyncStatePanel } from './PlatformAsyncStatePanel';
|
|
|
|
describe('PlatformAsyncStatePanel', () => {
|
|
test('prefers error state over loading and content', () => {
|
|
render(
|
|
<PlatformAsyncStatePanel
|
|
errorState={<div>出错了</div>}
|
|
isLoading
|
|
loadingState={<div>读取中</div>}
|
|
>
|
|
<div>内容</div>
|
|
</PlatformAsyncStatePanel>,
|
|
);
|
|
|
|
expect(screen.getByText('出错了')).toBeTruthy();
|
|
expect(screen.queryByText('读取中')).toBeNull();
|
|
expect(screen.queryByText('内容')).toBeNull();
|
|
});
|
|
|
|
test('renders loading state before empty state', () => {
|
|
render(
|
|
<PlatformAsyncStatePanel
|
|
isLoading
|
|
isEmpty
|
|
loadingState={<div>读取中</div>}
|
|
emptyState={<div>暂无内容</div>}
|
|
>
|
|
<div>内容</div>
|
|
</PlatformAsyncStatePanel>,
|
|
);
|
|
|
|
expect(screen.getByText('读取中')).toBeTruthy();
|
|
expect(screen.queryByText('暂无内容')).toBeNull();
|
|
});
|
|
|
|
test('renders empty state when requested', () => {
|
|
render(
|
|
<PlatformAsyncStatePanel isEmpty emptyState={<div>暂无内容</div>}>
|
|
<div>内容</div>
|
|
</PlatformAsyncStatePanel>,
|
|
);
|
|
|
|
expect(screen.getByText('暂无内容')).toBeTruthy();
|
|
expect(screen.queryByText('内容')).toBeNull();
|
|
});
|
|
|
|
test('falls back to content when no async state is active', () => {
|
|
render(
|
|
<PlatformAsyncStatePanel>
|
|
<div>内容</div>
|
|
</PlatformAsyncStatePanel>,
|
|
);
|
|
|
|
expect(screen.getByText('内容')).toBeTruthy();
|
|
});
|
|
});
|