|
@@ -94,30 +94,8 @@ jest.mock('@/components/ui/carousel', () => ({
|
|
|
)
|
|
)
|
|
|
}))
|
|
}))
|
|
|
|
|
|
|
|
-// Mock GoodsSpecSelector组件
|
|
|
|
|
-jest.mock('@/components/goods-spec-selector', () => ({
|
|
|
|
|
- GoodsSpecSelector: ({ visible, onClose, onConfirm, parentGoodsId, currentSpec, currentQuantity }: any) => {
|
|
|
|
|
- if (!visible) return null
|
|
|
|
|
- return (
|
|
|
|
|
- <div className="spec-modal" data-testid="spec-modal">
|
|
|
|
|
- <div className="spec-modal-content">
|
|
|
|
|
- <div className="spec-modal-header">
|
|
|
|
|
- <span>选择规格</span>
|
|
|
|
|
- <div className="spec-modal-close" onClick={onClose}>×</div>
|
|
|
|
|
- </div>
|
|
|
|
|
- <div className="spec-options">
|
|
|
|
|
- <div className="spec-option" data-testid="spec-option-red" onClick={() => onConfirm({ id: 101, name: '红色款', price: 299, stock: 50 }, 1)}>
|
|
|
|
|
- 红色款
|
|
|
|
|
- </div>
|
|
|
|
|
- <div className="spec-option" data-testid="spec-option-blue" onClick={() => onConfirm({ id: 102, name: '蓝色款', price: 319, stock: 30 }, 1)}>
|
|
|
|
|
- 蓝色款
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
-}))
|
|
|
|
|
|
|
+// 使用真实的GoodsSpecSelector组件,不模拟
|
|
|
|
|
+// jest.mock('@/components/goods-spec-selector', () => ({ ... })) 已移除
|
|
|
|
|
|
|
|
const createTestQueryClient = () => new QueryClient({
|
|
const createTestQueryClient = () => new QueryClient({
|
|
|
defaultOptions: {
|
|
defaultOptions: {
|
|
@@ -228,10 +206,13 @@ describe('GoodsDetailPage集成测试', () => {
|
|
|
const specButton = screen.getByText('选择规格')
|
|
const specButton = screen.getByText('选择规格')
|
|
|
fireEvent.click(specButton)
|
|
fireEvent.click(specButton)
|
|
|
|
|
|
|
|
- // 验证规格选择弹窗显示
|
|
|
|
|
- expect(screen.getByTestId('spec-modal')).toBeInTheDocument()
|
|
|
|
|
- expect(screen.getByTestId('spec-option-red')).toBeInTheDocument()
|
|
|
|
|
- expect(screen.getByTestId('spec-option-blue')).toBeInTheDocument()
|
|
|
|
|
|
|
+ // 验证规格选择弹窗显示 - 使用真实组件的类名和文本
|
|
|
|
|
+ // 等待组件加载完成(API mock立即返回数据)
|
|
|
|
|
+ await waitFor(() => {
|
|
|
|
|
+ expect(screen.getByText('选择规格')).toBeInTheDocument()
|
|
|
|
|
+ })
|
|
|
|
|
+ expect(screen.getByText('红色款')).toBeInTheDocument()
|
|
|
|
|
+ expect(screen.getByText('蓝色款')).toBeInTheDocument()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('选择规格后更新显示', async () => {
|
|
it('选择规格后更新显示', async () => {
|