|
|
@@ -15,22 +15,20 @@ const mockCartItems = [
|
|
|
{
|
|
|
id: 1,
|
|
|
parentGoodsId: 100, // 父商品ID
|
|
|
- name: '测试商品1',
|
|
|
+ name: '红色/M', // 子商品规格名称
|
|
|
price: 29.9,
|
|
|
image: 'test-image1.jpg',
|
|
|
stock: 10,
|
|
|
quantity: 2,
|
|
|
- spec: '红色/M',
|
|
|
},
|
|
|
{
|
|
|
id: 2,
|
|
|
parentGoodsId: 200, // 父商品ID
|
|
|
- name: '测试商品2',
|
|
|
+ name: '蓝色/L', // 子商品规格名称
|
|
|
price: 49.9,
|
|
|
image: 'test-image2.jpg',
|
|
|
stock: 2, // 改为2,触发库存不足提示(<=3)
|
|
|
quantity: 1,
|
|
|
- spec: '蓝色/L',
|
|
|
},
|
|
|
]
|
|
|
|
|
|
@@ -38,17 +36,37 @@ const mockCartItems = [
|
|
|
const mockGoodsData = {
|
|
|
1: {
|
|
|
id: 1,
|
|
|
- name: '测试商品1',
|
|
|
+ name: '红色/M', // 子商品规格名称
|
|
|
price: 29.9,
|
|
|
imageFile: { fullUrl: 'test-image1.jpg' },
|
|
|
- stock: 10
|
|
|
+ stock: 10,
|
|
|
+ parent: { // 父商品信息
|
|
|
+ id: 100,
|
|
|
+ name: '测试商品1', // 父商品名称(不含规格)
|
|
|
+ price: 29.9,
|
|
|
+ costPrice: 20,
|
|
|
+ stock: 50,
|
|
|
+ imageFileId: 1,
|
|
|
+ goodsType: 'normal',
|
|
|
+ spuId: 0
|
|
|
+ }
|
|
|
},
|
|
|
2: {
|
|
|
id: 2,
|
|
|
- name: '测试商品2',
|
|
|
+ name: '蓝色/L', // 子商品规格名称
|
|
|
price: 49.9,
|
|
|
imageFile: { fullUrl: 'test-image2.jpg' },
|
|
|
- stock: 3
|
|
|
+ stock: 3,
|
|
|
+ parent: { // 父商品信息
|
|
|
+ id: 200,
|
|
|
+ name: '测试商品2', // 父商品名称(不含规格)
|
|
|
+ price: 49.9,
|
|
|
+ costPrice: 35,
|
|
|
+ stock: 30,
|
|
|
+ imageFileId: 2,
|
|
|
+ goodsType: 'normal',
|
|
|
+ spuId: 0
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -172,10 +190,10 @@ describe('购物车页面', () => {
|
|
|
expect(getByText('¥49.90')).toBeDefined()
|
|
|
})
|
|
|
|
|
|
- it('应该显示商品规格信息', () => {
|
|
|
- const { getByText } = renderWithProviders(<CartPage />)
|
|
|
- expect(getByText('红色/M')).toBeDefined()
|
|
|
- expect(getByText('蓝色/L')).toBeDefined()
|
|
|
+ it('应该显示商品规格信息', async () => {
|
|
|
+ const { findByText } = renderWithProviders(<CartPage />)
|
|
|
+ expect(await findByText('红色/M')).toBeDefined()
|
|
|
+ expect(await findByText('蓝色/L')).toBeDefined()
|
|
|
})
|
|
|
|
|
|
it('应该显示商品数量选择器', () => {
|
|
|
@@ -272,7 +290,6 @@ describe('购物车页面', () => {
|
|
|
image: 'test-image1.jpg',
|
|
|
stock: 10,
|
|
|
quantity: 2,
|
|
|
- spec: '红色/M',
|
|
|
},
|
|
|
{
|
|
|
id: 2,
|
|
|
@@ -282,7 +299,6 @@ describe('购物车页面', () => {
|
|
|
image: 'test-image2.jpg',
|
|
|
stock: 5, // 本地库存5,不触发提示(>3)
|
|
|
quantity: 1,
|
|
|
- spec: '蓝色/L',
|
|
|
},
|
|
|
]
|
|
|
mockGetStorageSync.mockReturnValue({ items: testCartItems })
|
|
|
@@ -411,19 +427,19 @@ describe('购物车页面', () => {
|
|
|
mockRequest.mockClear()
|
|
|
})
|
|
|
|
|
|
- it('应该显示规格选择区域', () => {
|
|
|
- const { getByText } = renderWithProviders(<CartPage />)
|
|
|
+ it('应该显示规格选择区域', async () => {
|
|
|
+ const { findByText } = renderWithProviders(<CartPage />)
|
|
|
|
|
|
// 检查规格文本是否显示
|
|
|
- expect(getByText('红色/M')).toBeDefined()
|
|
|
- expect(getByText('蓝色/L')).toBeDefined()
|
|
|
+ expect(await findByText('红色/M')).toBeDefined()
|
|
|
+ expect(await findByText('蓝色/L')).toBeDefined()
|
|
|
})
|
|
|
|
|
|
- it('规格区域应该可点击并打开规格选择器', () => {
|
|
|
- const { getByText } = renderWithProviders(<CartPage />)
|
|
|
+ it('规格区域应该可点击并打开规格选择器', async () => {
|
|
|
+ const { findByText } = renderWithProviders(<CartPage />)
|
|
|
|
|
|
// 获取规格元素
|
|
|
- const specElement = getByText('红色/M')
|
|
|
+ const specElement = await findByText('红色/M')
|
|
|
|
|
|
// 验证元素存在
|
|
|
expect(specElement).toBeDefined()
|
|
|
@@ -469,10 +485,10 @@ describe('购物车页面', () => {
|
|
|
return Promise.resolve(mockChildGoodsResponse)
|
|
|
})
|
|
|
|
|
|
- const { getByText, container } = renderWithProviders(<CartPage />)
|
|
|
+ const { findByText, container } = renderWithProviders(<CartPage />)
|
|
|
|
|
|
// 点击规格区域打开选择器
|
|
|
- const specElement = getByText('红色/M')
|
|
|
+ const specElement = await findByText('红色/M')
|
|
|
fireEvent.click(specElement)
|
|
|
|
|
|
// 等待API调用
|