import { test, expect } from '@playwright/test'; test.describe('数据字典管理完整工作流', () => { test.describe.configure({ mode: 'serial' }); const timestamp = Date.now(); const dictType = `test_dict_type_${timestamp}`; const dictName = `测试字典_${timestamp}`; const dictCode = `test_dict_code_${timestamp}`; test('创建字典类型', async ({ page }) => { await test.step('导航到数据字典管理', async () => { await page.goto('/dashboard'); await page.waitForLoadState('networkidle'); await page.locator('text=系统管理').click(); await page.waitForTimeout(500); await page.locator('text=数据字典').click(); await page.waitForLoadState('networkidle'); await expect(page).toHaveURL(/.*dicts/, { timeout: 10000 }); }); await test.step('切换到字典类型标签页', async () => { await page.locator('.el-tabs__item:has-text("字典类型")').click(); await page.waitForLoadState('networkidle'); }); await test.step('点击新增字典类型按钮', async () => { await page.locator('button:has-text("新增字典类型")').click(); await page.waitForSelector('.el-dialog', { state: 'visible', timeout: 5000 }); }); await test.step('填写字典类型信息', async () => { const dialog = page.locator('.el-dialog'); await dialog.locator('input').first().fill(dictType); await dialog.locator('input').nth(1).fill(`测试字典类型_${timestamp}`); await dialog.locator('textarea').fill(`这是测试字典类型的备注信息,时间戳:${timestamp}`); }); await test.step('提交字典类型表单', async () => { await page.locator('.el-dialog button:has-text("确定")').click(); await page.waitForSelector('.el-dialog', { state: 'hidden', timeout: 10000 }); await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 }); }); await test.step('验证字典类型已创建', async () => { await page.locator('input[placeholder="请输入字典类型"]').fill(dictType); await page.locator('button:has-text("查询")').click(); await page.waitForLoadState('networkidle'); const dictTypeRow = page.locator(`tr:has-text("${dictType}")`); await expect(dictTypeRow).toBeVisible({ timeout: 10000 }); }); }); test('创建字典数据', async ({ page }) => { await test.step('导航到数据字典管理', async () => { await page.goto('/dashboard'); await page.waitForLoadState('networkidle'); await page.locator('text=系统管理').click(); await page.waitForTimeout(500); await page.locator('text=数据字典').click(); await page.waitForLoadState('networkidle'); }); await test.step('切换到字典数据标签页', async () => { await page.locator('.el-tabs__item:has-text("字典数据")').click(); await page.waitForLoadState('networkidle'); }); await test.step('点击新增字典数据按钮', async () => { await page.locator('button:has-text("新增字典数据")').click(); await page.waitForSelector('.el-dialog', { state: 'visible', timeout: 5000 }); }); await test.step('填写字典数据信息', async () => { const dialog = page.locator('.el-dialog'); // 选择字典类型 await dialog.locator('.el-select').first().click(); await page.locator(`.el-select-dropdown:visible .el-select-dropdown__item:has-text("${dictType}")`).click(); await dialog.locator('input').nth(1).fill(dictName); await dialog.locator('input').nth(2).fill(dictCode); await dialog.locator('.el-input-number .el-input__inner').fill('99'); await dialog.locator('textarea').fill(`这是测试字典数据的备注信息,时间戳:${timestamp}`); }); await test.step('提交字典数据表单', async () => { await page.locator('.el-dialog button:has-text("确定")').click(); await page.waitForSelector('.el-dialog', { state: 'hidden', timeout: 10000 }); await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 }); }); await test.step('验证字典数据已创建', async () => { await page.locator('input[placeholder="请输入字典名称"]').fill(dictName); await page.locator('button:has-text("查询")').click(); await page.waitForLoadState('networkidle'); const dictDataRow = page.locator(`tr:has-text("${dictName}")`); await expect(dictDataRow).toBeVisible({ timeout: 10000 }); await expect(dictDataRow.locator('td').nth(2)).toHaveText(dictCode); }); }); test('编辑字典数据', async ({ page }) => { const updatedName = `更新字典_${timestamp}`; await test.step('导航到数据字典管理', async () => { await page.goto('/dashboard'); await page.waitForLoadState('networkidle'); await page.locator('text=系统管理').click(); await page.waitForTimeout(500); await page.locator('text=数据字典').click(); await page.waitForLoadState('networkidle'); }); await test.step('切换到字典数据标签页', async () => { await page.locator('.el-tabs__item:has-text("字典数据")').click(); await page.waitForLoadState('networkidle'); }); await test.step('搜索并编辑字典数据', async () => { await page.locator('input[placeholder="请输入字典名称"]').fill(dictName); await page.locator('button:has-text("查询")').click(); await page.waitForLoadState('networkidle'); const dictDataRow = page.locator(`tr:has-text("${dictName}")`); await dictDataRow.locator('button:has-text("编辑")').click(); await page.waitForSelector('.el-dialog', { state: 'visible', timeout: 5000 }); }); await test.step('修改字典数据信息', async () => { const dialog = page.locator('.el-dialog'); await dialog.locator('input').nth(1).fill(updatedName); await dialog.locator('textarea').fill(`这是更新后的字典数据备注,时间戳:${timestamp}`); }); await test.step('提交更新', async () => { await page.locator('.el-dialog button:has-text("确定")').click(); await page.waitForSelector('.el-dialog', { state: 'hidden', timeout: 10000 }); await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 }); }); await test.step('验证字典数据已更新', async () => { await page.locator('input[placeholder="请输入字典名称"]').fill(updatedName); await page.locator('button:has-text("查询")').click(); await page.waitForLoadState('networkidle'); const dictDataRow = page.locator(`tr:has-text("${updatedName}")`); await expect(dictDataRow).toBeVisible({ timeout: 10000 }); }); }); test('删除字典数据', async ({ page }) => { await test.step('导航到数据字典管理', async () => { await page.goto('/dashboard'); await page.waitForLoadState('networkidle'); await page.locator('text=系统管理').click(); await page.waitForTimeout(500); await page.locator('text=数据字典').click(); await page.waitForLoadState('networkidle'); }); await test.step('切换到字典数据标签页', async () => { await page.locator('.el-tabs__item:has-text("字典数据")').click(); await page.waitForLoadState('networkidle'); }); await test.step('搜索并删除字典数据', async () => { await page.locator('input[placeholder="请输入字典名称"]').fill(`更新字典_${timestamp}`); await page.locator('button:has-text("查询")').click(); await page.waitForLoadState('networkidle'); const dictDataRow = page.locator(`tr:has-text("更新字典_${timestamp}")`); await dictDataRow.locator('button:has-text("删除")').click(); await page.waitForSelector('.el-message-box', { state: 'visible', timeout: 5000 }); }); await test.step('确认删除', async () => { await page.locator('.el-message-box button:has-text("确定")').click(); await page.waitForSelector('.el-message-box', { state: 'hidden', timeout: 10000 }); await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 }); }); await test.step('验证字典数据已删除', async () => { await page.locator('input[placeholder="请输入字典名称"]').fill(`更新字典_${timestamp}`); await page.locator('button:has-text("查询")').click(); await page.waitForLoadState('networkidle'); const emptyText = page.locator('text=暂无数据'); await expect(emptyText).toBeVisible({ timeout: 10000 }); }); }); test('字典管理功能验证', async ({ page }) => { await test.step('验证字典管理页面访问权限', async () => { await page.goto('/dicts'); await page.waitForLoadState('networkidle'); // 验证页面标题 await expect(page.locator('h1:has-text("数据字典管理")')).toBeVisible({ timeout: 5000 }); // 验证标签页 await expect(page.locator('.el-tabs__item:has-text("字典类型")')).toBeVisible(); await expect(page.locator('.el-tabs__item:has-text("字典数据")')).toBeVisible(); // 验证功能按钮 await expect(page.locator('button:has-text("新增字典类型")')).toBeVisible(); await expect(page.locator('button:has-text("新增字典数据")')).toBeVisible(); await expect(page.locator('button:has-text("查询")')).toBeVisible(); }); await test.step('验证字典类型搜索功能', async () => { await page.locator('.el-tabs__item:has-text("字典类型")').click(); await page.waitForLoadState('networkidle'); const searchInput = page.locator('input[placeholder="请输入字典类型"]'); await expect(searchInput).toBeVisible(); const searchButton = page.locator('button:has-text("查询")'); await expect(searchButton).toBeVisible(); // 测试搜索功能 await searchInput.fill('test'); await searchButton.click(); await page.waitForLoadState('networkidle'); // 验证搜索结果 const table = page.locator('.el-table'); await expect(table).toBeVisible(); }); await test.step('验证字典数据搜索功能', async () => { await page.locator('.el-tabs__item:has-text("字典数据")').click(); await page.waitForLoadState('networkidle'); const searchInput = page.locator('input[placeholder="请输入字典名称"]'); await expect(searchInput).toBeVisible(); const searchButton = page.locator('button:has-text("查询")'); await expect(searchButton).toBeVisible(); // 测试搜索功能 await searchInput.fill('test'); await searchButton.click(); await page.waitForLoadState('networkidle'); // 验证搜索结果 const table = page.locator('.el-table'); await expect(table).toBeVisible(); }); }); });