diff --git a/tests/pages/appointmentPage.ts b/tests/pages/appointmentPage.ts index 746f5d4..7557e63 100644 --- a/tests/pages/appointmentPage.ts +++ b/tests/pages/appointmentPage.ts @@ -5,7 +5,7 @@ import { getNextAppointmentTime } from '@/utils/timeUtils'; /** * 预约状态颜色 */ -type colorStatus = { +type status = { name: string; color: string; quantity: number; @@ -30,11 +30,11 @@ export class AppointmentPage { $customer: Locator; $occupy: Locator; appointmentStatus: { - NORMAL: colorStatus; - CONSULT: colorStatus; - BILL: colorStatus; - SETTLED: colorStatus; - EXPIRED: colorStatus; + NORMAL: status; + CONSULT: status; + BILL: status; + SETTLED: status; + EXPIRED: status; }; appointmentOperation: typeof AppointmentOperation; diff --git a/tests/touch/boss_appointment.spec.ts b/tests/touch/boss_appointment.spec.ts index ded7471..a737418 100644 --- a/tests/touch/boss_appointment.spec.ts +++ b/tests/touch/boss_appointment.spec.ts @@ -128,7 +128,10 @@ test('占用预约单元格', async ({ await appointmentPage.operationAppointment(AppointmentOperation.ADD_REMARK); // 进行添加备注,确认添加备注成功 await page.getByPlaceholder('请输入备注').fill(remark); - await popupContent.confirm(); + await Promise.all([ + page.waitForResponse(res => res.url().includes('/reservation_num') && res.status() === 200), + popupContent.confirm(), + ]); // 判断备注后的单元格存在 await expect($$occupy.filter({ hasText: remark })).toBeVisible(); }); @@ -139,10 +142,11 @@ test('占用预约单元格', async ({ // 取消占用 await appointmentPage.operationAppointment(AppointmentOperation.CANCEL_OCCUPY); // 判断取消占用成功 - await expect(async () => { - await popupContent.confirm(); - await expect($$occupy.filter({ hasText: remark })).not.toBeVisible({ timeout: 1500 }); - }).toPass(); + await Promise.all([ + page.waitForResponse(res => res.url().includes('/reservation_num') && res.status() === 200), + popupContent.confirm(), + ]); + await expect($$occupy.filter({ hasText: remark })).not.toBeVisible(); }); await test.step('取消占用后,能够进行预约', async () => { @@ -185,15 +189,14 @@ test.describe('预约状态', () => { const $time = page.locator('.times_table td').filter({ hasText: appointmentTime }); // 员工定位器 const $employee = page.locator('.room_table .tr .name_th').filter({ hasText: employee.name }); - - // 获取设置的预约状态 - let appointmentStatusSetting; - await test.step('获取预约状态', async () => { - await homeNavigation.gotoModule('预约'); - appointmentStatusSetting = await appointmentPage.getAppointmentStatusSetting(); - }); + // 顾客预约定位器 + const $customerAppointment = page + .locator('.a_userInfo') + .filter({ hasText: customer.phone }) + .filter({ hasText: customer.username }); await test.step('进行创建预约', async () => { + await homeNavigation.gotoModule('预约'); await $time.scrollIntoViewIfNeeded(); await $employee.scrollIntoViewIfNeeded(); // 打开预约单元格,进行预约 @@ -201,68 +204,63 @@ test.describe('预约状态', () => { await appointmentPage.operationAppointment(AppointmentOperation.ADD_APPOINT); await customerPage.searchCustomer(customer.phone); await customerPage.selectSearchCustomer(customer.phone); - await expect.soft(page.locator('.newAppointmentContent .header_title')).toContainText('新建预约'); - await expect(page.locator('.newAppointmentContent .content .phone')).toContainText(customer.phone); + await expect(page.locator('div.name_box div.phone')).toContainText(customer.phone); + await expect(page.locator('div.user_box')).toContainText(employee.name); await page.getByRole('button', { name: '确认新建' }).click(); - await expect(page.locator('.ant-message', { hasText: '预约成功' })).toBeVisible(); + await expect($customerAppointment).toBeVisible(); }); await test.step('判断预约,状态为未到店', async () => { - const { customerColor, customerStatus } = await appointmentPage.getCustomerAppointmentStatus(customer); - // 进入未到店状态 - expect.soft(customerColor).toEqual(appointmentStatusSetting.NORMAL.color); - expect(customerStatus).toEqual(appointmentStatusSetting.NORMAL.name); + await appointmentPage.openAppointmentDetail(customer.phone); + await expect(page.locator('div.state')).toContainText('未到店'); }); await test.step('进行挂单,状态为已开单', async () => { - await page - .locator('.a_userInfo', { hasText: customer.username }) - .first() - .locator('.user_name_info') - .click(); // 预约进行挂单 await page.getByRole('button', { name: '到店开单' }).click(); await page - .locator('.project_list') + .locator('div.project_list') .filter({ hasText: project.name }) .filter({ hasText: project.no }) .click(); - await page.locator('.hold_bill', { hasText: '挂单' }).click(); - await expect(page.locator('.ant-message', { hasText: '挂单成功' })).toBeVisible(); + await Promise.all([ + page.waitForResponse(res => res.url().includes('/bill') && res.status() === 200), + page.locator('div.hold_bill', { hasText: '挂单' }).click(), + ]); await homeNavigation.gotoModule('预约'); - // 获取当前预约的状态 - const { customerColor, customerStatus } = await appointmentPage.getCustomerAppointmentStatus(customer); - // 进入未到店状态 - expect.soft(customerColor).toEqual(appointmentStatusSetting.BILL.color); - expect(customerStatus).toEqual(appointmentStatusSetting.BILL.name); + await appointmentPage.openAppointmentDetail(customer.phone); + await expect(page.locator('div.state')).toContainText('已开单'); }); await test.step('进行结算,状态为已结算', async () => { - await page - .locator('.a_userInfo', { hasText: customer.username }) - .first() - .locator('.user_name_info') - .click(); await page.getByRole('button', { name: /取\s单/ }).click(); - await page.locator('.pay_btn', { hasText: /结\s算/ }).click(); + await page.locator('div.pay_btn', { hasText: /结\s算/ }).click(); // 取消推送消费提醒和结算签字 await page.getByLabel('推送消费提醒').uncheck(); await page.getByLabel('结算签字').uncheck(); - await page.locator('.paytype .paymentInfoItem', { hasText: '现金' }).click(); + await page.locator('div.paymentInfoItem', { hasText: '现金' }).click(); // 结算 const [response] = await Promise.all([ - page.waitForResponse(async res => { - return res.url().includes('/bill') && (await res.json()).code === 'SUCCESS'; - }), + page.waitForResponse(res => res.url().includes('/bill') && res.status() === 200 && res.request().method() === 'POST'), page.getByRole('button', { name: /结\s算/ }).click(), ]); - const responseBody = await response.json(); - const billNo = responseBody?.content?.billNo; - expect(billNo).not.toBeNull(); + const billNo = (await response.json())?.content?.billNo; billSet.add(billNo); + await page.waitForResponse(async res => { + if ( + res.url().includes('/bill_status') && + res.status() === 200 && + res.request().method() === 'GET' + ) { + const responseBody = await res.json(); // 等待解析 JSON + return responseBody?.content?.status === 'SETTLED'; + } + return false; + }); + // 处理结算后的弹窗 await page.addLocatorHandler(page.getByRole('button', { name: '我知道了' }), async () => { await page.getByRole('button', { name: '我知道了' }).click(); @@ -273,11 +271,8 @@ test.describe('预约状态', () => { // 进入预约模块 await homeNavigation.gotoModule('预约'); - // 获取当前创建预约的状态 - const { customerColor, customerStatus } = await appointmentPage.getCustomerAppointmentStatus(customer); - // 进入未到店状态 - expect.soft(customerColor).toEqual(appointmentStatusSetting.SETTLED.color); - expect(customerStatus).toEqual(appointmentStatusSetting.SETTLED.name); + await appointmentPage.openAppointmentDetail(customer.phone); + await expect(page.locator('div.state')).toContainText('已结算'); }); }); }); \ No newline at end of file