|
|
@@ -75,7 +75,7 @@ vi.mock('../src/api/goodsClient', () => {
|
|
|
parent: {
|
|
|
$delete: vi.fn(() => Promise.resolve(createMockResponse(200))),
|
|
|
},
|
|
|
- $delete: vi.fn(() => Promise.resolve(createMockResponse(200, { success: true }))),
|
|
|
+ $delete: vi.fn(() => Promise.resolve(createMockResponse(204))),
|
|
|
$get: vi.fn(() => Promise.resolve(createMockResponse(200, { id: 123, spuId: 0, tenantId: 1 }))),
|
|
|
},
|
|
|
batchCreateChildren: {
|
|
|
@@ -380,8 +380,8 @@ describe('GoodsParentChildPanel', () => {
|
|
|
json: () => Promise.resolve(mockGoodsDetail)
|
|
|
});
|
|
|
mockClient[':id'].$delete.mockResolvedValue({
|
|
|
- status: 200,
|
|
|
- json: () => Promise.resolve(mockDeleteResponse)
|
|
|
+ status: 204,
|
|
|
+ json: () => Promise.resolve(null) // 204 No Content 响应没有body
|
|
|
});
|
|
|
|
|
|
const onUpdate = vi.fn();
|
|
|
@@ -409,6 +409,68 @@ describe('GoodsParentChildPanel', () => {
|
|
|
expect(screen.getByText('管理子商品')).toBeInTheDocument();
|
|
|
});
|
|
|
|
|
|
+ it('应该使查询失效当批量创建子商品成功', async () => {
|
|
|
+ // 模拟 queryClient
|
|
|
+ const mockQueryClient = {
|
|
|
+ invalidateQueries: vi.fn()
|
|
|
+ };
|
|
|
+ vi.spyOn(require('@tanstack/react-query'), 'useQueryClient').mockReturnValue(mockQueryClient);
|
|
|
+
|
|
|
+ // 模拟 goodsClientManager
|
|
|
+ const mockClient = require('../src/api/goodsClient').goodsClientManager.get();
|
|
|
+ mockClient.batchCreateChildren.$post.mockResolvedValue({
|
|
|
+ status: 200,
|
|
|
+ json: () => Promise.resolve({ success: true })
|
|
|
+ });
|
|
|
+
|
|
|
+ const onUpdate = vi.fn();
|
|
|
+ render(
|
|
|
+ <GoodsParentChildPanel
|
|
|
+ {...defaultProps}
|
|
|
+ mode="edit"
|
|
|
+ goodsId={123}
|
|
|
+ tenantId={1}
|
|
|
+ spuId={0}
|
|
|
+ spuName={null}
|
|
|
+ onUpdate={onUpdate}
|
|
|
+ />,
|
|
|
+ { wrapper: createWrapper() }
|
|
|
+ );
|
|
|
+
|
|
|
+ // 切换到批量创建标签页
|
|
|
+ const batchCreateTab = screen.getByText('批量创建');
|
|
|
+ fireEvent.click(batchCreateTab);
|
|
|
+
|
|
|
+ // 添加规格
|
|
|
+ const addSpecButton = screen.getByText('添加规格');
|
|
|
+ fireEvent.click(addSpecButton);
|
|
|
+
|
|
|
+ // 填写规格信息
|
|
|
+ const nameInput = screen.getByPlaceholderText('如:红色、XL');
|
|
|
+ fireEvent.change(nameInput, { target: { value: '红色' } });
|
|
|
+
|
|
|
+ const priceInput = screen.getAllByPlaceholderText('0.00')[0];
|
|
|
+ fireEvent.change(priceInput, { target: { value: '100' } });
|
|
|
+
|
|
|
+ const stockInput = screen.getAllByPlaceholderText('0')[0];
|
|
|
+ fireEvent.change(stockInput, { target: { value: '10' } });
|
|
|
+
|
|
|
+ // 点击批量创建按钮
|
|
|
+ const createButton = screen.getByText('批量创建子商品');
|
|
|
+ fireEvent.click(createButton);
|
|
|
+
|
|
|
+ // 等待 mutation 完成
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(mockQueryClient.invalidateQueries).toHaveBeenCalledWith({
|
|
|
+ queryKey: ['goods-children', 123, 1]
|
|
|
+ });
|
|
|
+ expect(mockQueryClient.invalidateQueries).toHaveBeenCalledWith({
|
|
|
+ queryKey: ['goods', 'children', 'list', 123, 1]
|
|
|
+ });
|
|
|
+ expect(toast.success).toHaveBeenCalledWith('批量创建子商品成功');
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
it('应该显示删除确认对话框当点击删除按钮', () => {
|
|
|
// 这个测试需要模拟ChildGoodsList的交互
|
|
|
// 由于时间限制,暂时跳过
|