修复bug

This commit is contained in:
brother7 committed 2026-08-30 00:13:22 +08:00
1 parent c65f00c941
commit 98282d127c
33 files changed
+1104 -167

No files matched your search

+86
View File
@@ -2,6 +2,7 @@ import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import { readFile } from 'node:fs/promises';
import test from 'node:test';
import vm from 'node:vm';
const require = createRequire(import.meta.url);
const timing = require('../chrome-extension/ltjt-order-assistant/operation-timing.js');
@@ -180,6 +181,8 @@ test('team-order preflight waits on ERP completion events without page-timer pol
assert.match(preflight, /await productEffectCompletion/);
assert.match(preflight, /preflight_lookup\.parallel_wall/);
assert.match(preflight, /preflight_product_linkage/);
assert.match(preflight, /await waitForJQueryAjaxIdle\(jq\)/);
assert.match(preflight, /preflight_native_ajax_idle/);
assert.match(preflight, /preflight_customer_restore/);
assert.match(preflight, /dispatchNativeSideEffect: false/);
assert.match(preflight, /customerRestoreReadiness/);
@@ -220,6 +223,89 @@ test('team-order frame discovery targets the exact ERP iframe instead of injecti
assert.ok(JSON.parse(manifestText).permissions.includes('webNavigation'));
});
test('team-order frame waits for native customer and staff lookup data before preflight', async () => {
const background = await readFile(new URL('../chrome-extension/ltjt-order-assistant/background.js', import.meta.url), 'utf8');
const start = background.indexOf('function lightweightOrderFrameProbe()');
const end = background.indexOf('function lightweightTeamBatchFrameProbe()', start);
const probeSource = background.slice(start, end);
const runProbe = (readyFields, activeAjaxCount = 0) => {
const fields = Object.fromEntries(['zutuanshe', 'gendanren', 'xiaoshouren'].map((name) => [
name,
{ getAttribute: (attribute) => attribute === 'data' && readyFields.includes(name) ? 'native-options' : '' }
]));
const form = {
elements: { length: 822 },
querySelector: (selector) => fields[selector.slice(1)] || null
};
const sandbox = {
performance,
document: {
title: '计划下单/修改',
querySelector: (selector) => selector === '#ListForm' ? form : null
},
location: { href: 'https://lwlt.hisy.cc/System/Business/orders_add.asp' },
window: { frameElement: null, jQuery: { active: activeAjaxCount } },
URL
};
vm.runInNewContext(`${probeSource};globalThis.result=lightweightOrderFrameProbe();`, sandbox);
return JSON.parse(JSON.stringify(sandbox.result));
};
const loading = runProbe([]);
assert.equal(loading.status, 'order_frame_loading');
assert.deepEqual(loading.missing, ['zutuanshe.data', 'gendanren.data', 'xiaoshouren.data']);
const nativeAjaxPending = runProbe(['zutuanshe', 'gendanren', 'xiaoshouren'], 2);
assert.equal(nativeAjaxPending.status, 'order_frame_loading');
assert.deepEqual(nativeAjaxPending.missing, ['jquery.ajax.pending:2']);
assert.equal(runProbe(['zutuanshe', 'gendanren', 'xiaoshouren']).status, 'order_frame_ready');
});
test('team-order preflight waits for the native jQuery Ajax completion event', async () => {
const source = await readFile(new URL('../chrome-extension/ltjt-order-assistant/inpage.js', import.meta.url), 'utf8');
const inpage = source.replace(
'inspectProtectedSubmitFieldChanges: protectedSubmitFieldChanges,',
'inspectWaitForJQueryAjaxIdle: waitForJQueryAjaxIdle,\n inspectProtectedSubmitFieldChanges: protectedSubmitFieldChanges,'
);
const handlers = new Map();
const eventTarget = {
one(eventName, handler) {
handlers.set(eventName, handler);
return this;
},
off(eventName) {
handlers.delete(eventName);
return this;
}
};
const jq = () => eventTarget;
jq.active = 2;
const pageWindow = { setTimeout, clearTimeout };
pageWindow.window = pageWindow;
vm.runInNewContext(inpage, {
window: pageWindow,
document: {},
performance,
setTimeout,
clearTimeout
});
const waiting = pageWindow.LTJTOrderAssistant.inspectWaitForJQueryAjaxIdle(jq, 1000);
setTimeout(() => {
jq.active = 0;
const handler = [...handlers.entries()].find(([eventName]) => eventName.startsWith('ajaxStop'))?.[1];
handler?.();
}, 5);
const result = await waiting;
assert.deepEqual(JSON.parse(JSON.stringify(result)), {
status: 'idle',
initial_pending_ajax_count: 2,
final_pending_ajax_count: 0,
duration_ms: result.duration_ms
});
assert.ok(result.duration_ms >= 0);
});
test('extension result changes push immediately while polling remains as a fallback', async () => {
const bridge = await readFile(new URL('../chrome-extension/ltjt-order-assistant/business-bridge.js', import.meta.url), 'utf8');
const app = await readFile(new URL('../LianSyn-platform/app.js', import.meta.url), 'utf8');