From 089af38e1a85724364dc490ae5aea698aede01dc Mon Sep 17 00:00:00 2001
From: liu <2021943741@qq.com>
Date: 星期五, 16 十月 2026 17:50:48 +0800
Subject: [PATCH] test(mes): 新增种子质检三种扫码类型冒烟测试
---
scripts/pc-seed-quality-multitype-smoke.cjs | 122 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 122 insertions(+), 0 deletions(-)
diff --git a/scripts/pc-seed-quality-multitype-smoke.cjs b/scripts/pc-seed-quality-multitype-smoke.cjs
new file mode 100644
index 0000000..c9d30ff
--- /dev/null
+++ b/scripts/pc-seed-quality-multitype-smoke.cjs
@@ -0,0 +1,122 @@
+const { chromium } = require('playwright');
+const fs = require('fs'), path = require('path'), assert = require('assert/strict');
+const base = process.env.PC_TEST_URL || 'http://127.0.0.1:5667';
+const out = path.resolve('.export_tmp/pc-seed-quality'); fs.mkdirSync(out, { recursive: true });
+(async () => {
+ const browser = await chromium.launch({ headless: true, channel: 'msedge' });
+ const context = await browser.newContext({ viewport: { width: 1512, height: 1100 } });
+ const page = await context.newPage(), writes = [], errors = [];
+ page.on('pageerror', e => errors.push(e.message));
+ // 涓夌绫诲瀷鐨勫緟妫�琚嬫竻鍗曪細琚嬬爜 1 琚嬨�佹墭鐩� 2 琚嬨�佹壒娆� 3 琚�
+ const pending = { BAG: [11], PALLET: [21, 22], BATCH: [31, 32, 33] };
+ const codeOf = { BAG: 'BAG-TRACE-1', PALLET: 'PALLET-100', BATCH: 'BATCH-100' };
+ let resolveMode = 'ok'; // ok | canceled | notInbound | inspected
+ 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 = null;
+ 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: '/mes/qc/seedQuality' },
+ roles: ['worker'], permissions: ['mes:qc-seed-quality:submit', 'mes:qc-seed-quality:query'],
+ menus: [{ id: 1, name: '绉嶅瓙璐ㄦ', path: '/mes/qc/seedQuality', component: 'mes/qc/seedQuality/index', visible: true }],
+ };
+ else if (p.endsWith('/warehouse/simple-list')) data = [
+ { id: 8, code: 'WK-01', name: '绉嶅瓙鍚堟牸搴�', type: 20 },
+ { id: 9, code: 'WK-02', name: '鍐荤粨鍚堟牸搴�', type: 20, frozen: true },
+ { id: 10, code: 'WK-03', name: '鏆傚瓨搴�', type: 10 },
+ ];
+ else if (p.endsWith('/seed-quality/resolve')) {
+ const t = u.searchParams.get('scanType') || 'BAG';
+ const shell = { scanType: t, code: codeOf[t], businessCode: '8888888888888888', batchCode: 'BATCH-1' };
+ if (resolveMode === 'canceled') data = { ...shell, canceled: true, inbound: true, totalCount: 0, pendingBagIds: [], completedBagIds: [] };
+ else if (resolveMode === 'notInbound') data = { ...shell, canceled: false, inbound: false, totalCount: 2, pendingBagIds: [11], completedBagIds: [] };
+ else if (resolveMode === 'inspected') data = { ...shell, canceled: false, inbound: true, totalCount: 2, pendingBagIds: [], completedBagIds: [11] };
+ else data = { ...shell, canceled: false, inbound: true, totalCount: pending[t].length + 1, pendingBagIds: pending[t], completedBagIds: [99] };
+ } else if (p.endsWith('/seed-quality/submit-group')) {
+ const body = req.postDataJSON(); writes.push(body); data = { processedCount: body.bagIds.length };
+ } else if (p.endsWith('/get-unread-count')) data = 0;
+ else if (p.endsWith('/simple-list')) data = [];
+ else if (p.endsWith('/page')) data = { list: [], total: 0 };
+ return route.fulfill({ json: { code: 0, data, msg: '' } });
+ });
+ // 涓嬫媺閫夐」鍙彇褰撳墠鍙鐨勯偅涓�涓細Ant 浼氭妸宸叉墦寮�杩囩殑涓嬫媺鐣欏湪 DOM 閲�
+ const visibleOption = (label) => page.locator('.ant-select-dropdown:not(.ant-select-dropdown-hidden) .ant-select-item-option').filter({ hasText: label });
+ async function pickOption(label) { await visibleOption(label).first().click(); }
+ async function identify(type, label) {
+ await page.locator('.scan-type').click(); await pickOption(label);
+ await page.locator('.scan-input input').fill(codeOf[type]);
+ // Ant 鍦ㄤ袱瀛椾腑鏂囨寜閽腑鎻掑叆绌烘牸锛屽彲璁块棶鍚嶆槸銆岃瘑 鍒�嶏紝鏁呯敤 class 瀹氫綅
+ await page.locator('.scan-input .ant-input-search-button').click();
+ // 鎽樿鍗′笌妫�楠屽璞¢潰鏉块兘鏈夈�屾湰娆″緟妫�銆嶅瓧鏍凤紝鏁呯洿鎺ョ瓑闈㈡澘閲岀殑琚嬫暟娓叉煋
+ await page.locator('.target-stats .highlight strong').waitFor();
+ }
+ 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('**/mes/qc/seedQuality');
+ await page.locator('#__app-loading__').waitFor({ state: 'detached' });
+ await page.getByRole('heading', { name: '绉嶅瓙璐ㄦ' }).waitFor();
+ // 1) 鎵爜绫诲瀷涓嬫媺蹇呴』鏄� 琚嬬爜 / 鎵樼洏鐮� / 鎵规鐮� 涓夐」
+ await page.locator('.scan-type').click();
+ for (const label of ['琚嬬爜', '鎵樼洏鐮�', '鎵规鐮�']) {
+ assert.equal(await visibleOption(label).count() > 0, true, '涓嬫媺缂哄皯閫夐」锛�' + label);
+ }
+ assert.equal(await page.locator('.ant-select-dropdown:not(.ant-select-dropdown-hidden) .ant-select-item-option').count(), 3, '鎵爜绫诲瀷涓嬫媺搴旀伆濂戒笁椤�');
+ await page.screenshot({ path: path.join(out, 'scan-type-options.png'), fullPage: true });
+ await page.keyboard.press('Escape');
+ // 2) 鍒囨崲鎵爜绫诲瀷蹇呴』娓呯┖宸茶瘑鍒璞★紝閬垮厤鎷夸笂涓�涓被鍨嬬殑鐮佸��/娓呭崟鎻愪氦
+ await identify('BAG', '琚嬬爜');
+ await page.locator('.scan-type').click(); await pickOption('鎵樼洏鐮�');
+ await page.waitForFunction(() => document.querySelector('.target-panel') === null);
+ // 3) 涓夌绫诲瀷閫愪竴璇嗗埆骞舵彁浜�
+ for (const [type, label] of [['BAG', '琚嬬爜'], ['PALLET', '鎵樼洏鐮�'], ['BATCH', '鎵规鐮�']]) {
+ await identify(type, label);
+ const shownPending = (await page.locator('.target-stats .highlight strong').innerText()).trim();
+ assert.equal(shownPending, pending[type].length + ' 琚�', type + ' 鏈寰呮琚嬫暟涓嶇锛岄〉闈㈡樉绀猴細' + shownPending);
+ const shownCompleted = (await page.locator('.target-stats div').nth(1).locator('strong').innerText()).trim();
+ assert.equal(shownCompleted, '1', type + ' 宸叉琚嬫暟涓嶇锛岄〉闈㈡樉绀猴細' + shownCompleted);
+ assert.equal((await page.locator('.target-head .target-code').innerText()).trim(), codeOf[type], type + ' 璇嗗埆瀵硅薄鐮佸�间笉绗�');
+ for (const field of await page.getByPlaceholder('瀹炴祴鍊�').all()) await field.fill('90');
+ await page.locator('.base-grid .ant-select').click();
+ assert.equal(await visibleOption('鍐荤粨鍚堟牸搴�').count(), 0, '鍐荤粨浠撳簱涓嶅簲鍑虹幇鍦ㄥ悎鏍煎簱涓嬫媺涓�');
+ await pickOption('绉嶅瓙鍚堟牸搴�');
+ await page.screenshot({ path: path.join(out, 'filled-' + type.toLowerCase() + '.png'), fullPage: true });
+ await page.getByRole('button', { name: '鎻愪氦璐ㄦ' }).click();
+ await page.getByRole('button', { name: '纭鎻愪氦' }).click();
+ // 鎻愮ず鏉′細鍙犵暀锛屾寜鏈琚嬫暟瀹氫綅锛岄伩鍏嶅尮閰嶅埌涓婁竴娆$殑鎻愮ず
+ await page.locator('.ant-message-notice-content').filter({ hasText: '鏈 ' + pending[type].length + ' 琚嬪凡鎻愪氦锛氳川妫�鍚堟牸锛屽凡杞叆鎵�閫夊悎鏍煎簱' }).last().waitFor();
+ const w = writes.at(-1);
+ assert.equal(w.scanType, type, type + ' 鎻愪氦鐨� scanType 涓嶆纭�');
+ assert.deepEqual(w.bagIds, pending[type], type + ' 鎻愪氦鐨� bagIds 涓庤瘑鍒竻鍗曚笉涓�鑷�');
+ assert.equal(w.qualifiedWarehouseId, 8, type + ' 鏈甫鍏ラ�変腑鐨勫悎鏍煎簱');
+ assert.equal(w.indicators.length, 4, type + ' 鍥涢」鎸囨爣鏈畬鏁存彁浜�');
+ assert.equal(w.code, codeOf[type], type + ' 鎻愪氦鐨勭爜鍊间笉姝g‘');
+ await page.waitForFunction(() => document.querySelector('.target-panel') === null);
+ }
+ // 4) 宸蹭綔搴� / 鏈叏閮ㄥ叆搴� / 鏃犲緟妫�琚嬬爜鏃跺繀椤绘嫤浣忥紝涓斾笉浜х敓浠讳綍鎻愪氦
+ const before = writes.length;
+ for (const [mode, expected] of [
+ ['canceled', '璇ヨ川妫�瀵硅薄宸蹭綔搴燂紝涓嶈兘璐ㄦ'],
+ ['notInbound', '璇ュ璞$殑鏈夋晥琚嬬爜灏氭湭鍏ㄩ儴鍏ュ簱锛屾殏涓嶈兘璐ㄦ'],
+ ['inspected', '璇ュ璞℃病鏈夊緟璐ㄦ琚嬬爜锛岃鍦ㄨ川妫�璁板綍涓煡鐪嬪凡鏈夌粨鏋�'],
+ ]) {
+ resolveMode = mode;
+ await page.locator('.scan-input input').fill(codeOf.BAG);
+ await page.locator('.scan-input .ant-input-search-button').click();
+ await page.locator('.ant-message-notice-content').filter({ hasText: expected }).last().waitFor();
+ await page.waitForFunction(() => document.querySelector('.target-panel') === null);
+ assert.equal(await page.getByRole('button', { name: '鎻愪氦璐ㄦ' }).isDisabled(), true, mode + ' 鏃舵彁浜ゆ寜閽簲淇濇寔涓嶅彲鐢�');
+ }
+ assert.equal(writes.length, before, '琚嫤浣忕殑璇嗗埆涓嶅簲浜х敓鎻愪氦');
+ assert.deepEqual(errors, []);
+ console.log('PASS: 绉嶅瓙璐ㄦ 琚嬬爜/鎵樼洏鐮�/鎵规鐮� 涓夌被鍨嬩笅鎷夈�佽瘑鍒寖鍥存牳瀵广�佸垎缁勬彁浜ゃ�佸悎鏍煎簱杩囨护涓庡紓甯告嫤鎴�');
+ } catch (e) {
+ await page.screenshot({ path: path.join(out, 'failure.png'), fullPage: true });
+ console.error(e); process.exitCode = 1;
+ } finally { await browser.close(); }
+})();
--
Gitblit v1.9.3