优化代码

This commit is contained in:
LingandRX 2024-12-29 22:04:57 +08:00
parent 28430d0c9b
commit c9a8014c09
8 changed files with 81 additions and 67 deletions

View File

@ -1,6 +1,6 @@
// @ts-check
import { test, expect } from '@/fixtures/boss_common.js'; //使用公共套件
import { Feature, Employees, ProjectName, CardType, Coupons } from '@/fixtures/userconfig.js';
import { Feature, Employees, ProjectName, CardType, Coupons } from '@/common/userconfig';
import { decodeQR, KeepOnlyNumbers } from '@/utils/utils.js';
import { faker } from '@faker-js/faker/locale/zh_CN';
import path from 'path';

View File

@ -3,7 +3,7 @@ import { test, expect } from '@/fixtures/boss_common.js';
import { faker } from '@faker-js/faker/locale/zh_CN';
import { Customer } from '@/utils/customer';
import { waitSpecifyApiLoad, convertAmountText, waitStable } from '@/utils/utils.js';
import { Employees, ProjectName } from '@/fixtures/userconfig.js';
import { Employees, ProjectName } from '@/common/userconfig';
import path from 'path';
import fs from 'fs';
import { HomeNavigation } from '@/pages/homeNavigationPage.js';
@ -11,6 +11,8 @@ import { CustomerPage } from '@/pages/customer/customerPage.js';
test.describe('顾客通用', () => {
test.describe('快捷查询', () => {
test('精准查询', async ({ page, homeNavigation, createCustomCustomer, customerPage }) => {
let historySet = new Set();
const customer = new Customer(1, 1, {
archive: 'ABC' + faker.string.alpha(3),
employees: [
@ -20,39 +22,7 @@ test.describe('顾客通用', () => {
},
],
});
/**@type {import('playwright').BrowserContext} */
let browserContext;
/**@type {import('playwright').Page} */
let page;
let homeNavigation;
let customerPage;
test.beforeAll(async ({ browser, baseURL }) => {
browserContext = await browser.newContext();
page = await browserContext.newPage();
if (!baseURL) throw new Error('baseURL is required');
await page.goto(baseURL);
await page.waitForLoadState('networkidle');
await page.reload();
await page.getByRole('button', { name: /开\s单/ }).waitFor();
homeNavigation = new HomeNavigation(page);
customerPage = new CustomerPage(page);
await homeNavigation.gotoModule('顾客');
await customerPage.createCustomer(customer);
});
test.afterAll(async () => {
homeNavigation = new HomeNavigation(page);
customerPage = new CustomerPage(page);
await homeNavigation.gotoModule('顾客');
await customerPage.setInvalidCustomer(customer);
await page.close();
await browserContext.close();
});
test('精准查询', async ({ page, homeNavigation, customerPage }) => {
/**@type{Set<String>} 搜索历史 */
let historySet = new Set();
await createCustomCustomer(customer);
// 去创建顾客
const username = customer.username;
const phone = customer.phone;
@ -101,7 +71,18 @@ test.describe('顾客通用', () => {
});
});
test('顾客概要', async ({ page, homeNavigation, customerPage, tablePage }) => {
test('顾客概要', async ({ page, homeNavigation, createCustomCustomer, customerPage, tablePage }) => {
const customer = new Customer(1, 1, {
archive: 'ABC' + faker.string.alpha(3),
employees: [
{
name: '周慧',
level: '咨询师',
},
],
});
await createCustomCustomer(customer);
// 第一个顾客
const $firstCustomer = tablePage.fixedLeftTable.locator('tr td:nth-child(2)').locator('.name ').first();
await test.step('选择部门一,查看顾客详情', async () => {
@ -138,7 +119,18 @@ test.describe('顾客通用', () => {
});
});
test('顾客分配', async ({ page, homeNavigation, customerPage, tablePage }) => {
test('顾客分配', async ({ page, homeNavigation, createCustomCustomer, customerPage, tablePage }) => {
const customer = new Customer(1, 1, {
archive: 'ABC' + faker.string.alpha(3),
employees: [
{
name: '周慧',
level: '咨询师',
},
],
});
await createCustomCustomer(customer);
// 第一个顾客
const $firstCustomer = tablePage.fixedLeftTable.locator('tr td:nth-child(2)').locator('.name ').first();
await test.step('顾客分配', async () => {
@ -163,7 +155,18 @@ test.describe('顾客通用', () => {
});
});
test('顾客动态', async ({ page, homeNavigation, customerPage, tablePage }) => {
test('顾客动态', async ({ page, homeNavigation, createCustomCustomer, customerPage, tablePage }) => {
const customer = new Customer(1, 1, {
archive: 'ABC' + faker.string.alpha(3),
employees: [
{
name: '周慧',
level: '咨询师',
},
],
});
await createCustomCustomer(customer);
// 第一个顾客
const $firstCustomer = tablePage.fixedLeftTable.locator('tr td:nth-child(2)').locator('.name ').first();
await test.step('选择部门一,查看顾客详情', async () => {
@ -195,7 +198,18 @@ test.describe('顾客通用', () => {
});
});
test('顾客分析', async ({ page, homeNavigation, customerPage, tablePage }) => {
test('顾客分析', async ({ page, homeNavigation, createCustomCustomer, customerPage, tablePage }) => {
const customer = new Customer(1, 1, {
archive: 'ABC' + faker.string.alpha(3),
employees: [
{
name: '周慧',
level: '咨询师',
},
],
});
await createCustomCustomer(customer);
// 第一个顾客
const $firstCustomer = tablePage.fixedLeftTable.locator('tr td:nth-child(2)').locator('.name ').first();
await test.step('选择部门一,查看顾客详情', async () => {

View File

@ -1,7 +1,7 @@
// @ts-check
import { expect, test } from '@/fixtures/boss_common.js';
import { staffData } from '@/common/staff';
import { Employees } from '@/fixtures/userconfig.js';
import { Employees } from '@/common/userconfig';
import { Customer } from '@/utils/customer';
import { KeepOnlyNumbers } from '@/utils/utils.js';

View File

@ -2,7 +2,7 @@
import { faker } from '@faker-js/faker/locale/zh_CN';
import { expect, test } from '@/fixtures/boss_common.js';
import { CleanPunctuation, getListIndexForTargetElement, KeepOnlyNumbers } from '@/utils/utils.js';
import { ProjectName } from '@/fixtures/userconfig.js';
import { ProjectName } from '@/common/userconfig';
test.describe('出入库管理', () => {
test.describe('入库单', () => {
@ -3529,7 +3529,7 @@ test.describe.serial('盘点', () => {
let ProductMargin;
// 获取单号的ID
let billId;
let billId: string;
let billNo: string;
await test.step('记录各自批次数量', async () => {

View File

@ -4,7 +4,7 @@ import { expect, test } from '@/fixtures/merchantFixture.js';
import { faker } from '@faker-js/faker/locale/zh_CN';
import { Customer } from '@/utils/customer';
import { KeepOnlyNumbers, waitSpecifyApiLoad } from '@/utils/utils.js';
import { CardType, Employees, ProjectName } from '@/fixtures/userconfig.js';
import { CardType, Employees, ProjectName } from '@/common/userconfig';
test.describe('业绩明细表', () => {
test('数据校验', async ({ page, createCustomer, homeNavigation, reportPage, customerPage }) => {

View File

@ -5,7 +5,7 @@ import { Customer } from '@/utils/customer';
import { KeepOnlyNumbers } from '@/utils/utils.js';
import fs from 'fs';
import path from 'path';
import { Employees, ProjectName } from '@/fixtures/userconfig.js';
import { Employees, ProjectName } from '@/common/userconfig';
import { staffData } from '@/common/staff';
test.describe('营业记录', () => {

View File

@ -1,6 +1,6 @@
// @ts-check
import { test, expect } from '@/fixtures/staff_common.js';
import { Employees } from '@/fixtures/userconfig.js';
import { Employees } from '@/common/userconfig';
test.describe('目标-目标设置', () => {
test('门店设置一店', async ({ page, baseURL, numberInput }) => {