develop #1
@@ -34,10 +34,15 @@ test.describe('登录流程测试', () => {
|
|||||||
|
|
||||||
await page.fill('input[placeholder*="用户名"]', 'admin');
|
await page.fill('input[placeholder*="用户名"]', 'admin');
|
||||||
await page.fill('input[placeholder*="密码"]', 'wrongpassword');
|
await page.fill('input[placeholder*="密码"]', 'wrongpassword');
|
||||||
await page.click('button:has-text("登录")');
|
|
||||||
|
|
||||||
const errorMessage = page.locator('.el-message--error');
|
await Promise.all([
|
||||||
await expect(errorMessage).toBeVisible({ timeout: 5000 });
|
page.waitForResponse(resp => resp.url().includes('/auth/login') && resp.status() === 401),
|
||||||
|
page.click('button:has-text("登录")')
|
||||||
|
]);
|
||||||
|
|
||||||
|
const errorMessage = page.locator('.el-message');
|
||||||
|
await expect(errorMessage).toBeVisible({ timeout: 10000 });
|
||||||
|
await expect(errorMessage).toContainText(/用户名或密码错误|登录失败/i);
|
||||||
|
|
||||||
await expect(page).toHaveURL(/\/login/);
|
await expect(page).toHaveURL(/\/login/);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -47,8 +47,10 @@ request.interceptors.response.use(
|
|||||||
(error) => {
|
(error) => {
|
||||||
if (error.response?.status === 401) {
|
if (error.response?.status === 401) {
|
||||||
localStorage.removeItem('token')
|
localStorage.removeItem('token')
|
||||||
|
if (!window.location.pathname.includes('/login')) {
|
||||||
window.location.href = '/login'
|
window.location.href = '/login'
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user