|
|
@@ -78,6 +78,52 @@ async function loginTalentMini(page: any) {
|
|
|
console.debug('[人才小程序] 登录成功');
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * 遍历订单列表,找到第一个有关联人员的订单
|
|
|
+ * @param page - Playwright Page 对象
|
|
|
+ * @param orderPage - OrderManagementPage 实例
|
|
|
+ * @returns 订单名称和第一个人员名称
|
|
|
+ */
|
|
|
+async function findFirstOrderWithPersons(page: any, orderPage: OrderManagementPage): Promise<{ orderName: string; personName: string }> {
|
|
|
+ // 获取所有订单行
|
|
|
+ const allOrderRows = await page.locator('table tbody tr').all();
|
|
|
+ console.debug(`[订单查找] 总共 ${allOrderRows.length} 个订单,开始查找有人员的订单`);
|
|
|
+
|
|
|
+ for (let i = 0; i < allOrderRows.length; i++) {
|
|
|
+ const orderRow = allOrderRows[i];
|
|
|
+ const orderNameCell = orderRow.locator('td').first();
|
|
|
+ const orderName = await orderNameCell.textContent();
|
|
|
+
|
|
|
+ if (!orderName) continue;
|
|
|
+
|
|
|
+ const trimmedOrderName = orderName.trim();
|
|
|
+ console.debug(`[订单查找] 检查第 ${i + 1} 个订单: ${trimmedOrderName}`);
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 打开订单详情对话框
|
|
|
+ await orderPage.openDetailDialog(trimmedOrderName);
|
|
|
+
|
|
|
+ // 获取人员列表
|
|
|
+ const personList = await orderPage.getPersonListFromDetail();
|
|
|
+
|
|
|
+ // 关闭详情对话框
|
|
|
+ await orderPage.closeDetailDialog();
|
|
|
+
|
|
|
+ if (personList.length > 0 && personList[0].name) {
|
|
|
+ console.debug(`[订单查找] 找到有人员的订单: ${trimmedOrderName}, 人员: ${personList[0].name}`);
|
|
|
+ return { orderName: trimmedOrderName, personName: personList[0].name };
|
|
|
+ }
|
|
|
+
|
|
|
+ console.debug(`[订单查找] 订单 ${trimmedOrderName} 没有人员,继续查找`);
|
|
|
+ } catch (error) {
|
|
|
+ console.debug(`[订单查找] 检查订单 ${trimmedOrderName} 时出错: ${error}`);
|
|
|
+ // 继续检查下一个订单
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ throw new Error('未找到任何有关联人员的订单,无法进行测试');
|
|
|
+}
|
|
|
+
|
|
|
// 测试状态管理
|
|
|
interface TestState {
|
|
|
orderName: string | null;
|
|
|
@@ -93,18 +139,8 @@ const testState: TestState = {
|
|
|
newWorkStatus: WORK_STATUS.WORKING, // 默认测试:未入职 → 工作中
|
|
|
};
|
|
|
|
|
|
-test.describe('跨端数据同步测试 - 后台更新人员状态到双小程序', () => {
|
|
|
- // 在所有测试后清理测试数据
|
|
|
- test.afterAll(async () => {
|
|
|
- // 清理测试状态
|
|
|
- testState.orderName = null;
|
|
|
- testState.personName = null;
|
|
|
- testState.originalWorkStatus = null;
|
|
|
- console.debug('[清理] 测试状态已清理');
|
|
|
- });
|
|
|
-
|
|
|
- test.describe.serial('后台更新人员工作状态', () => {
|
|
|
- test('应该成功登录后台并更新人员工作状态', async ({ page: adminPage, testUsers }) => {
|
|
|
+test.describe.serial('跨端数据同步测试 - 后台更新人员状态到双小程序', () => {
|
|
|
+ test('应该成功登录后台并更新人员工作状态', async ({ page: adminPage, testUsers }) => {
|
|
|
// 记录开始时间
|
|
|
const startTime = Date.now();
|
|
|
|
|
|
@@ -118,36 +154,25 @@ test.describe('跨端数据同步测试 - 后台更新人员状态到双小程
|
|
|
await adminPage.waitForSelector('table tbody tr', { state: 'visible', timeout: TIMEOUTS.PAGE_LOAD_LONG });
|
|
|
console.debug('[后台] 导航到订单管理页面');
|
|
|
|
|
|
- // 3. 获取第一个订单的名称
|
|
|
- const orderPage = new OrderManagementPage(adminPage);
|
|
|
-
|
|
|
- // 等待表格数据完全加载
|
|
|
+ // 3. 等待表格数据完全加载
|
|
|
await adminPage.waitForLoadState('networkidle', { timeout: TIMEOUTS.TABLE_LOAD }).catch(() => {
|
|
|
console.debug('[后台] networkidle 等待超时,继续执行');
|
|
|
});
|
|
|
|
|
|
- const firstOrderRow = adminPage.locator('table tbody tr').first();
|
|
|
- const rowCount = await firstOrderRow.count();
|
|
|
-
|
|
|
- if (rowCount === 0) {
|
|
|
- throw new Error('订单列表为空,无法进行测试');
|
|
|
- }
|
|
|
-
|
|
|
- // 获取订单名称(假设在第二列)
|
|
|
- const orderNameCell = firstOrderRow.locator('td').nth(1);
|
|
|
- const orderName = await orderNameCell.textContent();
|
|
|
- if (!orderName) {
|
|
|
- throw new Error('无法获取订单名称');
|
|
|
- }
|
|
|
+ // 4. 创建 OrderManagementPage 实例
|
|
|
+ const orderPage = new OrderManagementPage(adminPage);
|
|
|
|
|
|
- testState.orderName = orderName.trim();
|
|
|
- console.debug(`[后台] 使用订单: ${testState.orderName}`);
|
|
|
+ // 5. 遍历订单列表,找到第一个有关联人员的订单
|
|
|
+ const { orderName, personName } = await findFirstOrderWithPersons(adminPage, orderPage);
|
|
|
+ testState.orderName = orderName;
|
|
|
+
|
|
|
+ console.debug(`[后台] 使用订单: ${orderName}, 人员: ${personName}`);
|
|
|
|
|
|
- // 4. 打开订单详情对话框
|
|
|
+ // 6. 重新打开订单详情对话框(findFirstOrderWithPersons 会关闭对话框)
|
|
|
await orderPage.openDetailDialog(testState.orderName);
|
|
|
console.debug('[后台] 打开订单详情对话框');
|
|
|
|
|
|
- // 6. 获取人员列表和第一个人员的当前状态
|
|
|
+ // 7. 获取人员列表和当前人员的状态
|
|
|
const personList = await orderPage.getPersonListFromDetail();
|
|
|
console.debug(`[后台] 订单中的人员数量: ${personList.length}`);
|
|
|
|
|
|
@@ -155,19 +180,16 @@ test.describe('跨端数据同步测试 - 后台更新人员状态到双小程
|
|
|
throw new Error('订单中没有关联人员,无法进行状态更新测试');
|
|
|
}
|
|
|
|
|
|
- // 获取第一个人员的信息
|
|
|
- const firstPerson = personList[0];
|
|
|
- const personName = firstPerson.name;
|
|
|
-
|
|
|
- if (!personName) {
|
|
|
- throw new Error('人员姓名为空,无法进行状态更新测试');
|
|
|
+ // 从人员列表中找到对应的人员(findFirstOrderWithPersons 返回的人员)
|
|
|
+ const currentPerson = personList.find(p => p.name === testState.personName);
|
|
|
+ if (!currentPerson) {
|
|
|
+ throw new Error(`未找到人员 "${testState.personName}"`);
|
|
|
}
|
|
|
|
|
|
- testState.personName = personName;
|
|
|
- console.debug(`[后台] 测试人员: ${personName}`);
|
|
|
+ console.debug(`[后台] 测试人员: ${testState.personName}`);
|
|
|
|
|
|
// 解析当前工作状态
|
|
|
- const currentStatusText = firstPerson.workStatus;
|
|
|
+ const currentStatusText = currentPerson.workStatus;
|
|
|
let currentStatus: WorkStatus;
|
|
|
|
|
|
// 根据状态文本映射到 WORK_STATUS 枚举
|
|
|
@@ -197,15 +219,15 @@ test.describe('跨端数据同步测试 - 后台更新人员状态到双小程
|
|
|
console.debug(`[后台] 将更新状态到: ${WORK_STATUS_LABELS[testState.newWorkStatus]}`);
|
|
|
|
|
|
// 7. 更新人员工作状态
|
|
|
- await orderPage.updatePersonWorkStatus(personName, testState.newWorkStatus);
|
|
|
- console.debug(`[后台] 已更新人员 "${personName}" 的工作状态`);
|
|
|
+ await orderPage.updatePersonWorkStatus(testState.personName, testState.newWorkStatus);
|
|
|
+ console.debug(`[后台] 已更新人员 "${testState.personName}" 的工作状态`);
|
|
|
|
|
|
// 8. 验证后台列表中状态更新正确(重新获取人员列表)
|
|
|
const updatedPersonList = await orderPage.getPersonListFromDetail();
|
|
|
- const updatedPerson = updatedPersonList.find(p => p.name === personName);
|
|
|
+ const updatedPerson = updatedPersonList.find(p => p.name === testState.personName);
|
|
|
|
|
|
if (!updatedPerson) {
|
|
|
- throw new Error(`更新后未找到人员 "${personName}"`);
|
|
|
+ throw new Error(`更新后未找到人员 "${testState.personName}"`);
|
|
|
}
|
|
|
|
|
|
const expectedStatusText = WORK_STATUS_LABELS[testState.newWorkStatus];
|
|
|
@@ -225,12 +247,8 @@ test.describe('跨端数据同步测试 - 后台更新人员状态到双小程
|
|
|
// 10. 关闭详情对话框
|
|
|
await orderPage.closeDetailDialog();
|
|
|
});
|
|
|
- });
|
|
|
|
|
|
- test.describe.serial('企业小程序验证人员状态同步', () => {
|
|
|
- test.use({ storageState: undefined }); // 确保使用新的浏览器上下文
|
|
|
-
|
|
|
- test('应该在企业小程序中显示更新后的人员状态', async ({ page: miniPage }) => {
|
|
|
+ test('应该在企业小程序中显示更新后的人员状态', async ({ page: miniPage }) => {
|
|
|
const { personName, newWorkStatus } = testState;
|
|
|
|
|
|
if (!personName) {
|
|
|
@@ -289,12 +307,8 @@ test.describe('跨端数据同步测试 - 后台更新人员状态到双小程
|
|
|
const syncEndTime = Date.now();
|
|
|
console.debug(`[企业小程序] 数据同步验证完成,时间戳: ${syncEndTime}`);
|
|
|
});
|
|
|
- });
|
|
|
-
|
|
|
- test.describe.serial('人才小程序验证人员状态同步', () => {
|
|
|
- test.use({ storageState: undefined }); // 确保使用新的浏览器上下文
|
|
|
|
|
|
- test('应该在人才小程序中显示更新后的人员状态', async ({ page: miniPage }) => {
|
|
|
+ test('应该在人才小程序中显示更新后的人员状态', async ({ page: miniPage }) => {
|
|
|
const { personName, newWorkStatus } = testState;
|
|
|
|
|
|
if (!personName) {
|
|
|
@@ -347,10 +361,8 @@ test.describe('跨端数据同步测试 - 后台更新人员状态到双小程
|
|
|
const syncEndTime = Date.now();
|
|
|
console.debug(`[人才小程序] 数据同步验证完成,时间戳: ${syncEndTime}`);
|
|
|
});
|
|
|
- });
|
|
|
|
|
|
- test.describe.serial('数据清理和恢复', () => {
|
|
|
- test('应该恢复人员到原始状态', async ({ page: adminPage, testUsers }) => {
|
|
|
+ test('应该在所有测试后恢复人员到原始状态', async ({ page: adminPage, testUsers }) => {
|
|
|
const { orderName, personName, originalWorkStatus } = testState;
|
|
|
|
|
|
if (!orderName || !personName || originalWorkStatus === null) {
|
|
|
@@ -371,7 +383,7 @@ test.describe('跨端数据同步测试 - 后台更新人员状态到双小程
|
|
|
console.debug('[清理] 打开订单详情对话框');
|
|
|
|
|
|
// 4. 恢复人员到原始状态
|
|
|
- await orderPage.updatePersonWorkStatus(personName, originalWorkStatus);
|
|
|
+ await orderPage.updatePersonWorkStatus(testState.personName, originalWorkStatus);
|
|
|
console.debug(`[清理] 已恢复人员 "${personName}" 到原始状态: ${WORK_STATUS_LABELS[originalWorkStatus]}`);
|
|
|
|
|
|
// 5. 验证恢复成功
|
|
|
@@ -393,5 +405,13 @@ test.describe('跨端数据同步测试 - 后台更新人员状态到双小程
|
|
|
await orderPage.closeDetailDialog();
|
|
|
console.debug('[清理] 测试数据恢复完成');
|
|
|
});
|
|
|
+
|
|
|
+ // 在所有测试后清理测试数据
|
|
|
+ test.afterAll(async () => {
|
|
|
+ // 清理测试状态
|
|
|
+ testState.orderName = null;
|
|
|
+ testState.personName = null;
|
|
|
+ testState.originalWorkStatus = null;
|
|
|
+ console.debug('[清理] 测试状态已清理');
|
|
|
});
|
|
|
});
|