|
|
@@ -346,6 +346,7 @@ describe('商品管理集成测试', () => {
|
|
|
page: 1,
|
|
|
pageSize: 10,
|
|
|
keyword: '搜索关键词',
|
|
|
+ filters: '{"spuId": 0}',
|
|
|
},
|
|
|
});
|
|
|
});
|
|
|
@@ -418,6 +419,243 @@ describe('商品管理集成测试', () => {
|
|
|
expect(screen.getByText('创建时间')).toBeInTheDocument();
|
|
|
});
|
|
|
|
|
|
+ describe('商品筛选器功能测试 (故事006.015)', () => {
|
|
|
+ it('应该默认只显示父商品', async () => {
|
|
|
+ const mockGoods = {
|
|
|
+ data: [
|
|
|
+ {
|
|
|
+ id: 1,
|
|
|
+ name: '父商品1',
|
|
|
+ price: 100.00,
|
|
|
+ spuId: 0,
|
|
|
+ spuName: null,
|
|
|
+ childGoodsIds: [2, 3],
|
|
|
+ stock: 100,
|
|
|
+ salesNum: 10,
|
|
|
+ state: 1,
|
|
|
+ createdAt: '2024-01-01T00:00:00Z',
|
|
|
+ supplier: { id: 1, name: '供应商1' },
|
|
|
+ merchant: { id: 1, name: '商户1' },
|
|
|
+ costPrice: 50.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 },
|
|
|
+ };
|
|
|
+
|
|
|
+ (goodsClientManager.get().index.$get as any).mockResolvedValue(createMockResponse(200, mockGoods));
|
|
|
+
|
|
|
+ renderWithProviders(<GoodsManagement />);
|
|
|
+
|
|
|
+ // 等待数据加载
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByText('父商品1')).toBeInTheDocument();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 验证默认传递了filters参数
|
|
|
+ expect(goodsClientManager.get().index.$get).toHaveBeenCalledWith({
|
|
|
+ query: {
|
|
|
+ page: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ keyword: '',
|
|
|
+ filters: '{"spuId": 0}'
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ // 验证筛选器默认选中"只显示父商品"
|
|
|
+ const parentRadio = screen.getByLabelText('只显示父商品');
|
|
|
+ expect(parentRadio).toBeChecked();
|
|
|
+
|
|
|
+ // 验证父子关系标识显示
|
|
|
+ expect(screen.getByText('父商品')).toBeInTheDocument();
|
|
|
+ expect(screen.getByText('子商品: 2个')).toBeInTheDocument();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('应该切换筛选器时实时刷新商品列表', async () => {
|
|
|
+ const mockAllGoods = {
|
|
|
+ data: [
|
|
|
+ {
|
|
|
+ id: 1,
|
|
|
+ name: '父商品1',
|
|
|
+ price: 100.00,
|
|
|
+ spuId: 0,
|
|
|
+ spuName: null,
|
|
|
+ childGoodsIds: [2, 3],
|
|
|
+ stock: 100,
|
|
|
+ salesNum: 10,
|
|
|
+ state: 1,
|
|
|
+ createdAt: '2024-01-01T00:00:00Z',
|
|
|
+ supplier: { id: 1, name: '供应商1' },
|
|
|
+ merchant: { id: 1, name: '商户1' },
|
|
|
+ costPrice: 50.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: []
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 2,
|
|
|
+ name: '子商品1',
|
|
|
+ price: 120.00,
|
|
|
+ spuId: 1,
|
|
|
+ spuName: '父商品1',
|
|
|
+ childGoodsIds: [],
|
|
|
+ stock: 50,
|
|
|
+ salesNum: 5,
|
|
|
+ state: 1,
|
|
|
+ createdAt: '2024-01-01T00:00:00Z',
|
|
|
+ supplier: { id: 1, name: '供应商1' },
|
|
|
+ merchant: { id: 1, name: '商户1' },
|
|
|
+ costPrice: 60.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: 2, page: 1, pageSize: 10 },
|
|
|
+ };
|
|
|
+
|
|
|
+ // 第一次调用:默认只显示父商品
|
|
|
+ (goodsClientManager.get().index.$get as any)
|
|
|
+ .mockResolvedValueOnce(createMockResponse(200, {
|
|
|
+ data: [mockAllGoods.data[0]],
|
|
|
+ pagination: { total: 1, page: 1, pageSize: 10 }
|
|
|
+ }))
|
|
|
+ .mockResolvedValueOnce(createMockResponse(200, mockAllGoods)); // 第二次调用:显示所有商品
|
|
|
+
|
|
|
+ renderWithProviders(<GoodsManagement />);
|
|
|
+
|
|
|
+ // 等待初始加载
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByText('父商品1')).toBeInTheDocument();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 切换到"显示所有商品"
|
|
|
+ const allRadio = screen.getByLabelText('显示所有商品');
|
|
|
+ fireEvent.click(allRadio);
|
|
|
+
|
|
|
+ // 验证API调用不包含filters参数
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(goodsClientManager.get().index.$get).toHaveBeenCalledWith({
|
|
|
+ query: {
|
|
|
+ page: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ keyword: '',
|
|
|
+ // 不传递filters参数
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ // 等待列表刷新
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByText('子商品1')).toBeInTheDocument();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 验证子商品标识显示
|
|
|
+ expect(screen.getByText('子商品')).toBeInTheDocument();
|
|
|
+ expect(screen.getByText('父商品: 父商品1')).toBeInTheDocument();
|
|
|
+ });
|
|
|
+
|
|
|
+ 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 searchInput = screen.getByPlaceholderText('搜索商品名称...');
|
|
|
+ fireEvent.change(searchInput, { target: { value: '测试' } });
|
|
|
+
|
|
|
+ // 提交搜索
|
|
|
+ const searchButton = screen.getByText('搜索');
|
|
|
+ fireEvent.click(searchButton);
|
|
|
+
|
|
|
+ // 验证搜索时保持筛选器状态
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(goodsClientManager.get().index.$get).toHaveBeenCalledWith({
|
|
|
+ query: {
|
|
|
+ page: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ keyword: '测试',
|
|
|
+ filters: '{"spuId": 0}'
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ // 切换到"显示所有商品"
|
|
|
+ const allRadio = screen.getByLabelText('显示所有商品');
|
|
|
+ fireEvent.click(allRadio);
|
|
|
+
|
|
|
+ // 验证切换筛选器时重置页码并包含搜索关键词
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(goodsClientManager.get().index.$get).toHaveBeenCalledWith({
|
|
|
+ query: {
|
|
|
+ page: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ keyword: '测试',
|
|
|
+ // 不传递filters参数
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
describe('父子商品管理面板完整流程测试 (故事006.002)', () => {
|
|
|
it('应该完成创建模式下的父子商品配置完整流程', async () => {
|
|
|
const mockGoods = {
|