fix(auth): highlight failed server connections

This commit is contained in:
2026-07-22 23:13:55 +08:00
parent b01928a5e4
commit a564d48154
5 changed files with 72 additions and 1 deletions

View File

@@ -36,6 +36,7 @@ const workspace = {
await page.route('http://localhost:9150/api/v1/**', async (route) => {
const request = route.request()
const path = new URL(request.url()).pathname
if (path === '/api/v1/status') return route.fulfill({ json: { status: 'unavailable' } })
if (path === '/api/v1/auth/login') return route.fulfill({ json: { token: 'mini-token' } })
if (path === '/api/v1/projects') {
if (request.method() === 'POST') return route.fulfill({ status: 201, json: workspace.project })
@@ -57,6 +58,11 @@ await page.route('http://localhost:9150/api/v1/**', async (route) => {
})
await page.goto(`http://127.0.0.1:${port}/`, { waitUntil: 'networkidle' })
await page.waitForSelector('.mini-connection.offline')
const offlineConnection = await page.locator('.mini-connection').evaluate((element) => ({
text: element.textContent,
borderColor: getComputedStyle(element).borderColor,
}))
await page.screenshot({ path: 'test-results/mini-login.png', fullPage: true })
const loginDefaults = await page.locator('.login-note input').evaluateAll((inputs) => inputs.map((input) => input.value))
await page.locator('.login-note input').nth(2).press('Enter')
@@ -96,6 +102,7 @@ await browser.close()
await server.close()
const failures = []
if (!offlineConnection.text?.includes('连接异常') || offlineConnection.borderColor !== 'rgb(245, 63, 63)') failures.push(`offline connection must be red: ${JSON.stringify(offlineConnection)}`)
if (loginDefaults[1] !== 'demo@senlin.ai' || loginDefaults[2] !== 'password123') failures.push(`login defaults failed: ${JSON.stringify(loginDefaults)}`)
if (errors.length) failures.push(`console errors: ${errors.join('; ')}`)
if (home.width !== 420) failures.push(`expected 420px shell, got ${home.width}`)