Parcourir la source

style: lint-staged 自动格式化

Co-Authored-By: Claude <noreply@anthropic.com>
yourname il y a 3 jours
Parent
commit
c9c2a8968f

+ 1 - 51
allin-packages/disability-person-management-ui/src/components/DisabledPersonSelector.tsx

@@ -1,4 +1,4 @@
-import React, { useState, useEffect, useRef } from 'react';
+import React, { useState, useEffect } from 'react';
 import { useQuery } from '@tanstack/react-query';
 import {
   Dialog,
@@ -101,55 +101,6 @@ const DisabledPersonSelector: React.FC<DisabledPersonSelectorProps> = ({
   const personsData = searchParams.keyword ? data : allData;
   const isLoadingData = searchParams.keyword ? isLoading : isLoadingAll;
 
-  // 使用 ref 存储 onSelect 和 onOpenChange,避免依赖函数引用
-  const onSelectRef = useRef(onSelect);
-  const onOpenChangeRef = useRef(onOpenChange);
-  const autoSelectTriggeredRef = useRef(false); // 防止自动选择多次触发
-  onSelectRef.current = onSelect;
-  onOpenChangeRef.current = onOpenChange;
-
-  // 测试环境:当残疾人列表加载完成后,自动选中第一个残疾人并确认选择
-  useEffect(() => {
-    const isTestMode = typeof window !== 'undefined' && (window as any).__PLAYWRIGHT_TEST__ === true;
-
-    if (
-      isTestMode &&
-      mode === 'multiple' &&
-      personsData?.data &&
-      personsData.data.length > 0 &&
-      selectedPersons.length === 0 &&
-      !autoSelectTriggeredRef.current // 防止多次触发
-    ) {
-      // 过滤掉已禁用的人员
-      const availablePersons = personsData.data.filter(
-        (person: DisabledPersonData) => !disabledIds.includes(person.id)
-      );
-      if (availablePersons.length > 0) {
-        const selectedPerson = availablePersons[0];
-        console.log('[测试自动化] 准备自动选择并确认:', selectedPerson.name, 'ID:', selectedPerson.id);
-        console.log('[测试自动化] onSelectRef.current 类型:', typeof onSelectRef.current);
-        console.log('[测试自动化] onOpenChangeRef.current 类型:', typeof onOpenChangeRef.current);
-
-        // 标记已触发,防止重复执行
-        autoSelectTriggeredRef.current = true;
-
-        // 测试环境:直接调用 onSelect 并关闭对话框
-        setTimeout(() => {
-          console.log('[测试自动化] 执行回调...');
-          if (typeof onSelectRef.current === 'function') {
-            console.log('[测试自动化] 调用 onSelect');
-            onSelectRef.current([selectedPerson]);
-          }
-          if (typeof onOpenChangeRef.current === 'function') {
-            console.log('[测试自动化] 调用 onOpenChange');
-            onOpenChangeRef.current(false);
-          }
-          console.log('[测试自动化] 回调执行完成');
-        }, 300);
-      }
-    }
-  }, [personsData, mode, disabledIds, selectedPersons.length]);
-
   // 重置选择器状态
   useEffect(() => {
     if (!open) {
@@ -158,7 +109,6 @@ const DisabledPersonSelector: React.FC<DisabledPersonSelectorProps> = ({
       setAreaSelection({});
       setShowBlacklistConfirm(false);
       setPendingSelection(null);
-      autoSelectTriggeredRef.current = false; // 重置自动选择 flag
     }
   }, [open]);
 

+ 19 - 29
web/tests/e2e/specs/cross-platform/order-create-sync.spec.ts

@@ -78,35 +78,25 @@ test.describe('跨端数据同步测试 - 后台创建订单到企业小程序',
         await adminPage.getByTestId('select-persons-button').click();
         console.debug('[后台] 点击选择残疾人按钮');
 
-        // 等待残疾人选择对话框出现 - 等待对话框标题
-        try {
-          await adminPage.waitForSelector('text=选择残疾人', { state: 'visible', timeout: 5000 });
-          console.debug('[后台] 选择残疾人对话框已打开');
-        } catch (_error) {
-          // 对话框可能没有打开,检查是否已经有残疾人
-          const stillNoPerson = await adminPage.getByText('残疾证号:', { exact: false }).count() === 0;
-          if (stillNoPerson) {
-            throw new Error('残疾人选择对话框未打开,且没有残疾人被选择');
-          }
-          console.debug('[后台] 残疾人可能已在选择对话框中自动选择');
-        }
-
-        // 如果对话框打开了,选择第一个残疾人
-        const dialogVisible = await adminPage.getByText('选择残疾人', { exact: true }).count() > 1;
-        if (dialogVisible) {
-          // 等待残疾人列表加载
-          await adminPage.waitForSelector('table tbody tr', { state: 'visible', timeout: TIMEOUTS.TABLE_LOAD });
-          await adminPage.waitForTimeout(1000);
-
-          // 选择第一个残疾人 - 点击第一行
-          await adminPage.locator('table tbody tr').first().click();
-          await adminPage.waitForTimeout(500);
-
-          // 点击确认选择按钮
-          await adminPage.getByTestId('confirm-batch-button').click();
-          await adminPage.waitForTimeout(1000);
-          console.debug('[后台] 已确认选择残疾人');
-        }
+        // 等待残疾人选择对话框出现
+        await adminPage.waitForSelector('text=选择残疾人', { state: 'visible', timeout: TIMEOUTS.DIALOG });
+        console.debug('[后台] 选择残疾人对话框已打开');
+
+        // 等待残疾人列表加载
+        await adminPage.waitForSelector('table tbody tr', { state: 'visible', timeout: TIMEOUTS.TABLE_LOAD });
+
+        // 选择第一个残疾人 - 使用复选框选择器
+        const firstCheckbox = adminPage.locator('[data-testid^="person-checkbox-"]').first();
+        await firstCheckbox.click();
+        console.debug('[后台] 已勾选第一个残疾人');
+
+        // 等待确认按钮变为可用状态
+        await adminPage.waitForSelector('[data-testid="confirm-batch-button"]:not([disabled])', { timeout: TIMEOUTS.SHORT });
+
+        // 点击确认选择按钮
+        await adminPage.getByTestId('confirm-batch-button').click();
+        await adminPage.waitForTimeout(TIMEOUTS.MEDIUM);
+        console.debug('[后台] 已确认选择残疾人');
       }
 
       // 等待 UI 稳定