feat: 添加贡献模式昵称和QQ字段,更新相关逻辑和测试

This commit is contained in:
QLHazyCoder
2026-04-20 13:15:22 +08:00
parent 4e9acfd2ee
commit 8a16d81e01
8 changed files with 187 additions and 10 deletions
+20 -9
View File
@@ -92,6 +92,8 @@ const DEFAULT_STATE = { panelMode: 'cpa' };
const CONTRIBUTION_RUNTIME_DEFAULTS = {
contributionMode: false,
contributionModeExpected: false,
contributionNickname: '',
contributionQq: '',
contributionSessionId: '',
contributionAuthUrl: '',
contributionAuthState: '',
@@ -123,6 +125,8 @@ return { buildContributionModeState };
{
contributionMode: true,
contributionModeExpected: true,
contributionNickname: '',
contributionQq: '',
contributionSessionId: 'session-001',
contributionAuthUrl: 'https://auth.example.com',
contributionAuthState: '',
@@ -153,6 +157,8 @@ return { buildContributionModeState };
{
contributionMode: false,
contributionModeExpected: false,
contributionNickname: '',
contributionQq: '',
contributionSessionId: '',
contributionAuthUrl: '',
contributionAuthState: '',
@@ -215,7 +221,7 @@ test('message router handles contribution mode, start flow, and status polling m
});
const startResponse = await router.handleMessage({
type: 'START_CONTRIBUTION_FLOW',
payload: { nickname: '阿青' },
payload: { nickname: '阿青', qq: '123456' },
});
const pollResponse = await router.handleMessage({
type: 'POLL_CONTRIBUTION_STATUS',
@@ -227,7 +233,7 @@ test('message router handles contribution mode, start flow, and status polling m
assert.equal(pollResponse.ok, true);
assert.deepStrictEqual(calls, [
{ type: 'toggle', enabled: true },
{ type: 'start', options: { nickname: '阿青' } },
{ type: 'start', options: { nickname: '阿青', qq: '123456' } },
{ type: 'poll', options: { reason: 'test_poll' } },
]);
});
@@ -260,17 +266,20 @@ test('message router re-syncs contribution mode before AUTO_RUN when sidepanel p
const response = await router.handleMessage({
type: 'AUTO_RUN',
payload: {
totalRuns: 2,
autoRunSkipFailures: true,
mode: 'restart',
contributionMode: true,
},
});
payload: {
totalRuns: 2,
autoRunSkipFailures: true,
mode: 'restart',
contributionMode: true,
contributionNickname: '阿青',
contributionQq: '123456',
},
});
assert.equal(response.ok, true);
assert.deepStrictEqual(calls, [
{ type: 'toggle', enabled: true },
{ type: 'setState', updates: { contributionNickname: '阿青', contributionQq: '123456' } },
{ type: 'setState', updates: { autoRunSkipFailures: true } },
{ type: 'startAutoRunLoop', totalRuns: 2, options: { autoRunSkipFailures: true, mode: 'restart' } },
]);
@@ -412,6 +421,8 @@ test('contribution oauth manager starts session, opens auth url, submits callbac
assert.equal(startedState.contributionAuthTabId, 88);
assert.equal(tabCalls.length, 1);
assert.match(fetchCalls[0].url, /\/start$/);
assert.match(String(fetchCalls[0].options.body || ''), /"nickname":"user@example\.com"/);
assert.match(String(fetchCalls[0].options.body || ''), /"qq":""/);
assert.match(fetchCalls[1].url, /\/status\?/);
const callbackState = await manager.handleCapturedCallback(
+30 -1
View File
@@ -111,6 +111,8 @@ test('sidepanel html contains contribution mode runtime UI and loads the module
assert.match(html, /id="btn-start-contribution"/);
assert.match(html, /id="btn-open-contribution-upload"/);
assert.match(html, /id="btn-exit-contribution-mode"/);
assert.match(html, /id="input-contribution-nickname"/);
assert.match(html, /id="input-contribution-qq"/);
assert.notEqual(moduleIndex, -1);
assert.notEqual(sidepanelIndex, -1);
assert.ok(moduleIndex < sidepanelIndex);
@@ -246,6 +248,8 @@ test('contribution mode manager enters mode, starts main auto flow, polls contri
btnOpenAccountRecords: createElement(),
btnOpenContributionUpload: createElement(),
btnStartContribution: createElement(),
inputContributionNickname: createElement({ value: '贡献者昵称' }),
inputContributionQq: createElement({ value: '123456' }),
contributionCallbackStatus: createElement(),
contributionModePanel: createElement({ hidden: true }),
contributionModeSummary: createElement(),
@@ -284,6 +288,12 @@ test('contribution mode manager enters mode, starts main auto flow, polls contri
getContributionNickname() {
return latestState.email;
},
getContributionProfile() {
return {
nickname: dom.inputContributionNickname.value,
qq: dom.inputContributionQq.value,
};
},
isModeSwitchBlocked() {
return blocked;
},
@@ -332,6 +342,8 @@ test('contribution mode manager enters mode, starts main auto flow, polls contri
? {
contributionMode: true,
panelMode: 'cpa',
contributionNickname: '',
contributionQq: '',
contributionSessionId: '',
contributionAuthUrl: '',
contributionAuthState: '',
@@ -344,6 +356,8 @@ test('contribution mode manager enters mode, starts main auto flow, polls contri
: {
contributionMode: false,
panelMode: 'cpa',
contributionNickname: '',
contributionQq: '',
contributionSessionId: '',
contributionAuthUrl: '',
contributionAuthState: '',
@@ -367,6 +381,14 @@ test('contribution mode manager enters mode, starts main auto flow, polls contri
},
};
}
if (message.type === 'SET_CONTRIBUTION_PROFILE') {
latestState = {
...latestState,
contributionNickname: message.payload.nickname,
contributionQq: message.payload.qq,
};
return { state: latestState };
}
return {};
},
},
@@ -399,11 +421,16 @@ test('contribution mode manager enters mode, starts main auto flow, polls contri
assert.ok(updateConfigMenuCount >= 1);
assert.equal(timers.length, 0);
dom.inputContributionNickname.value = '贡献者昵称';
dom.inputContributionQq.value = '123456';
await dom.btnStartContribution.listeners.click();
assert.equal(contributionAutoRunStartCount, 1);
assert.equal(appliedState.contributionSessionId, '');
assert.equal(latestState.contributionSessionId, 'session-002');
assert.equal(latestState.contributionStatus, 'started');
const contributionProfileMessage = sentMessages.find((message) => message.type === 'SET_CONTRIBUTION_PROFILE');
assert.deepStrictEqual(contributionProfileMessage?.payload, { nickname: '贡献者昵称', qq: '123456' });
assert.equal(timers.length > 0, true);
await manager.pollOnce({ reason: 'test_poll' });
@@ -423,7 +450,7 @@ test('contribution mode manager enters mode, starts main auto flow, polls contri
assert.equal(dom.rowVpsUrl.classList.contains('is-contribution-hidden'), false);
assert.deepStrictEqual(
sentMessages.map((message) => message.type),
['SET_CONTRIBUTION_MODE', 'POLL_CONTRIBUTION_STATUS', 'SET_CONTRIBUTION_MODE']
['SET_CONTRIBUTION_MODE', 'SET_CONTRIBUTION_PROFILE', 'POLL_CONTRIBUTION_STATUS', 'SET_CONTRIBUTION_MODE']
);
assert.deepStrictEqual(
toasts.map((item) => item.message),
@@ -434,6 +461,8 @@ test('contribution mode manager enters mode, starts main auto flow, polls contri
latestState = {
contributionMode: true,
panelMode: 'cpa',
contributionNickname: '贡献者昵称',
contributionQq: '123456',
contributionSessionId: 'session-002',
contributionAuthUrl: 'https://auth.example.com/oauth?state=oauth-state-002',
contributionStatus: 'waiting',