feat(db): 迁移数据库迁移脚本 V1-V5(任务 T1.1) #5

Merged
zhangxiang merged 21 commits from dev into main 2026-05-01 21:59:04 +08:00
3 changed files with 35 additions and 107 deletions
Showing only changes of commit 330828f585 - Show all commits
@@ -50,7 +50,8 @@ describe('RoleAuthManager', () => {
it('should throw error on authentication failure', async () => {
(global.fetch as any).mockResolvedValueOnce({
ok: false,
statusText: 'Unauthorized'
statusText: 'Unauthorized',
text: async () => 'Invalid credentials'
});
await expect(RoleAuthManager.getRoleToken('admin')).rejects.toThrow('Authentication failed');
+31 -105
View File
@@ -219,43 +219,17 @@ async function captureStep(page, stepName) {
console.log('=====================================');
try {
// 首先展开系统管理菜单(如果是折叠状态)
const systemMenuSelector = '.el-sub-menu:has-text("系统管理")';
const systemMenuElement = page.locator(systemMenuSelector).first();
await page.waitForTimeout(500);
if (await systemMenuElement.count() > 0) {
// 点击展开系统管理菜单
await systemMenuElement.click();
await page.waitForTimeout(500);
// 然后点击角色管理菜单项
const roleMenuSelectors = [
'.el-menu-item:has-text("角色管理")',
'text=角色管理',
'text=角色',
'[data-menu="role"]',
'a[href*="role"]'
];
let navigated = false;
for (const selector of roleMenuSelectors) {
const element = page.locator(selector).first();
if (await element.count() > 0) {
await element.click();
navigated = true;
break;
}
}
if (navigated) {
await page.waitForTimeout(1000);
await captureStep(page, '05-role-management');
logTest('导航到角色管理页面', true);
} else {
throw new Error('未找到角色管理菜单');
}
const roleMenuItem = page.locator('.el-menu-item:has-text("角色管理")').first();
if (await roleMenuItem.count() > 0) {
await roleMenuItem.click();
await page.waitForTimeout(1000);
await captureStep(page, '05-role-management');
logTest('导航到角色管理页面', true);
} else {
throw new Error('未找到系统管理菜单');
throw new Error('未找到角色管理菜单');
}
} catch (error) {
logTest('导航到角色管理页面', false, error.message);
@@ -266,46 +240,17 @@ async function captureStep(page, stepName) {
console.log('=====================================');
try {
// 首先展开系统管理菜单(如果是折叠状态)
const systemMenuSelector = '.el-sub-menu:has-text("系统管理")';
const systemMenuElement = page.locator(systemMenuSelector).first();
await page.waitForTimeout(500);
if (await systemMenuElement.count() > 0) {
// 点击展开系统管理菜单
await systemMenuElement.click();
await page.waitForTimeout(500);
// 然后点击参数配置菜单项
const configMenuSelectors = [
'.el-menu-item:has-text("参数配置")',
'.el-menu-item:has-text("系统配置")',
'.el-menu-item:has-text("配置管理")',
'text=参数配置',
'text=系统配置',
'text=配置管理',
'[data-menu="config"]',
'a[href*="config"]'
];
let navigated = false;
for (const selector of configMenuSelectors) {
const element = page.locator(selector).first();
if (await element.count() > 0) {
await element.click();
navigated = true;
break;
}
}
if (navigated) {
await page.waitForTimeout(1000);
await captureStep(page, '06-system-config');
logTest('导航到系统配置页面', true);
} else {
throw new Error('未找到系统配置菜单');
}
await page.goto(`${TARGET_URL}/sys/config`, { waitUntil: 'networkidle' });
await page.waitForTimeout(1000);
await captureStep(page, '06-system-config');
const currentUrl = page.url();
if (currentUrl.includes('/sys/config')) {
logTest('导航到系统配置页面', true);
} else {
throw new Error('未找到系统管理菜单');
throw new Error(`导航失败,当前URL: ${currentUrl}`);
}
} catch (error) {
logTest('导航到系统配置页面', false, error.message);
@@ -316,41 +261,22 @@ async function captureStep(page, stepName) {
console.log('=====================================');
try {
// 首先点击用户头像以展开下拉菜单
const avatarSelector = '.el-avatar';
const avatarElement = page.locator(avatarSelector).first();
await page.waitForTimeout(500);
if (await avatarElement.count() > 0) {
await avatarElement.click();
await page.waitForTimeout(500); // 等待下拉菜单展开
const dropdown = page.locator('.el-dropdown').first();
if (await dropdown.count() > 0) {
await dropdown.click();
await page.waitForSelector('.el-dropdown-menu', { state: 'visible', timeout: 5000 });
await page.waitForTimeout(300);
// 然后点击退出登录按钮
const logoutSelectors = [
'.el-dropdown-menu__item:has-text("退出登录")',
'.el-dropdown-menu__item:has-text("退出")',
'.el-dropdown-menu__item:has-text("登出")',
'button:has-text("退出")',
'button:has-text("登出")',
'a:has-text("退出")',
'a:has-text("登出")',
'[data-action="logout"]',
'.logout-button'
];
const logoutItem = page.locator('.el-dropdown-menu__item:has-text("退出登录")').first();
let loggedOut = false;
for (const selector of logoutSelectors) {
const element = page.locator(selector).first();
if (await element.count() > 0) {
await element.click();
loggedOut = true;
break;
}
}
if (loggedOut) {
if (await logoutItem.count() > 0) {
await logoutItem.click({ force: true });
await page.waitForTimeout(2000);
const currentUrl = page.url();
const currentUrl = page.url();
if (currentUrl.includes('login')) {
await captureStep(page, '07-after-logout');
logTest('登出成功', true);
@@ -358,10 +284,10 @@ async function captureStep(page, stepName) {
throw new Error(`登出后未跳转到登录页,当前URL: ${currentUrl}`);
}
} else {
throw new Error('未找到登出按钮');
throw new Error('未找到退出登录按钮');
}
} else {
throw new Error('未找到用户头像');
throw new Error('未找到用户下拉菜单');
}
} catch (error) {
logTest('登出成功', false, error.message);
+2 -1
View File
@@ -9,7 +9,8 @@ export default defineConfig({
environment: 'jsdom',
setupFiles: ['./src/__tests__/setup.ts'],
include: [
'src/__tests__/**/*.{test,spec}.{js,ts,jsx,tsx}'
'src/__tests__/**/*.{test,spec}.{js,ts,jsx,tsx}',
'src/role-based-tests/**/*.{test,spec}.{js,ts,jsx,tsx}'
],
// 明确排除E2E测试文件
exclude: [