import { type Locator, type Page } from '@playwright/test'; import { waitSpecifyApiLoad } from '@/utils/utils.js'; export class MarketingInviteGuestsPage { page: Page; subPages: { name: string; content?: { name: string; url?: string[] }[] }[]; $$tabItem: Locator; /** * 邀客管理页面 * @param page */ constructor(page: Page) { this.page = page; this.$$tabItem = this.page.locator('.tab_item'); this.subPages = [ { name: '邀客管理', }, { name: '返利方案', }, { name: '数据统计', }, { name: '设置', content: [ { name: '礼品设置', url: [] }, { name: '礼品分配', url: ['/user_present'] }, { name: '返利升级方案', url: [] }, { name: '设置', url: [] }, ], }, ]; } /** * 进入子页面 * @param subPageName 子页面名称 * - 邀客管理 * - 返利方案 * - 数据统计 * - 设置 */ gotoSubPage = async (subPageName: string) => { const subPage = this.subPages.find(e => e.name === subPageName); if (!subPage) { throw new Error(`${subPageName}不存在`); } const $tabItem = this.$$tabItem.filter({ hasText: subPageName }); await $tabItem.click(); }; /** * 进入设置子页面 * @param subPageName 子页面名称 * - 礼品设置 * - 礼品分配 * - 返利升级方案 * - 设置 */ gotoSettingSubPage = async (subPageName: string) => { const $tabItem = this.$$tabItem.filter({ hasText: subPageName }); const $tabItemDropDown = $tabItem.locator('.ant-dropdown-link'); const $dropDownSelected = this.page.getByRole('menuitem', { name: subPageName }); const settingSubPage = this.subPages.find(e => e.name === '设置')?.content?.find(e => e.name === subPageName); if (!settingSubPage) { throw new Error(`${subPageName}不存在`); } // 打开下拉 await $tabItemDropDown.click(); // 选择下拉选择 await Promise.all([$dropDownSelected.click(), waitSpecifyApiLoad(this.page, settingSubPage.url)]); // 确认选择成功 await $tabItemDropDown.filter({ hasText: subPageName }).waitFor(); }; }