feat(web): 同步预约演示与兜底渠道优化

This commit is contained in:
qiubaishen
2026-11-23 17:54:37 +08:00
parent 4317f99801
commit 87d4871418
11 changed files with 361 additions and 79 deletions
+80
View File
@@ -0,0 +1,80 @@
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import test from 'node:test';
const source = readFileSync(
new URL('../../src/hooks/video/useVideoGeneration.js', import.meta.url),
'utf8',
);
test('a refresh uses a new list request when the same page GET is pending', async () => {
const start = source.indexOf(' const loadTasks = useCallback(');
const end = source.indexOf(' const pollOnce =', start);
assert.ok(start >= 0 && end > start);
const loadTasksSource = source.slice(start, end);
const ref = (current) => ({ current });
const noop = () => {};
const issued = [];
let pending;
let visible;
const api = {
get(url, options) {
assert.equal(url, '/api/video/tasks');
if (pending && !options.disableDuplicate) return pending;
let resolve;
const promise = new Promise((finish) => {
resolve = finish;
});
pending = promise;
issued.push({ options, resolve });
return promise;
},
};
const createLoader = new Function(
'API',
'useCallback',
'taskQueryRef',
'taskRequestRef',
'mountedRef',
'setTaskPage',
'setTaskPageSize',
'setTasksLoading',
'setTasks',
'setTaskTotal',
'trackTasks',
'ACTIVE_STATUSES',
'normalizeVideoTaskStatus',
loadTasksSource + '\nreturn loadTasks;',
);
const load = createLoader(
api,
(fn) => fn,
ref({ page: 2, pageSize: 10 }),
ref(0),
ref(true),
noop,
noop,
noop,
(value) => {
visible = value;
},
noop,
noop,
new Set(),
(status) => status,
);
const earlier = load();
const afterWrite = load();
assert.equal(issued.length, 2);
assert.deepEqual(issued[1].options.params, { p: 2, page_size: 10 });
const response = (id) => ({
data: { success: true, data: { items: [{ task_id: id }], total: 12 } },
});
issued[1].resolve(response('remaining'));
await afterWrite;
issued[0].resolve(response('deleted'));
await earlier;
assert.deepEqual(visible, [{ task_id: 'remaining' }]);
});