|
|
@@ -399,220 +399,6 @@ describe('商品管理集成测试', () => {
|
|
|
expect(screen.getByText('创建时间')).toBeInTheDocument();
|
|
|
});
|
|
|
|
|
|
- describe('父子商品配置功能测试 (故事006.001)', () => {
|
|
|
- it('应该显示spuId/spuName字段表单控件', async () => {
|
|
|
- const mockGoods = {
|
|
|
- data: [],
|
|
|
- pagination: { total: 0, page: 1, pageSize: 10 },
|
|
|
- };
|
|
|
-
|
|
|
- (goodsClientManager.get().index.$get as any).mockResolvedValue(createMockResponse(200, mockGoods));
|
|
|
-
|
|
|
- renderWithProviders(<GoodsManagement />);
|
|
|
-
|
|
|
- // 打开创建商品表单
|
|
|
- const createButton = screen.getByTestId('create-goods-button');
|
|
|
- fireEvent.click(createButton);
|
|
|
-
|
|
|
- // 验证spuId字段存在
|
|
|
- await waitFor(() => {
|
|
|
- expect(screen.getByText('主商品ID')).toBeInTheDocument();
|
|
|
- expect(screen.getByTestId('goods-spu-id-input')).toBeInTheDocument();
|
|
|
- });
|
|
|
-
|
|
|
- // 验证spuName字段存在
|
|
|
- expect(screen.getByText('主商品名称')).toBeInTheDocument();
|
|
|
- expect(screen.getByTestId('goods-spu-name-input')).toBeInTheDocument();
|
|
|
- });
|
|
|
-
|
|
|
- it('应该支持创建父商品 (spuId=0)', async () => {
|
|
|
- const mockGoods = {
|
|
|
- data: [],
|
|
|
- pagination: { total: 0, page: 1, pageSize: 10 },
|
|
|
- };
|
|
|
-
|
|
|
- (goodsClientManager.get().index.$get as any).mockResolvedValue(createMockResponse(200, mockGoods));
|
|
|
-
|
|
|
- renderWithProviders(<GoodsManagement />);
|
|
|
-
|
|
|
- // 打开创建商品表单
|
|
|
- const createButton = screen.getByTestId('create-goods-button');
|
|
|
- fireEvent.click(createButton);
|
|
|
-
|
|
|
- // 验证可以设置spuId=0
|
|
|
- await waitFor(() => {
|
|
|
- const spuIdInput = screen.getByTestId('goods-spu-id-input');
|
|
|
- expect(spuIdInput).toBeInTheDocument();
|
|
|
-
|
|
|
- // 设置spuId=0(父商品)
|
|
|
- fireEvent.change(spuIdInput, { target: { value: '0' } });
|
|
|
- expect(spuIdInput).toHaveValue(0);
|
|
|
- });
|
|
|
-
|
|
|
- // 验证spuName字段可以设置为null或空
|
|
|
- const spuNameInput = screen.getByTestId('goods-spu-name-input');
|
|
|
- expect(spuNameInput).toBeInTheDocument();
|
|
|
-
|
|
|
- fireEvent.change(spuNameInput, { target: { value: '' } });
|
|
|
- expect(spuNameInput).toHaveValue('');
|
|
|
- });
|
|
|
-
|
|
|
- it('应该支持创建子商品并关联父商品', async () => {
|
|
|
- const mockGoods = {
|
|
|
- data: [],
|
|
|
- pagination: { total: 0, page: 1, pageSize: 10 },
|
|
|
- };
|
|
|
-
|
|
|
- (goodsClientManager.get().index.$get as any).mockResolvedValue(createMockResponse(200, mockGoods));
|
|
|
-
|
|
|
- renderWithProviders(<GoodsManagement />);
|
|
|
-
|
|
|
- // 打开创建商品表单
|
|
|
- const createButton = screen.getByTestId('create-goods-button');
|
|
|
- fireEvent.click(createButton);
|
|
|
-
|
|
|
- // 验证可以设置spuId>0和spuName
|
|
|
- await waitFor(() => {
|
|
|
- const spuIdInput = screen.getByTestId('goods-spu-id-input');
|
|
|
- const spuNameInput = screen.getByTestId('goods-spu-name-input');
|
|
|
-
|
|
|
- expect(spuIdInput).toBeInTheDocument();
|
|
|
- expect(spuNameInput).toBeInTheDocument();
|
|
|
-
|
|
|
- // 设置spuId=100(父商品ID)
|
|
|
- fireEvent.change(spuIdInput, { target: { value: '100' } });
|
|
|
- expect(spuIdInput).toHaveValue(100);
|
|
|
-
|
|
|
- // 设置spuName='父商品名称'
|
|
|
- fireEvent.change(spuNameInput, { target: { value: '父商品名称' } });
|
|
|
- expect(spuNameInput).toHaveValue('父商品名称');
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- it('应该显示子商品关联选择器组件', async () => {
|
|
|
- const mockGoods = {
|
|
|
- data: [],
|
|
|
- pagination: { total: 0, page: 1, pageSize: 10 },
|
|
|
- };
|
|
|
-
|
|
|
- (goodsClientManager.get().index.$get as any).mockResolvedValue(createMockResponse(200, mockGoods));
|
|
|
-
|
|
|
- renderWithProviders(<GoodsManagement />);
|
|
|
-
|
|
|
- // 打开创建商品表单
|
|
|
- const createButton = screen.getByTestId('create-goods-button');
|
|
|
- fireEvent.click(createButton);
|
|
|
-
|
|
|
- // 验证子商品相关UI元素存在
|
|
|
- await waitFor(() => {
|
|
|
- // 验证"子商品"标签存在
|
|
|
- expect(screen.getByText('子商品')).toBeInTheDocument();
|
|
|
- // 验证描述文本存在
|
|
|
- expect(screen.getByText('选择作为此商品子商品的商品')).toBeInTheDocument();
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- it('应该显示包含父子关系的商品列表', async () => {
|
|
|
- // Mock包含父子关系的商品数据
|
|
|
- const mockGoods = {
|
|
|
- data: [
|
|
|
- {
|
|
|
- id: 100,
|
|
|
- name: '父商品',
|
|
|
- price: 299.99,
|
|
|
- spuId: 0,
|
|
|
- spuName: null,
|
|
|
- childGoodsIds: [101, 102],
|
|
|
- stock: 100,
|
|
|
- salesNum: 50,
|
|
|
- state: 1,
|
|
|
- createdAt: '2024-01-01T00:00:00Z',
|
|
|
- supplier: { id: 1, name: '供应商1' },
|
|
|
- merchant: { id: 1, name: '商户1' },
|
|
|
- // 简化其他字段
|
|
|
- costPrice: 200.00,
|
|
|
- categoryId1: 1,
|
|
|
- categoryId2: 2,
|
|
|
- categoryId3: 3,
|
|
|
- goodsType: 1,
|
|
|
- supplierId: 1,
|
|
|
- merchantId: 1,
|
|
|
- imageFileId: null,
|
|
|
- slideImageIds: [],
|
|
|
- detail: '',
|
|
|
- instructions: '',
|
|
|
- sort: 0,
|
|
|
- lowestBuy: 1,
|
|
|
- updatedAt: '2024-01-01T00:00:00Z',
|
|
|
- createdBy: 1,
|
|
|
- updatedBy: 1,
|
|
|
- category1: { id: 1, name: '分类1' },
|
|
|
- category2: { id: 2, name: '分类2' },
|
|
|
- category3: { id: 3, name: '分类3' },
|
|
|
- imageFile: null,
|
|
|
- slideImages: []
|
|
|
- }
|
|
|
- ],
|
|
|
- pagination: { total: 1, page: 1, pageSize: 10 },
|
|
|
- };
|
|
|
-
|
|
|
- // 添加调试:记录mock调用
|
|
|
-
|
|
|
- (goodsClientManager.get().index.$get as any).mockResolvedValue(createMockResponse(200, mockGoods));
|
|
|
-
|
|
|
- renderWithProviders(<GoodsManagement />);
|
|
|
-
|
|
|
- // 等待数据加载 - 添加调试信息
|
|
|
- await waitFor(() => {
|
|
|
- // 验证表格容器存在
|
|
|
- const table = screen.getByRole('table');
|
|
|
- expect(table).toBeInTheDocument();
|
|
|
-
|
|
|
- // 查找所有行(包括表头和数据行)
|
|
|
- const allRows = screen.getAllByRole('row');
|
|
|
-
|
|
|
- // 检查表格body是否为空
|
|
|
- const tbody = table.querySelector('tbody');
|
|
|
-
|
|
|
- // 检查是否显示了"暂无商品数据"
|
|
|
- const noDataText = screen.queryByText('暂无商品数据');
|
|
|
-
|
|
|
- // 检查是否显示了"商品列表"标题
|
|
|
- const title = screen.queryByText('商品列表');
|
|
|
-
|
|
|
- // 检查搜索框是否存在
|
|
|
- const searchInput = screen.queryByPlaceholderText('搜索商品名称...');
|
|
|
-
|
|
|
- // 检查是否显示了"创建商品"按钮
|
|
|
- const createButton = screen.queryByText('创建商品');
|
|
|
-
|
|
|
- // 首先验证基本UI元素
|
|
|
- expect(screen.getByText('商品管理')).toBeInTheDocument();
|
|
|
- expect(screen.getByText('商品列表')).toBeInTheDocument();
|
|
|
- expect(screen.getByText('创建商品')).toBeInTheDocument();
|
|
|
- expect(screen.getByPlaceholderText('搜索商品名称...')).toBeInTheDocument();
|
|
|
-
|
|
|
- // 验证表格有数据行(至少表头+数据行)
|
|
|
- expect(allRows.length).toBeGreaterThan(1); // 至少表头 + 数据行
|
|
|
-
|
|
|
- // 验证父商品名称显示
|
|
|
- expect(screen.getByText('父商品')).toBeInTheDocument();
|
|
|
-
|
|
|
- // 验证价格显示
|
|
|
- expect(screen.getByText('¥299.99')).toBeInTheDocument();
|
|
|
-
|
|
|
- // 验证库存显示
|
|
|
- expect(screen.getByText('100')).toBeInTheDocument();
|
|
|
-
|
|
|
- // 验证供应商显示
|
|
|
- expect(screen.getByText('供应商1')).toBeInTheDocument();
|
|
|
-
|
|
|
- // 验证状态显示
|
|
|
- expect(screen.getByText('可用')).toBeInTheDocument();
|
|
|
- }, { timeout: 5000 }); // 增加超时时间
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
describe('父子商品管理面板完整流程测试 (故事006.002)', () => {
|
|
|
it('应该完成创建模式下的父子商品配置完整流程', async () => {
|
|
|
const mockGoods = {
|
|
|
@@ -1298,7 +1084,7 @@ describe('商品管理集成测试', () => {
|
|
|
await waitFor(() => {
|
|
|
expect(batchCreateMock).toHaveBeenCalled();
|
|
|
const callArgs = batchCreateMock.mock.calls[0][0];
|
|
|
- const jsonData = callArgs.json();
|
|
|
+ const jsonData = callArgs.json;
|
|
|
expect(jsonData.specs).toHaveLength(5);
|
|
|
});
|
|
|
});
|