liu
3 天以前 089af38e1a85724364dc490ae5aea698aede01dc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const { chromium } = require('playwright');
const fs = require('fs'), path = require('path'), assert = require('assert/strict');
const base = process.env.MOBILE_TEST_URL || 'http://127.0.0.1:5174';
const out = path.resolve('.export_tmp/mobile-quality-sales');fs.mkdirSync(out,{recursive:true});
(async()=>{
  const browser=await chromium.launch({headless:true,channel:'msedge'});
  const context=await browser.newContext({viewport:{width:1440,height:1000}}),page=await context.newPage();
  const writes=[], errors=[];page.on('pageerror',e=>errors.push(e.message));
  const order={id:11,code:'SALE-1',name:'测试销售出库',clientId:1,clientName:'测试经销商',status:2,salesDate:'2026-10-10'};
  await context.route('**/*',async route=>{
    const req=route.request(),u=new URL(req.url()),p=u.pathname;
    if(u.origin!==base)return route.abort();if(!p.startsWith('/admin-api/'))return route.continue();
    let data=[];
    if(p.endsWith('/auth/login'))data={accessToken:'test-token',refreshToken:'test-refresh',userId:7,expiresTime:Date.now()+3600000};
    else if(p.endsWith('/get-permission-info'))data={user:{id:7,nickname:'仓库测试员',username:'fixture',homePath:'/wls/productsales'},roles:['worker'],permissions:['mes:wm-product-sales:query','mes:wm-product-sales:stock'],menus:[{id:1,name:'销售出库',path:'/wls/productsales',component:'wls/productsales/index',visible:true}]};
    else if(p.endsWith('/product-sales/page'))data={list:[order],total:1};
    else if(p.endsWith('/product-sales/get'))data=order;
    else if(p.endsWith('/product-sales-line/page'))data={list:[{id:21,itemId:1,itemName:'塔河4号',quantity:5,unitMeasureName:'袋'}],total:1};
    else if(p.endsWith('/product-sales/scan-preview'))data={scanType:u.searchParams.get('scanType'),codeId:100,scanContent:u.searchParams.get('code'),batchCode:'BATCH-1',itemId:1,scanQuantity:3,bags:[31,32,33].map(id=>({id,code:'TRACE-'+id,businessCode:'BUS-'+id,selectable:true}))};
    else if(p.endsWith('/product-sales/scan')){const body=req.postDataJSON();writes.push(body);data={outboundQuantity:body.bagIds.length,alreadyScanned:false};}
    else if(p.endsWith('/get-unread-count'))data=0;
    else if(p.endsWith('/page'))data={list:[],total:0};
    return route.fulfill({json:{code:0,data,msg:''}});
  });
  try{
    await page.goto(base+'/auth/login');await page.getByRole('radio',{name:'PC 端',exact:true}).check();
    await page.locator('input[autocomplete=username]').fill('fixture');await page.locator('input[autocomplete=current-password]').fill('fixture');await page.getByRole('button',{name:'登录 PC 端',exact:true}).click();
    await page.waitForURL('**/wls/productsales');await page.getByRole('button',{name:'拣货',exact:true}).first().click();
    await page.getByRole('heading',{name:'执行拣货',exact:true}).waitFor();
    await page.locator('.ant-select').filter({has:page.getByRole('combobox',{name:'拣货扫码类型'})}).click();await page.getByText('生产批次码',{exact:true}).click();
    await page.getByPlaceholder('扫描所选类型码,回车识别').fill('BATCH-100');await page.getByRole('button',{name:'识别码值',exact:true}).click();
    await page.getByRole('heading',{name:'核对拣货对象'}).waitFor();assert.equal(writes.length,0);
    await page.getByRole('spinbutton',{name:'本次拣货数量'}).fill('2');await page.getByRole('button',{name:'按数量选择袋码'}).click();
    await page.getByRole('checkbox',{name:'选择袋码 TRACE-31',exact:true}).uncheck();assert.equal(await page.getByRole('spinbutton',{name:'本次拣货数量'}).inputValue(),'1');await page.getByRole('checkbox',{name:'选择袋码 TRACE-33',exact:true}).check();
    await page.screenshot({path:path.join(out,'pc-sales-batch-selection.png'),fullPage:true});
    await page.getByRole('button',{name:'确认加入拣货'}).click();await page.getByRole('button',{name:/^确\s*认$/}).click();
    await page.getByText('已加入拣货 2 袋,逐袋关联追溯码',{exact:true}).waitFor();
    assert.equal(writes.length,1);assert.equal(writes[0].scanType,'BATCH');assert.equal(writes[0].quantity,2);assert.deepEqual(writes[0].bagIds,[32,33]);
    assert.deepEqual(errors,[]);console.log('PASS: PC batch partial picking, selected bag IDs and exact quantity; preview performs no writes');
  }catch(e){await page.screenshot({path:path.join(out,'pc-sales-selection-failure.png')});console.error(e);process.exitCode=1;}
  finally{await browser.close();}
})();