import { test, expect } from './test-fixtures'; test.describe('操作日志 - 完全Mock模式', () => { test.beforeEach(async ({ page, mockManager }) => { mockManager.enableMock(); mockManager.configureMock({ mode: 'full', delay: 100 }); mockManager.presetTestData({ operationLogs: [ { id: 1, userId: 1, username: 'admin', module: '用户管理', operation: '查询', method: 'GET', path: '/sys/user/query', params: '{"page":1,"pageSize":10}', ip: '192.168.1.100', status: 'success', errorMsg: undefined, duration: 120, createdAt: '2024-01-01T10:00:00.000Z' }, { id: 2, userId: 1, username: 'admin', module: '用户管理', operation: '新增', method: 'POST', path: '/sys/user/create', params: '{"username":"testuser"}', ip: '192.168.1.100', status: 'success', errorMsg: undefined, duration: 250, createdAt: '2024-01-01T11:00:00.000Z' }, { id: 3, userId: 1, username: 'admin', module: '角色管理', operation: '修改', method: 'PUT', path: '/sys/role/update', params: '{"roleId":1,"name":"更新后的角色"}', ip: '192.168.1.100', status: 'success', errorMsg: undefined, duration: 180, createdAt: '2024-01-01T12:00:00.000Z' }, { id: 4, userId: 2, username: 'user1', module: '菜单管理', operation: '删除', method: 'DELETE', path: '/sys/menu/delete', params: '{"menuId":5}', ip: '192.168.1.101', status: 'error', errorMsg: '操作失败:权限不足或参数错误', duration: 80, createdAt: '2024-01-01T13:00:00.000Z' }, { id: 5, userId: 1, username: 'admin', module: '操作日志', operation: '导出', method: 'GET', path: '/sys/operationLog/export', params: '{"startDate":"2024-01-01","endDate":"2024-01-31"}', ip: '192.168.1.100', status: 'success', errorMsg: undefined, duration: 350, createdAt: '2024-01-01T14:00:00.000Z' } ] }); await page.goto('/'); await page.fill('input[placeholder="请输入用户名"]', 'admin'); await page.fill('input[placeholder="请输入密码"]', 'admin123'); await page.click('button[type="submit"]'); await page.waitForURL(/.*dashboard/, { timeout: 10000 }); }); test.afterEach(async ({ mockManager }) => { mockManager.clearPresets(); mockManager.disableMock(); }); test('应该显示操作日志列表', async ({ page }) => { await page.goto('/operationLogs'); await page.waitForLoadState('networkidle'); await expect(page.locator('.ant-table')).toBeVisible(); await expect(page.locator('text=用户管理')).toBeVisible(); await expect(page.locator('text=角色管理')).toBeVisible(); await expect(page.locator('text=菜单管理')).toBeVisible(); await expect(page.locator('text=操作日志')).toBeVisible(); }); test('应该能够按用户名搜索', async ({ page }) => { await page.goto('/operationLogs'); await page.waitForLoadState('networkidle'); await page.fill('input[placeholder="请输入用户名"]', 'admin'); await page.click('button:has-text("查询")'); await expect(page.locator('text=admin')).toBeVisible(); }); test('应该能够按模块搜索', async ({ page }) => { await page.goto('/operationLogs'); await page.waitForLoadState('networkidle'); await page.click('.ant-select-selector'); await page.click('text=用户管理'); await page.click('button:has-text("查询")'); await expect(page.locator('text=用户管理')).toBeVisible(); }); test('应该能够按日期范围搜索', async ({ page }) => { await page.goto('/operationLogs'); await page.waitForLoadState('networkidle'); await page.click('.ant-picker'); await page.click('text=今天'); await page.click('button:has-text("查询")'); await expect(page.locator('.ant-table')).toBeVisible(); }); test('应该能够导出操作日志', async ({ page }) => { await page.goto('/operationLogs'); await page.waitForLoadState('networkidle'); const downloadPromise = page.waitForEvent('download'); await page.click('button:has-text("导出")'); const download = await downloadPromise; expect(download.suggestedFilename()).toContain('.xlsx'); }); test('应该能够查看日志详情', async ({ page }) => { await page.goto('/operationLogs'); await page.waitForLoadState('networkidle'); await page.click('button:has-text("详情"):first'); await expect(page.locator('.ant-modal')).toBeVisible(); await expect(page.locator('text=用户名')).toBeVisible(); await expect(page.locator('text=模块')).toBeVisible(); await expect(page.locator('text=操作')).toBeVisible(); await expect(page.locator('text=请求方法')).toBeVisible(); await expect(page.locator('text=请求路径')).toBeVisible(); await expect(page.locator('text=请求参数')).toBeVisible(); await expect(page.locator('text=IP地址')).toBeVisible(); await expect(page.locator('text=状态')).toBeVisible(); await expect(page.locator('text=执行时长')).toBeVisible(); }); });