|
|
@@ -4,15 +4,35 @@ export class AdminLoginPage {
|
|
|
readonly page: Page;
|
|
|
readonly usernameInput: Locator;
|
|
|
readonly passwordInput: Locator;
|
|
|
- readonly loginButton: Locator;
|
|
|
- readonly errorMessage: Locator;
|
|
|
+ readonly submitButton: Locator;
|
|
|
+ readonly togglePasswordButton: Locator;
|
|
|
+ readonly pageTitle: Locator;
|
|
|
+ readonly welcomeText: Locator;
|
|
|
+ readonly successToast: Locator;
|
|
|
+ readonly errorToast: Locator;
|
|
|
+ readonly usernameError: Locator;
|
|
|
+ readonly passwordError: Locator;
|
|
|
+ readonly testAccountInfo: Locator;
|
|
|
+ readonly loadingSpinner: Locator;
|
|
|
+ readonly backgroundElement: Locator;
|
|
|
+ readonly loginCard: Locator;
|
|
|
|
|
|
constructor(page: Page) {
|
|
|
this.page = page;
|
|
|
this.usernameInput = page.getByPlaceholder('请输入用户名');
|
|
|
this.passwordInput = page.getByPlaceholder('请输入密码');
|
|
|
- this.loginButton = page.getByRole('button', { name: '登录' });
|
|
|
- this.errorMessage = page.locator('[data-sonner-toast]');
|
|
|
+ this.submitButton = page.getByRole('button', { name: '登录' });
|
|
|
+ this.togglePasswordButton = page.locator('button[aria-label*="密码"], button[aria-label*="显示"], button[aria-label*="隐藏"]');
|
|
|
+ this.pageTitle = page.getByRole('heading', { name: '管理后台登录' });
|
|
|
+ this.welcomeText = page.getByText('请输入您的账号和密码继续操作');
|
|
|
+ this.successToast = page.locator('[data-sonner-toast][data-type="success"]');
|
|
|
+ this.errorToast = page.locator('[data-sonner-toast][data-type="error"]');
|
|
|
+ this.usernameError = page.locator('text=请输入用户名');
|
|
|
+ this.passwordError = page.locator('text=请输入密码');
|
|
|
+ this.testAccountInfo = page.locator('text=测试账号:');
|
|
|
+ this.loadingSpinner = page.locator('[aria-busy="true"], .loading-spinner, .spinner');
|
|
|
+ this.backgroundElement = page.locator('main, .background, [class*="bg-"]').first();
|
|
|
+ this.loginCard = page.locator('.card, .login-card, .form-card').first();
|
|
|
}
|
|
|
|
|
|
async goto() {
|
|
|
@@ -20,23 +40,35 @@ export class AdminLoginPage {
|
|
|
await this.page.waitForLoadState('networkidle');
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ async expectLoginSuccess() {
|
|
|
+ // 登录成功后应该重定向到管理后台dashboard
|
|
|
+ await expect(this.page).toHaveURL('/admin/dashboard');
|
|
|
+ await expect(this.page.locator('text=登录成功')).toBeVisible();
|
|
|
+ }
|
|
|
+
|
|
|
+ async expectLoginError() {
|
|
|
+ await expect(this.errorToast).toBeVisible();
|
|
|
+ }
|
|
|
+
|
|
|
+ async expectToBeVisible() {
|
|
|
+ await expect(this.pageTitle).toBeVisible();
|
|
|
+ await expect(this.usernameInput).toBeVisible();
|
|
|
+ await expect(this.passwordInput).toBeVisible();
|
|
|
+ await expect(this.submitButton).toBeVisible();
|
|
|
+ }
|
|
|
+
|
|
|
async login(username: string, password: string) {
|
|
|
await this.usernameInput.fill(username);
|
|
|
await this.passwordInput.fill(password);
|
|
|
- await this.loginButton.click();
|
|
|
+ await this.submitButton.click();
|
|
|
|
|
|
// 等待登录完成
|
|
|
await this.page.waitForLoadState('networkidle');
|
|
|
await this.page.waitForTimeout(2000);
|
|
|
}
|
|
|
|
|
|
- async expectLoginSuccess() {
|
|
|
- // 登录成功后应该重定向到管理后台dashboard
|
|
|
- await expect(this.page).toHaveURL('/admin/dashboard');
|
|
|
- await expect(this.page.locator('text=登录成功')).toBeVisible();
|
|
|
- }
|
|
|
-
|
|
|
- async expectLoginError() {
|
|
|
- await expect(this.errorMessage).toBeVisible();
|
|
|
+ clone(newPage: Page): AdminLoginPage {
|
|
|
+ return new AdminLoginPage(newPage);
|
|
|
}
|
|
|
}
|