59 lines
1.5 KiB
JavaScript
59 lines
1.5 KiB
JavaScript
import { expect } from '@playwright/test';
|
|
|
|
export class HomeNavigation {
|
|
/**
|
|
* @param {import("@playwright/test").Page} page
|
|
*/
|
|
constructor(page) {
|
|
this.page = page;
|
|
this.$moduleList = this.page.locator('.left_box .link_item');
|
|
this.pages = {
|
|
cash: '收银',
|
|
appointment: '预约',
|
|
member: '顾客',
|
|
flow: '流水',
|
|
stock: '库存',
|
|
management: '目标',
|
|
marketing: '营销',
|
|
report: '报表',
|
|
setting: '设置',
|
|
other: '其他',
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 跳转到对应模块
|
|
* @param {string} pageName 模块名称
|
|
* - cash-收银
|
|
* - appointment-预约
|
|
* - member-顾客
|
|
* - flow-流水
|
|
* - stock-库存
|
|
* - management-目标
|
|
* - marketing-营销
|
|
* - report-报表
|
|
* - setting-设置
|
|
* - other-其他
|
|
*/
|
|
gotoModule = async (pageName) => {
|
|
const moduleName = this.pages[pageName];
|
|
|
|
if (!moduleName) {
|
|
throw new Error(`Page ${pageName} does not exist`);
|
|
}
|
|
// 模块定位器
|
|
const moduleLocator = this.$moduleList.filter({ hasText: moduleName });
|
|
// 当前模块选中提示定位器
|
|
const activeLocator = moduleLocator.locator('.active_arrow');
|
|
|
|
await expect(moduleLocator).toBeInViewport();
|
|
|
|
await expect(async () => {
|
|
if (!(await activeLocator.isVisible())) {
|
|
await moduleLocator.click({ clickCount: 1 });
|
|
}
|
|
await expect(activeLocator).toBeInViewport();
|
|
}).toPass({ timeout: 30_000 });
|
|
};
|
|
}
|