db8cdf3360
- 合入 weiyuan 新功能前端:分佣 V2 / 伙伴工作台、智能路由、企业资金与分析、官网设置与预约演示等, semi-ui 已全部迁移到 antd 6 / @/components/ui,不重新引入 Semi - 分佣二级菜单与页头去重、伙伴入口探测(企业伙伴走企业中心「企业分佣」)、超管侧栏入口恢复 - 适配层 DatePicker / TimePicker 统一 onChange(Date|Date[]|null, 文本) 契约;生产构建剔除调试日志 - 图片链接刷新:同任务请求复用、后台刷新不弹全局错误、离页停止批量请求 - 恢复 bun.lock(与 package-lock.json 共存);docs 规范与 CHANGELOG 更新 - 停止跟踪 .env.playwright.local(本地登录凭据,已加入 .gitignore)
942 lines
33 KiB
JavaScript
942 lines
33 KiB
JavaScript
/** Actual commission UI regression, isolated API fixtures and no remote traffic.
|
|
* PLAYWRIGHT_MODULE: existing playwright/index.mjs; COMMISSION_QA_OUTPUT: artifacts.
|
|
* Browser plugin is unavailable; uses existing Playwright/Chromium, no installation.
|
|
*/
|
|
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import os from 'node:os';
|
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
|
|
const webRoot = path.resolve(
|
|
path.dirname(fileURLToPath(import.meta.url)),
|
|
'..',
|
|
);
|
|
process.chdir(webRoot);
|
|
const out =
|
|
process.env.COMMISSION_QA_OUTPUT ||
|
|
fs.mkdtempSync(path.join(os.tmpdir(), 'commission-qa-'));
|
|
fs.mkdirSync(out, { recursive: true });
|
|
const { chromium } = await import(
|
|
process.env.PLAYWRIGHT_MODULE
|
|
? pathToFileURL(path.resolve(process.env.PLAYWRIGHT_MODULE)).href
|
|
: 'playwright'
|
|
);
|
|
const { createServer, loadConfigFromFile } = await import(
|
|
pathToFileURL(path.join(webRoot, 'node_modules/vite/dist/node/index.js')).href
|
|
);
|
|
const { config: base } = await loadConfigFromFile(
|
|
{ command: 'serve', mode: 'development' },
|
|
path.join(webRoot, 'vite.config.js'),
|
|
);
|
|
const entry = path
|
|
.join(webRoot, 'src/__commission-qa.jsx')
|
|
.replaceAll('\\', '/');
|
|
const server = await createServer({
|
|
...base,
|
|
configFile: false,
|
|
root: webRoot,
|
|
cacheDir: path.join(out, 'vite-cache'),
|
|
optimizeDeps: { ...base.optimizeDeps, force: false },
|
|
server: { host: '127.0.0.1', port: 0, strictPort: false, proxy: {} },
|
|
plugins: [
|
|
...base.plugins,
|
|
{
|
|
name: 'commission-adjustment-qa',
|
|
configureServer(vite) {
|
|
vite.middlewares.use('/api/', (_req, res) => {
|
|
res.statusCode = 503;
|
|
res.end('QA requires intercepted API');
|
|
});
|
|
vite.middlewares.use('/__commission-qa.html', async (_req, res) => {
|
|
res.setHeader('Content-Type', 'text/html');
|
|
res.end(
|
|
await vite.transformIndexHtml(
|
|
'/__commission-qa.html',
|
|
'<html><head><title>Commission adjustment QA</title></head><body><div id="root"></div><script type="module" src="/__commission-qa.jsx"></script></body></html>',
|
|
),
|
|
);
|
|
});
|
|
},
|
|
resolveId(id) {
|
|
if (id === '/__commission-qa.jsx') return entry;
|
|
},
|
|
load(id) {
|
|
if (id === entry)
|
|
return `
|
|
import '/src/styles/tokens.css';import '/src/index.css';import '/src/styles/org.css';
|
|
import React from 'react';import {createRoot} from 'react-dom/client';
|
|
import i18n from 'i18next';import {initReactI18next} from 'react-i18next';
|
|
import {MemoryRouter, Routes, Route, useLocation, useNavigate} from 'react-router-dom';
|
|
import {StatusContext} from '/src/context/Status/index.jsx';import {UserContext} from '/src/context/User/index.jsx';
|
|
import CommissionV2 from '/src/pages/CommissionV2/index.jsx';
|
|
import Organization from '/src/pages/Organization/index.jsx';
|
|
import {OrgProvider} from '/src/context/Org/index.jsx';
|
|
import {SettlementDialog} from '/src/pages/CommissionV2/operations.jsx';
|
|
i18n.use(initReactI18next).init({lng:'zh',fallbackLng:'zh',resources:{zh:{translation:{}}},interpolation:{escapeValue:false}});
|
|
const user={id:1,role:100,username:'qa'};
|
|
const view=new URLSearchParams(location.search).get('view');
|
|
const section=new URLSearchParams(location.search).get('section');
|
|
function RouteProbe(){const route=useLocation();window.__qaNavigate=useNavigate();return <output hidden data-qa-route={route.pathname+route.search}/>;}
|
|
function SettlementTest(){const [operation,setOperation]=React.useState(null);return <><button onClick={()=>setOperation({kind:'fee'})}>打开测试结算</button><SettlementDialog operation={operation} statement={{id:1,fee_uyuan:0}} items={[]} mutateJSON={async()=>{}} onClose={()=>setOperation(null)} onSaved={()=>{}}/></>}
|
|
createRoot(document.getElementById('root')).render(<MemoryRouter initialEntries={[view==='org'?'/org/commission'+(section?'?view='+section:''):view==='personal'?'/console/my-commission':'/console/commission'+location.search]}><RouteProbe/><StatusContext.Provider value={[{status:{commission_partner_portal_enabled:true}},()=>{}]}><UserContext.Provider value={[{user,authChecking:false},()=>{}]}><OrgProvider>{view==='org'?<Routes><Route path='/org/*' element={<Organization/>}/></Routes>:view==='settlement'?<SettlementTest/>:<CommissionV2/>}</OrgProvider></UserContext.Provider></StatusContext.Provider></MemoryRouter>);
|
|
`;
|
|
},
|
|
},
|
|
],
|
|
});
|
|
await server.listen();
|
|
const origin = `http://127.0.0.1:${server.httpServer.address().port}`;
|
|
console.log('QA origin:', origin, 'Artifacts:', out);
|
|
let browser;
|
|
try {
|
|
browser = await chromium.launch({ headless: true });
|
|
} catch (error) {
|
|
await server.close();
|
|
throw error;
|
|
}
|
|
const results = [];
|
|
let activeState;
|
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
function deferred() {
|
|
let resolve;
|
|
const promise = new Promise((done) => {
|
|
resolve = done;
|
|
});
|
|
return { promise, resolve };
|
|
}
|
|
async function until(check, message) {
|
|
const end = Date.now() + 12000;
|
|
while (!(await check())) {
|
|
if (Date.now() > end) throw new Error(message || 'Timed out');
|
|
await sleep(30);
|
|
}
|
|
}
|
|
const now = Math.floor(Date.now() / 1000);
|
|
const tiers = [
|
|
{
|
|
id: 2,
|
|
config_id: 1,
|
|
name: '企业专用最新档',
|
|
source_type: 'channel',
|
|
source_id: 10,
|
|
channel_ids: [10],
|
|
model_names: [],
|
|
tier_key: 'G1',
|
|
rate_bps: 1000,
|
|
effective_from: now - 30,
|
|
effective_to: 0,
|
|
},
|
|
{
|
|
id: 3,
|
|
config_id: 3,
|
|
name: '真正停用档',
|
|
source_type: 'channel',
|
|
source_id: 11,
|
|
channel_ids: [11],
|
|
model_names: [],
|
|
tier_key: 'G2',
|
|
rate_bps: 500,
|
|
effective_from: now - 100,
|
|
effective_to: now - 10,
|
|
},
|
|
{
|
|
id: 4,
|
|
config_id: 4,
|
|
name: '明日生效档',
|
|
source_type: 'model',
|
|
source_id: 0,
|
|
channel_ids: [],
|
|
model_names: ['future-model'],
|
|
tier_key: 'G3',
|
|
rate_bps: 700,
|
|
effective_from: now + 86400,
|
|
effective_to: 0,
|
|
},
|
|
];
|
|
const oldTier = {
|
|
...tiers[0],
|
|
id: 1,
|
|
name: '不应显示的历史档',
|
|
effective_from: now - 200,
|
|
effective_to: now - 30,
|
|
};
|
|
async function setup(view = 'partners', width = 1500, section = '') {
|
|
const context = await browser.newContext({
|
|
viewport: { width, height: 1050 },
|
|
});
|
|
await context.addInitScript(() => {
|
|
localStorage.setItem('current_org_id', '101');
|
|
localStorage.setItem(
|
|
'user',
|
|
JSON.stringify({ id: 1, role: 100, username: 'qa' }),
|
|
);
|
|
});
|
|
const page = await context.newPage();
|
|
page.setDefaultTimeout(12000);
|
|
page.setDefaultNavigationTimeout(120000);
|
|
const state = {
|
|
context,
|
|
page,
|
|
requests: [],
|
|
writes: [],
|
|
errors: [],
|
|
mode: '',
|
|
delays: {},
|
|
orgDelays: {},
|
|
};
|
|
activeState = state;
|
|
page.on('pageerror', (error) => state.errors.push(error.message));
|
|
page.on('dialog', (dialog) => dialog.accept());
|
|
await page.route('**/*', async (route) => {
|
|
const req = route.request();
|
|
const url = new URL(req.url());
|
|
if (url.origin !== origin) {
|
|
await route.abort();
|
|
return;
|
|
}
|
|
if (!url.pathname.startsWith('/api/')) {
|
|
await route.continue();
|
|
return;
|
|
}
|
|
state.requests.push({
|
|
path: url.pathname,
|
|
query: Object.fromEntries(url.searchParams),
|
|
method: req.method(),
|
|
headers: req.headers(),
|
|
});
|
|
let data = [];
|
|
if (req.method() !== 'GET') {
|
|
state.writes.push({
|
|
path: url.pathname,
|
|
body: req.postDataJSON(),
|
|
headers: req.headers(),
|
|
});
|
|
data = { id: 91 };
|
|
} else if (url.pathname.startsWith('/api/org/commission/')) {
|
|
const id = Number(req.headers()['x-org-id']);
|
|
if (state.orgDelays[id]) await state.orgDelays[id];
|
|
if (/\/statements\/\d+$/.test(url.pathname) && state.detailDelay)
|
|
await state.detailDelay;
|
|
const statement = {
|
|
id: id * 10,
|
|
partner_id: id,
|
|
statement_month: '2026-11',
|
|
status: 'pending_confirmation',
|
|
payable_uyuan: 1000000,
|
|
commission_uyuan: 1000000,
|
|
};
|
|
if (url.pathname.endsWith('/summary'))
|
|
data = {
|
|
partner_status: 'active',
|
|
agreement_expires_at: now + 86400 * 60,
|
|
};
|
|
else if (url.pathname.endsWith('/statements')) data = [statement];
|
|
else if (/\/statements\/\d+$/.test(url.pathname)) data = statement;
|
|
else if (url.pathname.endsWith('/assignments'))
|
|
data = [
|
|
{
|
|
id,
|
|
status: 'formal',
|
|
customer_name: `企业${id}客户`,
|
|
subject_type: 'organization',
|
|
subject_id: id,
|
|
},
|
|
];
|
|
} else if (url.pathname === '/api/org/info') {
|
|
const id = Number(req.headers()['x-org-id']);
|
|
if (state.pendingOrg === id) {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({
|
|
success: false,
|
|
code: 'org_pending_activation',
|
|
}),
|
|
});
|
|
return;
|
|
}
|
|
data = {
|
|
organization: { id, name: `企业${id}`, status: 1, feature_flags: {} },
|
|
member: { role: 'admin', is_member_actor: true },
|
|
};
|
|
} else if (url.pathname === '/api/org/list') {
|
|
data = [101, 102].map((id) => ({
|
|
id,
|
|
name: `企业${id}`,
|
|
status: 1,
|
|
role: 'admin',
|
|
}));
|
|
} else if (
|
|
url.pathname.endsWith('/options/users') ||
|
|
url.pathname.endsWith('/options/organizations')
|
|
) {
|
|
const q = url.searchParams.get('q') || '';
|
|
if (state.delays[q]) await state.delays[q];
|
|
if (state.mode === 'search-error' && q) {
|
|
await route.fulfill({
|
|
status: 503,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ success: false, message: '选项查询暂不可用' }),
|
|
});
|
|
return;
|
|
}
|
|
const user = {
|
|
id: 7,
|
|
username: 'redstar',
|
|
display_name: '红星',
|
|
disabled: false,
|
|
disabled_reason: '',
|
|
};
|
|
const org = {
|
|
id: 8,
|
|
name: '测试企业',
|
|
code: 'qa-company',
|
|
disabled: false,
|
|
disabled_reason: '',
|
|
};
|
|
const isUser = url.pathname.endsWith('/users');
|
|
const items = isUser
|
|
? ['7', '#7', '红星', 'redstar', 'slow'].includes(q)
|
|
? [
|
|
{
|
|
...user,
|
|
...(q === 'slow'
|
|
? { id: 99, display_name: '迟到的旧结果' }
|
|
: {}),
|
|
},
|
|
]
|
|
: []
|
|
: [org];
|
|
data = { items, total: items.length, p: 1, page_size: 20 };
|
|
} else if (url.pathname.endsWith('/options')) {
|
|
data = {
|
|
users: [{ id: 900, username: 'recent-only', display_name: '最近用户' }],
|
|
organizations: [],
|
|
channels: [
|
|
{ id: 10, name: '测试渠道' },
|
|
{ id: 11, name: '旧渠道' },
|
|
],
|
|
models: [{ id: 'future-model', name: 'future-model' }],
|
|
levels: [],
|
|
};
|
|
} else if (url.pathname.endsWith('/tiers')) {
|
|
if (url.searchParams.get('view') === 'latest') {
|
|
let items = state.tierRows || tiers;
|
|
const pageNumber = Number(url.searchParams.get('p') || 1);
|
|
const pageSize = Number(url.searchParams.get('page_size') || 20);
|
|
if (state.exportConflict && pageNumber > 1) {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({
|
|
success: false,
|
|
message: '档位配置已变化,请重新加载或重新导出',
|
|
}),
|
|
});
|
|
return;
|
|
}
|
|
const q = url.searchParams.get('q');
|
|
const source = url.searchParams.get('source_type');
|
|
const status = url.searchParams.get('status');
|
|
if (q) items = items.filter((row) => row.name.includes(q));
|
|
if (source) items = items.filter((row) => row.source_type === source);
|
|
const stateOf = (row) =>
|
|
row.effective_to
|
|
? 'disabled'
|
|
: row.effective_from > now
|
|
? 'pending'
|
|
: 'active';
|
|
const counts = {
|
|
all: items.length,
|
|
active: items.filter((r) => stateOf(r) === 'active').length,
|
|
pending: items.filter((r) => stateOf(r) === 'pending').length,
|
|
disabled: items.filter((r) => stateOf(r) === 'disabled').length,
|
|
};
|
|
if (status && status !== 'all')
|
|
items = items.filter((row) => stateOf(row) === status);
|
|
data = {
|
|
items: items.slice(
|
|
(pageNumber - 1) * pageSize,
|
|
pageNumber * pageSize,
|
|
),
|
|
total: items.length,
|
|
counts,
|
|
p: Number(url.searchParams.get('p') || 1),
|
|
page_size: Number(url.searchParams.get('page_size') || 20),
|
|
as_of: now,
|
|
revision: 3,
|
|
};
|
|
} else data = [...tiers, oldTier];
|
|
}
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ success: true, data }),
|
|
});
|
|
});
|
|
await page.goto(
|
|
`${origin}/__commission-qa.html?view=${view}§ion=${section}`,
|
|
);
|
|
if (view === 'org')
|
|
await page.locator('[data-partner-scope="1:101"]').waitFor();
|
|
else if (view === 'personal')
|
|
await page
|
|
.getByRole('heading', { name: '分佣概览', exact: true })
|
|
.waitFor();
|
|
else if (view === 'settlement')
|
|
await page
|
|
.getByRole('button', { name: '打开测试结算', exact: true })
|
|
.waitFor();
|
|
else
|
|
await page
|
|
.getByText(
|
|
view === 'tiers'
|
|
? '维护统一分佣比例与状态,支持按等级、模型及渠道关联档位'
|
|
: '已完成线下准入和协议签署的外部合作伙伴档案',
|
|
{ exact: true },
|
|
)
|
|
.waitFor();
|
|
assert.equal(await page.title(), 'Commission adjustment QA');
|
|
assert.equal(await page.locator('vite-error-overlay').count(), 0);
|
|
return state;
|
|
}
|
|
const field = (page, label) =>
|
|
page
|
|
.locator('.commission-form-field')
|
|
.filter({ has: page.locator('span').filter({ hasText: label }) });
|
|
async function openPartner(s) {
|
|
await s.page.getByRole('button', { name: /新建伙伴档案/ }).click();
|
|
await s.page.getByRole('button', { name: '保存草稿', exact: true }).waitFor();
|
|
}
|
|
async function searchUser(s, q) {
|
|
const control = field(s.page, '关联个人用户');
|
|
await control.locator('.semi-select').click();
|
|
await control.locator('input').fill(q);
|
|
}
|
|
async function test(name, run) {
|
|
if (process.env.QA_FILTER && !name.includes(process.env.QA_FILTER)) return;
|
|
let s;
|
|
try {
|
|
s = await run();
|
|
assert.deepEqual(s.errors, []);
|
|
await s.page.screenshot({
|
|
path: path.join(out, `${name}.png`),
|
|
fullPage: false,
|
|
animations: 'disabled',
|
|
});
|
|
results.push({ name, passed: true });
|
|
console.log('PASS', name);
|
|
} catch (error) {
|
|
results.push({ name, passed: false, error: error.stack });
|
|
console.log('FAIL', name, error.message);
|
|
if (activeState) {
|
|
await activeState.page.screenshot({
|
|
path: path.join(out, `${name}-failed.png`),
|
|
});
|
|
fs.writeFileSync(
|
|
path.join(out, `${name}-failed.txt`),
|
|
await activeState.page.locator('body').innerText(),
|
|
);
|
|
}
|
|
} finally {
|
|
if (s || activeState) await (s || activeState).context.close();
|
|
activeState = null;
|
|
}
|
|
}
|
|
try {
|
|
await test('organization-secondary-history-and-details', async () => {
|
|
const s = await setup('org', 1500, 'customers');
|
|
await s.page.getByText('企业101客户', { exact: true }).waitFor();
|
|
await s.page.reload();
|
|
await s.page.getByText('企业101客户', { exact: true }).waitFor();
|
|
await s.page.getByRole('link', { name: '分佣概览', exact: true }).click();
|
|
await s.page.locator('.partner-portal-reminder').first().click();
|
|
await s.page
|
|
.getByRole('heading', { name: '提成账单详情', exact: true })
|
|
.waitFor();
|
|
assert.equal(
|
|
await s.page
|
|
.getByRole('link', { name: '我的提成', exact: true })
|
|
.getAttribute('aria-current'),
|
|
'page',
|
|
);
|
|
await s.page.getByRole('button', { name: '确认账单', exact: true }).click();
|
|
await s.page
|
|
.locator('.semi-modal-footer button')
|
|
.filter({ hasText: '确认无误' })
|
|
.waitFor();
|
|
// Browser back dismisses an unsubmitted confirmation and invalidates detail loads.
|
|
await s.page.evaluate(() => window.__qaNavigate(-1));
|
|
await s.page
|
|
.getByRole('heading', { name: '分佣概览', exact: true })
|
|
.waitFor();
|
|
await s.page
|
|
.locator('.semi-modal-footer button')
|
|
.filter({ hasText: '确认无误' })
|
|
.waitFor({ state: 'hidden' });
|
|
await s.page.evaluate(() => window.__qaNavigate(1));
|
|
await s.page
|
|
.getByRole('heading', { name: '我的提成', exact: true })
|
|
.waitFor();
|
|
await s.page.evaluate(() =>
|
|
window.__qaNavigate('/org/commission?view=invalid'),
|
|
);
|
|
await s.page
|
|
.getByRole('heading', { name: '分佣概览', exact: true })
|
|
.waitFor();
|
|
assert.equal(s.writes.length, 0);
|
|
return s;
|
|
});
|
|
await test('organization-secondary-collapse-and-search', async () => {
|
|
const s = await setup('org');
|
|
const menu = s.page.getByRole('button', { name: '企业分佣', exact: true });
|
|
await menu.click();
|
|
assert.equal(await menu.getAttribute('aria-expanded'), 'false');
|
|
await s.page
|
|
.getByRole('textbox', { name: '搜索菜单', exact: true })
|
|
.fill('提成');
|
|
await s.page.getByRole('link', { name: '我的提成', exact: true }).click();
|
|
await s.page
|
|
.getByRole('heading', { name: '我的提成', exact: true })
|
|
.waitFor();
|
|
await s.page.getByRole('button', { name: '清空搜索', exact: true }).click();
|
|
await s.page.getByRole('button', { name: '收起', exact: true }).click();
|
|
assert.equal(await menu.getAttribute('aria-expanded'), 'false');
|
|
await menu.click();
|
|
await s.page.getByRole('link', { name: '我的客户', exact: true }).click();
|
|
await s.page.getByText('企业101客户', { exact: true }).waitFor();
|
|
return s;
|
|
});
|
|
await test('organization-secondary-mobile', async () => {
|
|
const s = await setup('org', 390);
|
|
await s.page.getByRole('button', { name: '打开菜单', exact: true }).click();
|
|
await s.page
|
|
.getByRole('link', { name: '我的客户', exact: true })
|
|
.last()
|
|
.click();
|
|
await s.page
|
|
.getByRole('heading', { name: '我的客户', exact: true })
|
|
.waitFor();
|
|
await until(
|
|
async () => !(await s.page.locator('.semi-sidesheet').isVisible()),
|
|
'Mobile drawer did not close',
|
|
);
|
|
assert.equal(
|
|
await s.page.locator('.partner-portal .commission-v2-sider').count(),
|
|
0,
|
|
);
|
|
assert.ok(
|
|
await s.page.evaluate(
|
|
() => document.documentElement.scrollWidth <= innerWidth + 1,
|
|
),
|
|
'Page overflowed mobile viewport',
|
|
);
|
|
await s.page.screenshot({
|
|
path: path.join(out, 'organization-mobile-content.png'),
|
|
});
|
|
await s.page.getByRole('button', { name: '打开菜单', exact: true }).click();
|
|
await s.page
|
|
.getByRole('link', { name: '我的客户', exact: true })
|
|
.last()
|
|
.waitFor();
|
|
return s;
|
|
});
|
|
await test('organization-secondary-navigation', async () => {
|
|
const s = await setup('org');
|
|
const menu = s.page.getByRole('button', { name: '企业分佣', exact: true });
|
|
await menu.waitFor();
|
|
assert.equal(await menu.getAttribute('aria-expanded'), 'true');
|
|
assert.equal(
|
|
await s.page.locator('.partner-portal .commission-v2-sider').count(),
|
|
0,
|
|
);
|
|
await s.page.getByRole('link', { name: '我的客户', exact: true }).click();
|
|
await s.page.getByText('企业101客户', { exact: true }).waitFor();
|
|
assert.equal(
|
|
await s.page
|
|
.getByRole('link', { name: '我的客户', exact: true })
|
|
.getAttribute('aria-current'),
|
|
'page',
|
|
);
|
|
await s.page.getByRole('link', { name: '本月预估', exact: true }).click();
|
|
await s.page
|
|
.getByRole('heading', { name: '本月预估', exact: true })
|
|
.waitFor();
|
|
await s.page.getByRole('link', { name: '分佣规则', exact: true }).click();
|
|
await s.page
|
|
.getByRole('heading', { name: '分佣规则', exact: true })
|
|
.waitFor();
|
|
return s;
|
|
});
|
|
await test('personal-navigation-preserved', async () => {
|
|
const s = await setup('personal');
|
|
await s.page.getByRole('navigation', { name: '伙伴分佣导航' }).waitFor();
|
|
await s.page.getByRole('button', { name: '我的客户', exact: true }).click();
|
|
await s.page
|
|
.getByRole('heading', { name: '我的客户', exact: true })
|
|
.waitFor();
|
|
assert.ok(
|
|
!s.requests.some((r) => r.path.startsWith('/api/org/commission/')),
|
|
);
|
|
return s;
|
|
});
|
|
await test('user-id-remote-search', async () => {
|
|
const s = await setup();
|
|
await openPartner(s);
|
|
await searchUser(s, '7');
|
|
await until(
|
|
() =>
|
|
s.requests.some(
|
|
(r) => r.path.endsWith('/options/users') && r.query.q === '7',
|
|
),
|
|
'No remote user-ID search request',
|
|
);
|
|
await s.page
|
|
.getByText(/红星.*redstar.*#7/)
|
|
.last()
|
|
.click();
|
|
await field(s.page, '伙伴名称').locator('input').fill('红星伙伴');
|
|
await s.page.getByRole('button', { name: '保存草稿', exact: true }).click();
|
|
await until(() => s.writes.length === 1, 'Partner was not saved');
|
|
assert.equal(s.writes[0].body.user_id, 7);
|
|
assert.equal(s.writes[0].body.type, 'individual');
|
|
return s;
|
|
});
|
|
await test('company-without-user', async () => {
|
|
const s = await setup();
|
|
await openPartner(s);
|
|
await s.page.getByText('企业伙伴', { exact: true }).click();
|
|
assert.equal(
|
|
await s.page.getByText('企业管理员登录身份', { exact: true }).count(),
|
|
0,
|
|
);
|
|
const org = field(s.page, '关联企业');
|
|
await org.locator('.semi-select').click();
|
|
await s.page
|
|
.getByText(/测试企业.*#8/)
|
|
.last()
|
|
.click();
|
|
await field(s.page, '伙伴名称').locator('input').fill('企业伙伴测试');
|
|
await s.page.getByRole('button', { name: '保存草稿', exact: true }).click();
|
|
await until(
|
|
() => s.writes.length === 1,
|
|
'Company requires an obsolete user identity',
|
|
);
|
|
assert.equal(s.writes[0].body.organization_id, 8);
|
|
assert.ok(!s.writes[0].body.user_id);
|
|
return s;
|
|
});
|
|
await test('search-race-keeps-new-results', async () => {
|
|
const s = await setup();
|
|
const slow = deferred();
|
|
s.delays.slow = slow.promise;
|
|
await openPartner(s);
|
|
await searchUser(s, 'slow');
|
|
await until(
|
|
() => s.requests.some((r) => r.query.q === 'slow'),
|
|
'Slow request not sent',
|
|
);
|
|
await field(s.page, '关联个人用户').locator('input').fill('红星');
|
|
await s.page
|
|
.getByText(/红星.*redstar.*#7/)
|
|
.last()
|
|
.waitFor();
|
|
slow.resolve();
|
|
await sleep(150);
|
|
assert.equal(await s.page.getByText(/迟到的旧结果/).count(), 0);
|
|
await s.page
|
|
.getByText(/红星.*redstar.*#7/)
|
|
.last()
|
|
.click();
|
|
await field(s.page, '伙伴名称').locator('input').fill('保留选择');
|
|
await s.page.getByRole('button', { name: '保存草稿', exact: true }).click();
|
|
await until(() => s.writes.length === 1);
|
|
assert.equal(s.writes[0].body.user_id, 7);
|
|
return s;
|
|
});
|
|
await test('type-switch-discards-pending-user', async () => {
|
|
const s = await setup();
|
|
const slow = deferred();
|
|
s.delays.slow = slow.promise;
|
|
await openPartner(s);
|
|
await searchUser(s, 'slow');
|
|
await until(() => s.requests.some((r) => r.query.q === 'slow'));
|
|
await s.page.getByText('企业伙伴', { exact: true }).click();
|
|
slow.resolve();
|
|
await sleep(150);
|
|
assert.equal(await s.page.getByText(/迟到的旧结果/).count(), 0);
|
|
assert.equal(
|
|
await s.page.getByText('关联个人用户', { exact: true }).count(),
|
|
0,
|
|
);
|
|
await field(s.page, '关联企业').locator('.semi-select').click();
|
|
await s.page
|
|
.getByText(/测试企业.*#8/)
|
|
.last()
|
|
.waitFor();
|
|
return s;
|
|
});
|
|
await test('close-reopen-discards-old-search', async () => {
|
|
const s = await setup();
|
|
const slow = deferred();
|
|
s.delays.slow = slow.promise;
|
|
await openPartner(s);
|
|
await searchUser(s, 'slow');
|
|
await until(() => s.requests.some((r) => r.query.q === 'slow'));
|
|
await s.page.getByRole('button', { name: '取消', exact: true }).click();
|
|
await openPartner(s);
|
|
await searchUser(s, '7');
|
|
await s.page
|
|
.getByText(/红星.*redstar.*#7/)
|
|
.last()
|
|
.waitFor();
|
|
slow.resolve();
|
|
await sleep(150);
|
|
assert.equal(await s.page.getByText(/迟到的旧结果/).count(), 0);
|
|
return s;
|
|
});
|
|
await test('latest-tiers-only', async () => {
|
|
const s = await setup('tiers');
|
|
await s.page.getByText('企业专用最新档', { exact: true }).waitFor();
|
|
assert.equal(
|
|
await s.page.getByText('不应显示的历史档', { exact: true }).count(),
|
|
0,
|
|
);
|
|
assert.ok(
|
|
s.requests.some(
|
|
(r) => r.path.endsWith('/tiers') && r.query.view === 'latest',
|
|
),
|
|
);
|
|
await s.page.getByText('真正停用档', { exact: true }).waitFor();
|
|
const future = s.page.locator('tr').filter({ hasText: '明日生效档' });
|
|
assert.equal(
|
|
await future.getByRole('button', { name: '停用', exact: true }).count(),
|
|
0,
|
|
);
|
|
assert.equal(await s.page.locator('.semi-datepicker').count(), 0);
|
|
await s.page
|
|
.getByRole('button', { name: '绑定历史', exact: true })
|
|
.waitFor();
|
|
return s;
|
|
});
|
|
await test('latest-status-filter-is-server-side', async () => {
|
|
const s = await setup('tiers');
|
|
await s.page.getByText('企业专用最新档', { exact: true }).waitFor();
|
|
await s.page.getByRole('tab', { name: /已停用/ }).click();
|
|
await until(
|
|
() =>
|
|
s.requests.some(
|
|
(r) => r.path.endsWith('/tiers') && r.query.status === 'disabled',
|
|
),
|
|
'Status filter only ran locally',
|
|
);
|
|
await s.page.getByText('真正停用档', { exact: true }).waitFor();
|
|
await until(
|
|
async () =>
|
|
(await s.page.getByText('企业专用最新档', { exact: true }).count()) ===
|
|
0,
|
|
);
|
|
assert.equal(
|
|
await s.page.getByText('不应显示的历史档', { exact: true }).count(),
|
|
0,
|
|
);
|
|
return s;
|
|
});
|
|
await test('settlement-cancel-and-close', async () => {
|
|
const s = await setup('settlement');
|
|
await s.page
|
|
.getByRole('button', { name: '打开测试结算', exact: true })
|
|
.click();
|
|
await s.page.getByText('录入手续费', { exact: true }).waitFor();
|
|
await s.page
|
|
.locator('.semi-modal-footer button')
|
|
.filter({ hasText: '取消' })
|
|
.click();
|
|
await until(
|
|
async () =>
|
|
!(await s.page.getByText('录入手续费', { exact: true }).isVisible()),
|
|
);
|
|
await s.page
|
|
.getByRole('button', { name: '打开测试结算', exact: true })
|
|
.click();
|
|
await s.page.getByText('录入手续费', { exact: true }).waitFor();
|
|
await s.page.locator('.semi-modal-close').click();
|
|
await until(
|
|
async () =>
|
|
!(await s.page.getByText('录入手续费', { exact: true }).isVisible()),
|
|
);
|
|
assert.equal(s.page.isClosed(), false);
|
|
return s;
|
|
});
|
|
await test('latest-export-fetches-all-pages', async () => {
|
|
const s = await setup('tiers');
|
|
s.tierRows = Array.from({ length: 105 }, (_, index) => ({
|
|
...tiers[0],
|
|
id: 1000 + index,
|
|
config_id: 1000 + index,
|
|
name: `导出配置${index}`,
|
|
}));
|
|
await s.page.getByRole('button', { name: /刷新/ }).click();
|
|
await s.page.getByText('导出配置0', { exact: true }).waitFor();
|
|
const download = s.page.waitForEvent('download');
|
|
await s.page.getByRole('button', { name: '导出', exact: true }).click();
|
|
const file = await download;
|
|
const exportPath = path.join(out, 'latest-all-pages.xlsx');
|
|
await file.saveAs(exportPath);
|
|
const XLSX = await import(
|
|
pathToFileURL(path.join(webRoot, 'node_modules/xlsx/xlsx.mjs')).href
|
|
);
|
|
const workbook = XLSX.read(fs.readFileSync(exportPath), { type: 'buffer' });
|
|
const rows = XLSX.utils.sheet_to_json(
|
|
workbook.Sheets[workbook.SheetNames[0]],
|
|
);
|
|
assert.equal(rows.length, 105);
|
|
assert.ok(
|
|
s.requests.some(
|
|
(r) =>
|
|
r.path.endsWith('/tiers') &&
|
|
r.query.p === '2' &&
|
|
r.query.revision === '3' &&
|
|
r.query.as_of === String(now),
|
|
),
|
|
);
|
|
return s;
|
|
});
|
|
await test('latest-export-refuses-changed-revision', async () => {
|
|
const s = await setup('tiers');
|
|
s.tierRows = Array.from({ length: 105 }, (_, index) => ({
|
|
...tiers[0],
|
|
id: 1000 + index,
|
|
config_id: 1000 + index,
|
|
name: `变更配置${index}`,
|
|
}));
|
|
s.exportConflict = true;
|
|
let downloads = 0;
|
|
s.page.on('download', () => downloads++);
|
|
await s.page.getByRole('button', { name: /刷新/ }).click();
|
|
await s.page.getByText('变更配置0', { exact: true }).waitFor();
|
|
await s.page.getByRole('button', { name: '导出', exact: true }).click();
|
|
await s.page
|
|
.locator('.semi-banner')
|
|
.filter({ hasText: '档位配置已变化,请重新加载或重新导出' })
|
|
.waitFor();
|
|
assert.equal(downloads, 0);
|
|
return s;
|
|
});
|
|
await test('organization-navigation-discards-slow-detail', async () => {
|
|
const s = await setup('org');
|
|
const delayed = deferred();
|
|
s.detailDelay = delayed.promise;
|
|
await s.page.locator('.partner-portal-reminder').first().click();
|
|
await until(
|
|
() => s.requests.some((r) => /\/statements\/\d+$/.test(r.path)),
|
|
'No detail request',
|
|
);
|
|
await s.page.getByRole('link', { name: '我的客户', exact: true }).click();
|
|
await s.page.getByText('企业101客户', { exact: true }).waitFor();
|
|
const response = s.page.waitForResponse((r) =>
|
|
/\/statements\/\d+$/.test(new URL(r.url()).pathname),
|
|
);
|
|
delayed.resolve();
|
|
await (await response).finished();
|
|
await s.page.evaluate(
|
|
() =>
|
|
new Promise((done) =>
|
|
requestAnimationFrame(() => requestAnimationFrame(done)),
|
|
),
|
|
);
|
|
assert.equal(
|
|
await s.page
|
|
.getByRole('heading', { name: '提成账单详情', exact: true })
|
|
.count(),
|
|
0,
|
|
);
|
|
assert.equal(
|
|
await s.page
|
|
.getByRole('heading', { name: '我的客户', exact: true })
|
|
.count(),
|
|
1,
|
|
);
|
|
assert.equal(s.writes.length, 0);
|
|
return s;
|
|
});
|
|
await test('organization-pending-activation-switch', async () => {
|
|
const s = await setup('org');
|
|
await s.page.getByRole('link', { name: '我的客户', exact: true }).click();
|
|
await s.page.getByText('企业101客户', { exact: true }).waitFor();
|
|
s.pendingOrg = 102;
|
|
await s.page
|
|
.locator('select[aria-label="切换企业"]')
|
|
.first()
|
|
.selectOption('102');
|
|
await s.page.getByText('企业待激活', { exact: true }).waitFor();
|
|
assert.equal(await s.page.locator('[data-partner-scope]').count(), 0);
|
|
assert.equal(
|
|
await s.page.evaluate(() => localStorage.getItem('current_org_id')),
|
|
'102',
|
|
);
|
|
s.pendingOrg = null;
|
|
await s.page.getByRole('button', { name: '刷新状态', exact: true }).click();
|
|
await s.page.getByText('企业102客户', { exact: true }).waitFor();
|
|
assert.equal(
|
|
await s.page.getByText('企业101客户', { exact: true }).count(),
|
|
0,
|
|
);
|
|
return s;
|
|
});
|
|
await test('organization-switch-clears-confirmation', async () => {
|
|
const s = await setup('org');
|
|
await s.page.locator('.partner-portal-reminder').first().click();
|
|
await s.page.getByRole('button', { name: '确认账单', exact: true }).click();
|
|
await s.page
|
|
.locator('.semi-modal-footer button')
|
|
.filter({ hasText: '确认无误' })
|
|
.waitFor();
|
|
// The real sidebar switch must unmount the old confirmation and pin all subsequent requests.
|
|
await s.page
|
|
.locator('select[aria-label="切换企业"]')
|
|
.first()
|
|
.selectOption('102');
|
|
await s.page.locator('[data-partner-scope="1:102"]').waitFor();
|
|
assert.equal(
|
|
await s.page.locator('[data-partner-scope="1:101"]').count(),
|
|
0,
|
|
);
|
|
assert.equal(
|
|
await s.page
|
|
.locator('.semi-modal-footer button')
|
|
.filter({ hasText: '确认无误' })
|
|
.count(),
|
|
0,
|
|
);
|
|
assert.equal(s.writes.length, 0);
|
|
assert.ok(
|
|
s.requests.some(
|
|
(r) =>
|
|
r.path === '/api/org/commission/statements' &&
|
|
r.headers['x-org-id'] === '102',
|
|
),
|
|
);
|
|
assert.ok(!s.requests.some((r) => r.path.startsWith('/api/partner/v2/')));
|
|
await s.page.getByRole('link', { name: '我的客户', exact: true }).click();
|
|
await s.page.getByText('企业102客户', { exact: true }).waitFor();
|
|
assert.equal(
|
|
await s.page.getByText('企业101客户', { exact: true }).count(),
|
|
0,
|
|
);
|
|
return s;
|
|
});
|
|
} finally {
|
|
await browser.close();
|
|
await server.close();
|
|
fs.writeFileSync(
|
|
path.join(out, 'results.json'),
|
|
JSON.stringify(results, null, 2),
|
|
);
|
|
console.log(
|
|
`${results.filter((r) => r.passed).length}/${results.length} passed`,
|
|
);
|
|
}
|
|
if (results.some((r) => !r.passed)) process.exitCode = 1;
|