|
@@ -557,7 +557,6 @@ describe('商品管理集成测试', () => {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 添加调试:记录mock调用
|
|
// 添加调试:记录mock调用
|
|
|
- console.debug('设置mock响应:', JSON.stringify(mockGoods, null, 2));
|
|
|
|
|
|
|
|
|
|
(goodsClientManager.get().index.$get as any).mockResolvedValue(createMockResponse(200, mockGoods));
|
|
(goodsClientManager.get().index.$get as any).mockResolvedValue(createMockResponse(200, mockGoods));
|
|
|
|
|
|
|
@@ -569,38 +568,23 @@ describe('商品管理集成测试', () => {
|
|
|
const table = screen.getByRole('table');
|
|
const table = screen.getByRole('table');
|
|
|
expect(table).toBeInTheDocument();
|
|
expect(table).toBeInTheDocument();
|
|
|
|
|
|
|
|
- // 调试:打印DOM结构
|
|
|
|
|
- console.debug('表格HTML:', table.outerHTML);
|
|
|
|
|
-
|
|
|
|
|
// 查找所有行(包括表头和数据行)
|
|
// 查找所有行(包括表头和数据行)
|
|
|
const allRows = screen.getAllByRole('row');
|
|
const allRows = screen.getAllByRole('row');
|
|
|
- console.debug(`找到 ${allRows.length} 行`);
|
|
|
|
|
|
|
|
|
|
// 检查表格body是否为空
|
|
// 检查表格body是否为空
|
|
|
const tbody = table.querySelector('tbody');
|
|
const tbody = table.querySelector('tbody');
|
|
|
- console.debug('tbody内容:', tbody?.innerHTML);
|
|
|
|
|
|
|
|
|
|
// 检查是否显示了"暂无商品数据"
|
|
// 检查是否显示了"暂无商品数据"
|
|
|
const noDataText = screen.queryByText('暂无商品数据');
|
|
const noDataText = screen.queryByText('暂无商品数据');
|
|
|
- console.debug('是否显示暂无商品数据:', noDataText ? '是' : '否');
|
|
|
|
|
|
|
|
|
|
// 检查是否显示了"商品列表"标题
|
|
// 检查是否显示了"商品列表"标题
|
|
|
const title = screen.queryByText('商品列表');
|
|
const title = screen.queryByText('商品列表');
|
|
|
- console.debug('是否显示商品列表标题:', title ? '是' : '否');
|
|
|
|
|
|
|
|
|
|
// 检查搜索框是否存在
|
|
// 检查搜索框是否存在
|
|
|
const searchInput = screen.queryByPlaceholderText('搜索商品名称...');
|
|
const searchInput = screen.queryByPlaceholderText('搜索商品名称...');
|
|
|
- console.debug('搜索框是否存在:', searchInput ? '是' : '否');
|
|
|
|
|
|
|
|
|
|
// 检查是否显示了"创建商品"按钮
|
|
// 检查是否显示了"创建商品"按钮
|
|
|
const createButton = screen.queryByText('创建商品');
|
|
const createButton = screen.queryByText('创建商品');
|
|
|
- console.debug('创建商品按钮是否存在:', createButton ? '是' : '否');
|
|
|
|
|
-
|
|
|
|
|
- // 检查mock是否被调用
|
|
|
|
|
- console.debug('mock是否被调用:', (goodsClientManager.get().index.$get as any).mock.calls.length > 0 ? '是' : '否');
|
|
|
|
|
- if ((goodsClientManager.get().index.$get as any).mock.calls.length > 0) {
|
|
|
|
|
- console.debug('mock调用参数:', (goodsClientManager.get().index.$get as any).mock.calls[0]);
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
// 首先验证基本UI元素
|
|
// 首先验证基本UI元素
|
|
|
expect(screen.getByText('商品管理')).toBeInTheDocument();
|
|
expect(screen.getByText('商品管理')).toBeInTheDocument();
|
|
@@ -1025,13 +1009,10 @@ describe('商品管理集成测试', () => {
|
|
|
// 等待按钮启用 - 根据组件逻辑,按钮在规格名称不为空时启用
|
|
// 等待按钮启用 - 根据组件逻辑,按钮在规格名称不为空时启用
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
|
expect(addSpecButton).toBeEnabled();
|
|
expect(addSpecButton).toBeEnabled();
|
|
|
- screen.debug(addSpecButton)
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
fireEvent.click(addSpecButton);
|
|
fireEvent.click(addSpecButton);
|
|
|
|
|
|
|
|
- screen.debug(within(createDialog).getByTestId('spec-name-input'))
|
|
|
|
|
-
|
|
|
|
|
// 等待规格添加完成
|
|
// 等待规格添加完成
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
|
expect(within(createDialog).getByTestId('spec-row-0')).toBeInTheDocument();
|
|
expect(within(createDialog).getByTestId('spec-row-0')).toBeInTheDocument();
|
|
@@ -1221,31 +1202,25 @@ describe('商品管理集成测试', () => {
|
|
|
|
|
|
|
|
// 1. 打开创建表单
|
|
// 1. 打开创建表单
|
|
|
const createButton = screen.getByTestId('create-goods-button');
|
|
const createButton = screen.getByTestId('create-goods-button');
|
|
|
- console.debug('点击创建商品按钮前,页面标题:', screen.queryByText('商品管理')?.textContent);
|
|
|
|
|
fireEvent.click(createButton);
|
|
fireEvent.click(createButton);
|
|
|
- console.debug('点击创建商品按钮后');
|
|
|
|
|
|
|
|
|
|
// 等待对话框打开 - 先检查对话框是否显示
|
|
// 等待对话框打开 - 先检查对话框是否显示
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
|
expect(screen.getByTestId('create-edit-goods-dialog')).toBeInTheDocument();
|
|
expect(screen.getByTestId('create-edit-goods-dialog')).toBeInTheDocument();
|
|
|
}, { timeout: 5000 });
|
|
}, { timeout: 5000 });
|
|
|
- console.debug('create-edit-goods-dialog找到了');
|
|
|
|
|
|
|
|
|
|
// 然后等待输入框出现
|
|
// 然后等待输入框出现
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
|
expect(screen.getByTestId('goods-name-input')).toBeInTheDocument();
|
|
expect(screen.getByTestId('goods-name-input')).toBeInTheDocument();
|
|
|
}, { timeout: 5000 });
|
|
}, { timeout: 5000 });
|
|
|
- console.debug('goods-name-input找到了');
|
|
|
|
|
|
|
|
|
|
// 找到对话框容器 - 使用更通用的查询方式
|
|
// 找到对话框容器 - 使用更通用的查询方式
|
|
|
// 先检查是否有"创建商品"标题(对话框中的标题)
|
|
// 先检查是否有"创建商品"标题(对话框中的标题)
|
|
|
const dialogTitles = screen.getAllByText('创建商品');
|
|
const dialogTitles = screen.getAllByText('创建商品');
|
|
|
// 第一个是页面上的创建按钮,第二个是对话框标题
|
|
// 第一个是页面上的创建按钮,第二个是对话框标题
|
|
|
const dialogTitle = dialogTitles[1];
|
|
const dialogTitle = dialogTitles[1];
|
|
|
- console.debug('对话框标题找到了:', !!dialogTitle);
|
|
|
|
|
// 找到包含标题的对话框容器
|
|
// 找到包含标题的对话框容器
|
|
|
const dialogContainerByTitle = dialogTitle.closest('[role="dialog"], [data-radix-portal]');
|
|
const dialogContainerByTitle = dialogTitle.closest('[role="dialog"], [data-radix-portal]');
|
|
|
- console.debug('对话框容器找到了:', !!dialogContainerByTitle);
|
|
|
|
|
|
|
|
|
|
// 2. 填写基本商品信息
|
|
// 2. 填写基本商品信息
|
|
|
const nameInput = screen.getByTestId('goods-name-input');
|
|
const nameInput = screen.getByTestId('goods-name-input');
|