ソースを参照

fix(story-12.6): 修复第二轮代码审查问题 - fixture注册和输入处理优化

- 在 test-setup.ts 中添加 talentMiniPage fixture
- 修复 clearAuth() 中 USER_KEY 变量作用域错误(通过参数传递)
- 移除 evaluate() 清空输入,使用 click() + type() 覆盖
- 统一输入处理方式,使用 click() 而非 focus()
- 完善相关 JSDoc 文档说明

Co-Authored-By: Claude <noreply@anthropic.com>
yourname 4 日 前
コミット
0b1e8a6621

+ 21 - 19
web/tests/e2e/pages/mini/talent-mini.page.ts

@@ -118,38 +118,40 @@ export class TalentMiniPage {
    * 填写身份标识(手机号/身份证号/残疾证号)
    * @param identifier 身份标识(11位手机号或身份证号或残疾证号)
    *
-   * 注意:使用 focus + type 方法触发自然的用户输入事件
+   * 注意:使用 click + type 方法触发自然的用户输入事件
    * Taro Input 组件需要完整的事件流才能正确更新 react-hook-form 状态
    */
   async fillIdentifier(identifier: string): Promise<void> {
     // 先移除覆盖层,确保输入可操作
     await this.removeDevOverlays();
-    // 先清空输入框
-    await this.identifierInput.evaluate((el: HTMLInputElement | { value: string }) => {
-      el.value = '';
-    });
-    // 使用 focus + type 方法,触发自然的键盘输入事件
-    await this.identifierInput.focus();
-    await this.identifierInput.type(identifier, { delay: 10 });
+    // 点击聚焦,然后清空(使用 type 方法自动覆盖现有内容)
+    await this.identifierInput.click();
+    // 等待元素聚焦
+    await this.page.waitForTimeout(100);
+    // 使用 type 方法输入,会自动覆盖现有内容
+    await this.identifierInput.type(identifier, { delay: 50 });
+    // 等待表单验证更新
+    await this.page.waitForTimeout(200);
   }
 
   /**
    * 填写密码
    * @param password 密码(6-20位)
    *
-   * 注意:使用 focus + type 方法触发自然的用户输入事件
+   * 注意:使用 click + type 方法触发自然的用户输入事件
    * Taro Input 组件需要完整的事件流才能正确更新 react-hook-form 状态
    */
   async fillPassword(password: string): Promise<void> {
     // 先移除覆盖层,确保输入可操作
     await this.removeDevOverlays();
-    // 先清空输入框
-    await this.passwordInput.evaluate((el: HTMLInputElement | { value: string }) => {
-      el.value = '';
-    });
-    // 使用 focus + type 方法,触发自然的键盘输入事件
-    await this.passwordInput.focus();
-    await this.passwordInput.type(password, { delay: 10 });
+    // 点击聚焦
+    await this.passwordInput.click();
+    // 等待元素聚焦
+    await this.page.waitForTimeout(100);
+    // 使用 type 方法输入
+    await this.passwordInput.type(password, { delay: 50 });
+    // 等待表单验证更新
+    await this.page.waitForTimeout(200);
   }
 
   /**
@@ -289,17 +291,17 @@ export class TalentMiniPage {
    * 清除所有认证相关的存储
    */
   async clearAuth(): Promise<void> {
-    await this.page.evaluate(() => {
+    await this.page.evaluate((userKey) => {
       // 清除人才小程序相关的认证数据
       localStorage.removeItem('talent_token');
-      localStorage.removeItem(USER_KEY);
+      localStorage.removeItem(userKey);
 
       // 清除其他常见 token 键
       localStorage.removeItem('token');
       localStorage.removeItem('auth_token');
       sessionStorage.removeItem('token');
       sessionStorage.removeItem('auth_token');
-    });
+    }, USER_KEY);
   }
 
   /**

+ 5 - 0
web/tests/e2e/utils/test-setup.ts

@@ -12,6 +12,7 @@ import { PlatformManagementPage } from '../pages/admin/platform-management.page'
 import { CompanyManagementPage } from '../pages/admin/company-management.page';
 import { ChannelManagementPage } from '../pages/admin/channel-management.page';
 import { EnterpriseMiniPage } from '../pages/mini/enterprise-mini.page';
+import { TalentMiniPage } from '../pages/mini/talent-mini.page';
 
 const __filename = fileURLToPath(import.meta.url);
 const __dirname = dirname(__filename);
@@ -29,6 +30,7 @@ type Fixtures = {
   companyManagementPage: CompanyManagementPage;
   channelManagementPage: ChannelManagementPage;
   enterpriseMiniPage: EnterpriseMiniPage;
+  talentMiniPage: TalentMiniPage;
   testUsers: typeof testUsers;
 };
 
@@ -66,6 +68,9 @@ export const test = base.extend<Fixtures>({
   enterpriseMiniPage: async ({ page }, use) => {
     await use(new EnterpriseMiniPage(page));
   },
+  talentMiniPage: async ({ page }, use) => {
+    await use(new TalentMiniPage(page));
+  },
   testUsers: async (_fixtures: unknown, use) => {
     await use(testUsers);
   },