feat: 更新 isContributionButtonLocked 逻辑,确保在自动运行时按钮可用,并调整相关测试
This commit is contained in:
@@ -923,9 +923,17 @@ function syncAutoRunState(source = {}) {
|
||||
}
|
||||
|
||||
function isContributionButtonLocked() {
|
||||
const autoActive = currentAutoRun.autoRunning
|
||||
|| isAutoRunLockedPhase()
|
||||
|| isAutoRunPausedPhase()
|
||||
|| isAutoRunScheduledPhase();
|
||||
if (autoActive) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const statuses = getStepStatuses();
|
||||
const anyRunning = Object.values(statuses).some((status) => status === 'running');
|
||||
return anyRunning || isAutoRunLockedPhase() || isAutoRunPausedPhase() || isAutoRunScheduledPhase();
|
||||
return anyRunning;
|
||||
}
|
||||
|
||||
function isAutoRunLockedPhase() {
|
||||
|
||||
@@ -51,7 +51,7 @@ function extractFunction(name) {
|
||||
test('sidepanel html contains contribution button in header', () => {
|
||||
const html = fs.readFileSync('sidepanel/sidepanel.html', 'utf8');
|
||||
assert.match(html, /id="btn-contribution-mode"/);
|
||||
assert.match(html, />贡献</);
|
||||
assert.match(html, />\u8d21\u732e</);
|
||||
});
|
||||
|
||||
test('openContributionUploadPage opens upload page in a new tab directly', async () => {
|
||||
@@ -87,18 +87,96 @@ return {
|
||||
]);
|
||||
});
|
||||
|
||||
test('openContributionUploadPage blocks while flow is running', async () => {
|
||||
test('isContributionButtonLocked keeps contribution button available during auto-run', () => {
|
||||
const bundle = [
|
||||
extractFunction('isContributionButtonLocked'),
|
||||
].join('\n');
|
||||
|
||||
const api = new Function(`
|
||||
const currentAutoRun = { autoRunning: true, phase: 'running' };
|
||||
function getStepStatuses() {
|
||||
return { 1: 'running', 2: 'pending' };
|
||||
}
|
||||
function isAutoRunLockedPhase() {
|
||||
return true;
|
||||
}
|
||||
function isAutoRunPausedPhase() {
|
||||
return false;
|
||||
}
|
||||
function isAutoRunScheduledPhase() {
|
||||
return false;
|
||||
}
|
||||
${bundle}
|
||||
return { isContributionButtonLocked };
|
||||
`)();
|
||||
|
||||
assert.equal(api.isContributionButtonLocked(), false);
|
||||
});
|
||||
|
||||
test('openContributionUploadPage remains available during auto-run', async () => {
|
||||
const bundle = [
|
||||
extractFunction('isContributionButtonLocked'),
|
||||
extractFunction('openContributionUploadPage'),
|
||||
].join('\n');
|
||||
|
||||
const api = new Function(`
|
||||
const calls = [];
|
||||
const CONTRIBUTION_UPLOAD_URL = 'https://apikey.qzz.io/';
|
||||
const currentAutoRun = { autoRunning: true, phase: 'running' };
|
||||
function getStepStatuses() {
|
||||
return { 1: 'running', 2: 'pending' };
|
||||
}
|
||||
function isAutoRunLockedPhase() {
|
||||
return true;
|
||||
}
|
||||
function isAutoRunPausedPhase() {
|
||||
return false;
|
||||
}
|
||||
function isAutoRunScheduledPhase() {
|
||||
return false;
|
||||
}
|
||||
function openExternalUrl(url) {
|
||||
calls.push({ type: 'open', url });
|
||||
}
|
||||
${bundle}
|
||||
return {
|
||||
openContributionUploadPage,
|
||||
getCalls() {
|
||||
return calls;
|
||||
},
|
||||
};
|
||||
`)();
|
||||
|
||||
const result = await api.openContributionUploadPage();
|
||||
assert.equal(result, true);
|
||||
assert.deepStrictEqual(api.getCalls(), [
|
||||
{
|
||||
type: 'open',
|
||||
url: 'https://apikey.qzz.io/',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test('openContributionUploadPage blocks while manual flow is running', async () => {
|
||||
const bundle = [
|
||||
extractFunction('isContributionButtonLocked'),
|
||||
extractFunction('openContributionUploadPage'),
|
||||
].join('\n');
|
||||
|
||||
const api = new Function(`
|
||||
const CONTRIBUTION_UPLOAD_URL = 'https://apikey.qzz.io/';
|
||||
function isContributionButtonLocked() {
|
||||
return true;
|
||||
const currentAutoRun = { autoRunning: false, phase: 'idle' };
|
||||
function getStepStatuses() {
|
||||
return { 1: 'running', 2: 'pending' };
|
||||
}
|
||||
async function openConfirmModal() {
|
||||
throw new Error('should not open modal');
|
||||
function isAutoRunLockedPhase() {
|
||||
return false;
|
||||
}
|
||||
function isAutoRunPausedPhase() {
|
||||
return false;
|
||||
}
|
||||
function isAutoRunScheduledPhase() {
|
||||
return false;
|
||||
}
|
||||
function openExternalUrl() {
|
||||
throw new Error('should not open url');
|
||||
@@ -109,6 +187,9 @@ return { openContributionUploadPage };
|
||||
|
||||
await assert.rejects(
|
||||
() => api.openContributionUploadPage(),
|
||||
/当前流程运行中/
|
||||
(error) => {
|
||||
assert.match(error.message, /\u5f53\u524d\u6d41\u7a0b\u8fd0\u884c\u4e2d/);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
+2
-1
@@ -176,7 +176,8 @@
|
||||
- 当前这颗按钮不参与 1~10 步主流程
|
||||
- 当前这颗按钮不调用后台管理接口
|
||||
- 当前这颗按钮不保存额外运行态
|
||||
- 当步骤正在运行或自动流程处于锁定状态时,按钮会禁用,避免和主流程冲突
|
||||
- Auto 运行中不会跟随主流程按钮一起被禁用,仍可直接点击打开上传页
|
||||
- 手动单步流程运行时,按钮仍会禁用,避免和同页操作冲突
|
||||
|
||||
## 5. 内容脚本通信链路
|
||||
|
||||
|
||||
Reference in New Issue
Block a user