| 1234567891011121314151617181920 |
- import {chromium} from 'playwright';
- import {mkdirSync,writeFileSync,readFileSync} from 'node:fs';
- import * as XLSX from 'xlsx';
- import assert from 'node:assert/strict';
- export async function checkMemberCreditBrowser({auth,output,memberObjectId}){
- mkdirSync(output,{recursive:true});const browser=await chromium.launch({headless:true,executablePath:'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'}),checks=[],errors=[];
- try{
- const context=await browser.newContext({viewport:{width:1440,height:1050}});await context.addInitScript(auth=>{localStorage.setItem('xiaoshu_admin_session_v1',JSON.stringify(auth));sessionStorage.setItem('xiaoshu_admin_session_v1',JSON.stringify(auth));},auth);
- const page=await context.newPage();page.on('pageerror',e=>errors.push(e.message));await page.goto('http://127.0.0.1:4300/admin/members/'+memberObjectId+'?tab=balances');
- const panel=page.locator('app-member-credit-account');await panel.locator('.ledger-entry').first().waitFor({timeout:60000});assert.equal(await panel.locator('.accounts article').count(),4);assert.equal(await panel.locator('.ledger-entry').count(),10);checks.push('真实会员四类账户与 10 条历史流水');
- await panel.locator('.ledger-entry').first().locator('summary').click();await panel.getByRole('columnheader',{name:'调整前',exact:true}).waitFor();checks.push('展开原始流水,前后余额、操作人、来源单据可见');
- const dates=await panel.locator('.ledger-entry time').allTextContents();assert.deepEqual(dates,[...dates].sort().reverse());
- const ledger=panel.locator('.ledger-panel'),account=ledger.getByLabel('账户',{exact:true});await account.click();await page.getByRole('option',{name:'60分钟课时',exact:true}).click();await ledger.getByRole('button',{name:'查询',exact:true}).click();await page.waitForFunction(()=>document.querySelectorAll('.ledger-entry').length===5);checks.push('60 分钟账户筛选 5 条,北京时间倒序');
- const downloadPromise=page.waitForEvent('download');await ledger.getByRole('button',{name:'导出 Excel',exact:true}).click();const download=await downloadPromise;await download.saveAs(output+'/credits.xlsx');const book=XLSX.read(readFileSync(output+'/credits.xlsx'));assert.equal(XLSX.utils.sheet_to_json(book.Sheets[book.SheetNames[0]]).length,5);checks.push('真实筛选导出 5 行,与明细一致');
- await account.click();await page.getByRole('option',{name:'陪练时长',exact:true}).click();await ledger.getByRole('button',{name:'查询',exact:true}).click();await page.waitForFunction(()=>document.querySelectorAll('.ledger-entry').length===5&&document.querySelector('.ledger-entry')?.textContent.includes('陪练'));checks.push('陪练账户筛选 5 条');
- await ledger.getByRole('button',{name:'开始日期',exact:true}).click();await page.getByRole('dialog',{name:'选择开始日期'}).waitFor();await page.keyboard.press('Escape');checks.push('统一日期选择器展开与关闭');
- await page.screenshot({path:output+'/member-credit-desktop.png',fullPage:true});await page.setViewportSize({width:390,height:844});await page.screenshot({path:output+'/member-credit-narrow.png',fullPage:true});assert.ok(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+1));checks.push('390 像素窄屏无整页横向溢出');
- assert.deepEqual(errors,[]);writeFileSync(output+'/browser-result.json',JSON.stringify({passed:true,checks},null,2));return{passed:true,checks};
- }finally{await browser.close();}
- }
|