|
|
@@ -210,12 +210,30 @@ async function selectDisabledPersonInAddDialog(
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+// 全局计数器,确保每个测试生成唯一的数据
|
|
|
+let testDataCounter = 0;
|
|
|
+
|
|
|
function generateUniqueTestData() {
|
|
|
const timestamp = Date.now();
|
|
|
+ const counter = ++testDataCounter;
|
|
|
const random = Math.floor(Math.random() * 10000);
|
|
|
+ // 生成18位身份证号:110101(地区码6位) + 19900101(出生日期8位) + XXX(顺序码3位) + X(校验码1位)
|
|
|
+ // 使用计数器和随机数作为顺序码,确保唯一性
|
|
|
+ const sequenceCode = String(counter).padStart(2, '0') + String(random).slice(0, 1);
|
|
|
+ const idCard = '110101' + '19900101' + sequenceCode + '1'; // 6+8+3+1=18位
|
|
|
return {
|
|
|
- orderName: '测试订单_' + timestamp + '_' + random,
|
|
|
- personName: '测试残疾人_' + timestamp + '_' + random,
|
|
|
+ orderName: '测试订单_' + timestamp + '_' + counter + '_' + random,
|
|
|
+ personName: '测试残疾人_' + timestamp + '_' + counter + '_' + random,
|
|
|
+ // 18位身份证号
|
|
|
+ idCard,
|
|
|
+ phone: '138' + String(counter).padStart(4, '0') + String(random).padStart(4, '0'),
|
|
|
+ gender: '男',
|
|
|
+ disabilityType: '视力残疾',
|
|
|
+ disabilityLevel: '一级',
|
|
|
+ disabilityId: '残疾证' + sequenceCode + String(timestamp).slice(-6),
|
|
|
+ idAddress: '北京市东城区测试地址' + timestamp + '_' + counter,
|
|
|
+ province: '北京市',
|
|
|
+ city: '北京市',
|
|
|
hireDate: '2025-01-15',
|
|
|
salary: 5000,
|
|
|
};
|
|
|
@@ -612,12 +630,31 @@ test.describe('订单人员关联测试', () => {
|
|
|
});
|
|
|
|
|
|
test.describe('管理工作状态', () => {
|
|
|
- test('应该能修改人员工作状态:未就业 → 待就业', async ({ orderManagementPage, page }) => {
|
|
|
- if (!createdPersonName || !createdPlatformName || !createdCompanyName) {
|
|
|
- test.skip(true, '缺少测试数据(残疾人、平台或公司)');
|
|
|
+ test('应该能修改人员工作状态:未就业 → 待就业', async ({ orderManagementPage, page, request }) => {
|
|
|
+ if (!createdPlatformName || !createdCompanyName) {
|
|
|
+ test.skip(true, '缺少测试数据(平台或公司)');
|
|
|
return;
|
|
|
}
|
|
|
+ // 为此测试创建唯一的残疾人数据
|
|
|
const testData = generateUniqueTestData();
|
|
|
+ const personData = {
|
|
|
+ name: testData.personName,
|
|
|
+ gender: testData.gender,
|
|
|
+ idCard: testData.idCard,
|
|
|
+ disabilityId: testData.disabilityId,
|
|
|
+ disabilityType: testData.disabilityType,
|
|
|
+ disabilityLevel: testData.disabilityLevel,
|
|
|
+ idAddress: testData.idAddress,
|
|
|
+ phone: testData.phone,
|
|
|
+ province: testData.province,
|
|
|
+ city: testData.city,
|
|
|
+ };
|
|
|
+ const createdPerson = await createDisabledPersonViaAPI(request, personData);
|
|
|
+ if (!createdPerson) {
|
|
|
+ test.skip(true, '无法创建残疾人数据');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ console.debug('已创建残疾人:', createdPerson.name, 'ID:', createdPerson.id);
|
|
|
await orderManagementPage.openCreateDialog();
|
|
|
await page.getByLabel(/订单名称|名称/).fill(testData.orderName);
|
|
|
|
|
|
@@ -676,7 +713,7 @@ test.describe('订单人员关联测试', () => {
|
|
|
}
|
|
|
|
|
|
await page.getByLabel(/预计开始日期|开始日期/).fill('2025-01-15');
|
|
|
- const hasPerson = await selectDisabledPersonInAddDialog(page, createdPersonName);
|
|
|
+ const hasPerson = await selectDisabledPersonInAddDialog(page, createdPerson.name);
|
|
|
if (!hasPerson) {
|
|
|
await orderManagementPage.cancelDialog();
|
|
|
test.skip(true, '没有可用的残疾人数据');
|
|
|
@@ -689,21 +726,66 @@ test.describe('订单人员关联测试', () => {
|
|
|
// 等待订单详情对话框加载完成
|
|
|
await page.waitForTimeout(500);
|
|
|
|
|
|
- // 直接使用 createdPersonName,因为我们知道创建订单时添加了这个人员
|
|
|
- // 跳过 getPersonListFromDetail,直接使用已知的人员名称
|
|
|
- await orderManagementPage.updatePersonWorkStatus(createdPersonName!, 'pending');
|
|
|
+ // 监听网络响应以捕获 400 错误的详细信息
|
|
|
+ const apiResponses: any[] = [];
|
|
|
+ page.on('response', async (response) => {
|
|
|
+ if (response.status() === 400) {
|
|
|
+ const url = response.url();
|
|
|
+ const contentType = response.headers()['content-type'];
|
|
|
+ if (contentType && contentType.includes('application/json')) {
|
|
|
+ try {
|
|
|
+ const body = await response.json();
|
|
|
+ apiResponses.push({ url, status: response.status(), body });
|
|
|
+ console.debug('API 400 错误详情:', JSON.stringify(body, null, 2));
|
|
|
+ } catch (e) {
|
|
|
+ const text = await response.text();
|
|
|
+ apiResponses.push({ url, status: response.status(), body: text });
|
|
|
+ console.debug('API 400 错误详情:', text);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 获取实际绑定的人员列表,使用第一个人员的名称
|
|
|
+ const personList = await orderManagementPage.getPersonListFromDetail();
|
|
|
+ await orderManagementPage.updatePersonWorkStatus(personList[0].name, 'pre_working');
|
|
|
+
|
|
|
+ // 如果有 400 错误,打印详细信息
|
|
|
+ if (apiResponses.length > 0) {
|
|
|
+ console.debug('捕获到的 API 错误:', JSON.stringify(apiResponses, null, 2));
|
|
|
+ }
|
|
|
+
|
|
|
const successToast = page.locator('[data-sonner-toast][data-type="success"]');
|
|
|
const hasSuccess = await successToast.count() > 0;
|
|
|
expect(hasSuccess).toBe(true);
|
|
|
await orderManagementPage.closeDetailDialog();
|
|
|
});
|
|
|
|
|
|
- test('应该能修改人员工作状态:待就业 → 已就业', async ({ orderManagementPage, page }) => {
|
|
|
- if (!createdPersonName || !createdPlatformName || !createdCompanyName) {
|
|
|
- test.skip(true, '缺少测试数据(残疾人、平台或公司)');
|
|
|
+ test('应该能修改人员工作状态:待就业 → 已就业', async ({ orderManagementPage, page, request }) => {
|
|
|
+ if (!createdPlatformName || !createdCompanyName) {
|
|
|
+ test.skip(true, '缺少测试数据(平台或公司)');
|
|
|
return;
|
|
|
}
|
|
|
+ // 为此测试创建唯一的残疾人数据
|
|
|
const testData = generateUniqueTestData();
|
|
|
+ const personData = {
|
|
|
+ name: testData.personName,
|
|
|
+ gender: testData.gender,
|
|
|
+ idCard: testData.idCard,
|
|
|
+ disabilityId: testData.disabilityId,
|
|
|
+ disabilityType: testData.disabilityType,
|
|
|
+ disabilityLevel: testData.disabilityLevel,
|
|
|
+ idAddress: testData.idAddress,
|
|
|
+ phone: testData.phone,
|
|
|
+ province: testData.province,
|
|
|
+ city: testData.city,
|
|
|
+ };
|
|
|
+ const createdPerson = await createDisabledPersonViaAPI(request, personData);
|
|
|
+ if (!createdPerson) {
|
|
|
+ test.skip(true, '无法创建残疾人数据');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ console.debug('已创建残疾人:', createdPerson.name, 'ID:', createdPerson.id);
|
|
|
await orderManagementPage.openCreateDialog();
|
|
|
await page.getByLabel(/订单名称|名称/).fill(testData.orderName);
|
|
|
|
|
|
@@ -762,7 +844,7 @@ test.describe('订单人员关联测试', () => {
|
|
|
}
|
|
|
|
|
|
await page.getByLabel(/预计开始日期|开始日期/).fill('2025-01-15');
|
|
|
- const hasPerson = await selectDisabledPersonInAddDialog(page, createdPersonName);
|
|
|
+ const hasPerson = await selectDisabledPersonInAddDialog(page, createdPerson.name);
|
|
|
if (!hasPerson) {
|
|
|
await orderManagementPage.cancelDialog();
|
|
|
test.skip(true, '没有可用的残疾人数据');
|
|
|
@@ -772,19 +854,38 @@ test.describe('订单人员关联测试', () => {
|
|
|
await orderManagementPage.waitForDialogClosed();
|
|
|
await orderManagementPage.openPersonManagementDialog(testData.orderName);
|
|
|
const personList = await orderManagementPage.getPersonListFromDetail();
|
|
|
- await orderManagementPage.updatePersonWorkStatus(personList[0].name, 'employed');
|
|
|
+ await orderManagementPage.updatePersonWorkStatus(personList[0].name, 'working');
|
|
|
const successToast = page.locator('[data-sonner-toast][data-type="success"]');
|
|
|
const hasSuccess = await successToast.count() > 0;
|
|
|
expect(hasSuccess).toBe(true);
|
|
|
await orderManagementPage.closeDetailDialog();
|
|
|
});
|
|
|
|
|
|
- test('应该能修改人员工作状态:已就业 → 已离职', async ({ orderManagementPage, page }) => {
|
|
|
- if (!createdPersonName || !createdPlatformName || !createdCompanyName) {
|
|
|
- test.skip(true, '缺少测试数据(残疾人、平台或公司)');
|
|
|
+ test('应该能修改人员工作状态:已就业 → 已离职', async ({ orderManagementPage, page, request }) => {
|
|
|
+ if (!createdPlatformName || !createdCompanyName) {
|
|
|
+ test.skip(true, '缺少测试数据(平台或公司)');
|
|
|
return;
|
|
|
}
|
|
|
+ // 为此测试创建唯一的残疾人数据
|
|
|
const testData = generateUniqueTestData();
|
|
|
+ const personData = {
|
|
|
+ name: testData.personName,
|
|
|
+ gender: testData.gender,
|
|
|
+ idCard: testData.idCard,
|
|
|
+ disabilityId: testData.disabilityId,
|
|
|
+ disabilityType: testData.disabilityType,
|
|
|
+ disabilityLevel: testData.disabilityLevel,
|
|
|
+ idAddress: testData.idAddress,
|
|
|
+ phone: testData.phone,
|
|
|
+ province: testData.province,
|
|
|
+ city: testData.city,
|
|
|
+ };
|
|
|
+ const createdPerson = await createDisabledPersonViaAPI(request, personData);
|
|
|
+ if (!createdPerson) {
|
|
|
+ test.skip(true, '无法创建残疾人数据');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ console.debug('已创建残疾人:', createdPerson.name, 'ID:', createdPerson.id);
|
|
|
await orderManagementPage.openCreateDialog();
|
|
|
await page.getByLabel(/订单名称|名称/).fill(testData.orderName);
|
|
|
|
|
|
@@ -843,7 +944,7 @@ test.describe('订单人员关联测试', () => {
|
|
|
}
|
|
|
|
|
|
await page.getByLabel(/预计开始日期|开始日期/).fill('2025-01-15');
|
|
|
- const hasPerson = await selectDisabledPersonInAddDialog(page, createdPersonName);
|
|
|
+ const hasPerson = await selectDisabledPersonInAddDialog(page, createdPerson.name);
|
|
|
if (!hasPerson) {
|
|
|
await orderManagementPage.cancelDialog();
|
|
|
test.skip(true, '没有可用的残疾人数据');
|