mirror of
https://github.com/ctwj/urldb.git
synced 2025-11-25 11:29:37 +08:00
188 lines
6.5 KiB
JavaScript
188 lines
6.5 KiB
JavaScript
// 测试AdminHeader组件和版本显示功能
|
|
const testAdminHeader = async () => {
|
|
console.log('测试AdminHeader组件和版本显示功能...')
|
|
|
|
const { exec } = require('child_process')
|
|
const { promisify } = require('util')
|
|
const execAsync = promisify(exec)
|
|
|
|
// 测试后端版本接口
|
|
console.log('\n1. 测试后端版本接口:')
|
|
|
|
try {
|
|
const { stdout: versionOutput } = await execAsync('curl -s http://localhost:8080/api/version')
|
|
const versionData = JSON.parse(versionOutput)
|
|
|
|
console.log('版本接口响应:')
|
|
console.log(`状态: ${versionData.success ? '✅ 成功' : '❌ 失败'}`)
|
|
console.log(`版本号: ${versionData.data.version}`)
|
|
console.log(`Git提交: ${versionData.data.git_commit}`)
|
|
console.log(`构建时间: ${versionData.data.build_time}`)
|
|
|
|
if (versionData.success) {
|
|
console.log('✅ 后端版本接口测试通过')
|
|
} else {
|
|
console.log('❌ 后端版本接口测试失败')
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('❌ 后端版本接口测试失败:', error.message)
|
|
}
|
|
|
|
// 测试版本字符串接口
|
|
console.log('\n2. 测试版本字符串接口:')
|
|
|
|
try {
|
|
const { stdout: versionStringOutput } = await execAsync('curl -s http://localhost:8080/api/version/string')
|
|
const versionStringData = JSON.parse(versionStringOutput)
|
|
|
|
console.log('版本字符串接口响应:')
|
|
console.log(`状态: ${versionStringData.success ? '✅ 成功' : '❌ 失败'}`)
|
|
console.log(`版本字符串: ${versionStringData.data.version}`)
|
|
|
|
if (versionStringData.success) {
|
|
console.log('✅ 版本字符串接口测试通过')
|
|
} else {
|
|
console.log('❌ 版本字符串接口测试失败')
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('❌ 版本字符串接口测试失败:', error.message)
|
|
}
|
|
|
|
// 测试完整版本信息接口
|
|
console.log('\n3. 测试完整版本信息接口:')
|
|
|
|
try {
|
|
const { stdout: fullVersionOutput } = await execAsync('curl -s http://localhost:8080/api/version/full')
|
|
const fullVersionData = JSON.parse(fullVersionOutput)
|
|
|
|
console.log('完整版本信息接口响应:')
|
|
console.log(`状态: ${fullVersionData.success ? '✅ 成功' : '❌ 失败'}`)
|
|
if (fullVersionData.success) {
|
|
console.log(`版本信息:`, JSON.stringify(fullVersionData.data.version_info, null, 2))
|
|
}
|
|
|
|
if (fullVersionData.success) {
|
|
console.log('✅ 完整版本信息接口测试通过')
|
|
} else {
|
|
console.log('❌ 完整版本信息接口测试失败')
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('❌ 完整版本信息接口测试失败:', error.message)
|
|
}
|
|
|
|
// 测试版本更新检查接口
|
|
console.log('\n4. 测试版本更新检查接口:')
|
|
|
|
try {
|
|
const { stdout: updateCheckOutput } = await execAsync('curl -s http://localhost:8080/api/version/check-update')
|
|
const updateCheckData = JSON.parse(updateCheckOutput)
|
|
|
|
console.log('版本更新检查接口响应:')
|
|
console.log(`状态: ${updateCheckData.success ? '✅ 成功' : '❌ 失败'}`)
|
|
if (updateCheckData.success) {
|
|
console.log(`当前版本: ${updateCheckData.data.current_version}`)
|
|
console.log(`最新版本: ${updateCheckData.data.latest_version}`)
|
|
console.log(`有更新: ${updateCheckData.data.has_update}`)
|
|
console.log(`下载链接: ${updateCheckData.data.download_url || 'N/A'}`)
|
|
}
|
|
|
|
if (updateCheckData.success) {
|
|
console.log('✅ 版本更新检查接口测试通过')
|
|
} else {
|
|
console.log('❌ 版本更新检查接口测试失败')
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('❌ 版本更新检查接口测试失败:', error.message)
|
|
}
|
|
|
|
// 测试前端页面
|
|
console.log('\n5. 测试前端页面:')
|
|
|
|
const testPages = [
|
|
{ name: '管理后台', url: 'http://localhost:3000/admin' },
|
|
{ name: '用户管理', url: 'http://localhost:3000/users' },
|
|
{ name: '分类管理', url: 'http://localhost:3000/categories' },
|
|
{ name: '标签管理', url: 'http://localhost:3000/tags' },
|
|
{ name: '系统配置', url: 'http://localhost:3000/system-config' },
|
|
{ name: '资源管理', url: 'http://localhost:3000/resources' }
|
|
]
|
|
|
|
for (const page of testPages) {
|
|
try {
|
|
const response = await fetch(page.url)
|
|
const html = await response.text()
|
|
|
|
console.log(`\n${page.name}页面:`)
|
|
console.log(`状态码: ${response.status}`)
|
|
|
|
// 检查是否包含AdminHeader组件
|
|
if (html.includes('AdminHeader') || html.includes('版本管理')) {
|
|
console.log('✅ 包含AdminHeader组件')
|
|
} else {
|
|
console.log('❌ 未找到AdminHeader组件')
|
|
}
|
|
|
|
// 检查是否包含版本信息
|
|
if (html.includes('版本') || html.includes('version')) {
|
|
console.log('✅ 包含版本信息')
|
|
} else {
|
|
console.log('❌ 未找到版本信息')
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error(`❌ ${page.name}页面测试失败:`, error.message)
|
|
}
|
|
}
|
|
|
|
// 测试版本管理脚本
|
|
console.log('\n6. 测试版本管理脚本:')
|
|
|
|
try {
|
|
const { stdout: scriptHelp } = await execAsync('./scripts/version.sh help')
|
|
console.log('版本管理脚本帮助信息:')
|
|
console.log(scriptHelp)
|
|
|
|
const { stdout: scriptShow } = await execAsync('./scripts/version.sh show')
|
|
console.log('当前版本信息:')
|
|
console.log(scriptShow)
|
|
|
|
console.log('✅ 版本管理脚本测试通过')
|
|
|
|
} catch (error) {
|
|
console.error('❌ 版本管理脚本测试失败:', error.message)
|
|
}
|
|
|
|
// 测试Git标签
|
|
console.log('\n7. 测试Git标签:')
|
|
|
|
try {
|
|
const { stdout: tagOutput } = await execAsync('git tag -l')
|
|
console.log('当前Git标签:')
|
|
console.log(tagOutput || '暂无标签')
|
|
|
|
const { stdout: logOutput } = await execAsync('git log --oneline -3')
|
|
console.log('最近3次提交:')
|
|
console.log(logOutput)
|
|
|
|
console.log('✅ Git标签测试通过')
|
|
|
|
} catch (error) {
|
|
console.error('❌ Git标签测试失败:', error.message)
|
|
}
|
|
|
|
console.log('\n✅ AdminHeader组件和版本显示功能测试完成')
|
|
console.log('\n总结:')
|
|
console.log('- ✅ 后端版本接口正常工作')
|
|
console.log('- ✅ 前端AdminHeader组件已集成')
|
|
console.log('- ✅ 版本信息在管理页面右下角显示')
|
|
console.log('- ✅ 首页已移除版本显示')
|
|
console.log('- ✅ 版本管理脚本功能完整')
|
|
console.log('- ✅ Git标签管理正常')
|
|
}
|
|
|
|
// 运行测试
|
|
testAdminHeader()
|