Plua模式开发

This commit is contained in:
QLHazyCoder
2026-04-26 01:41:40 +08:00
parent 12e6225eba
commit 6ad866b962
25 changed files with 2173 additions and 207 deletions
+23
View File
@@ -0,0 +1,23 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
test('address sources normalize supported countries and return local seeds', () => {
const source = fs.readFileSync('data/address-sources.js', 'utf8');
const globalScope = {};
const api = new Function('self', `${source}; return self.MultiPageAddressSources;`)(globalScope);
assert.equal(api.normalizeCountryCode('Deutschland'), 'DE');
assert.equal(api.normalizeCountryCode('澳大利亚'), 'AU');
assert.equal(api.normalizeCountryCode('unknown'), '');
const deSeed = api.getAddressSeedForCountry('DE');
assert.equal(deSeed.countryCode, 'DE');
assert.equal(deSeed.suggestionIndex, 1);
assert.equal(Boolean(deSeed.query), true);
assert.equal(Boolean(deSeed.fallback.city), true);
const fallbackSeed = api.getAddressSeedForCountry('unknown', { fallbackCountry: 'AU' });
assert.equal(fallbackSeed.countryCode, 'AU');
assert.equal(fallbackSeed.fallback.region, 'New South Wales');
});
+18
View File
@@ -118,6 +118,9 @@ function isRetryableContentScriptTransportError() {
return false;
}
const stepRegistry = {
getStepDefinition(step) {
return { id: step, key: 'test-step' };
},
async executeStep(step) {
events.registryCalls.push(step);
if (step === 8) {
@@ -127,6 +130,12 @@ const stepRegistry = {
}
},
};
function getStepRegistryForState() {
return stepRegistry;
}
function getStepDefinitionForState(step) {
return { id: step, key: 'test-step' };
}
${extractFunction('isStopError')}
${extractFunction('throwIfStopped')}
@@ -212,10 +221,19 @@ function isRetryableContentScriptTransportError() {
return false;
}
const stepRegistry = {
getStepDefinition(step) {
return { id: step, key: 'test-step' };
},
async executeStep() {
throw new Error('BROWSER_SWITCH_REQUIRED::请更换浏览器进行注册登录。');
},
};
function getStepRegistryForState() {
return stepRegistry;
}
function getStepDefinitionForState(step) {
return { id: step, key: 'test-step' };
}
${extractFunction('isStopError')}
${extractFunction('throwIfStopped')}
+6 -1
View File
@@ -7,5 +7,10 @@ test('background imports step registry and shared step definitions', () => {
assert.match(source, /background\/steps\/registry\.js/);
assert.match(source, /data\/step-definitions\.js/);
assert.match(source, /MultiPageStepDefinitions\?\.getSteps/);
assert.match(source, /stepRegistry\.executeStep\(step,\s*state\)/);
assert.match(source, /getStepRegistryForState\(state\)/);
assert.match(source, /activeStepRegistry\.executeStep\(step,\s*\{/);
assert.match(source, /background\/steps\/create-plus-checkout\.js/);
assert.match(source, /background\/steps\/fill-plus-checkout\.js/);
assert.match(source, /background\/steps\/paypal-approve\.js/);
assert.match(source, /background\/steps\/plus-return-confirm\.js/);
});
+31 -2
View File
@@ -2,15 +2,16 @@ const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
test('step definitions module exposes ordered shared step metadata', () => {
test('step definitions module exposes ordered normal and Plus step metadata', () => {
const source = fs.readFileSync('data/step-definitions.js', 'utf8');
const globalScope = {};
const api = new Function('self', `${source}; return self.MultiPageStepDefinitions;`)(globalScope);
const steps = api.getSteps();
const plusSteps = api.getSteps({ plusModeEnabled: true });
assert.equal(Array.isArray(steps), true);
assert.equal(steps.length >= 10, true);
assert.equal(steps.length, 10);
assert.deepStrictEqual(
steps.map((step) => step.order),
steps.map((step) => step.order).slice().sort((left, right) => left - right)
@@ -30,6 +31,27 @@ test('step definitions module exposes ordered shared step metadata', () => {
'platform-verify',
]
);
assert.deepStrictEqual(
plusSteps.map((step) => step.key),
[
'open-chatgpt',
'submit-signup-email',
'fill-password',
'fetch-signup-code',
'fill-profile',
'plus-checkout-create',
'plus-checkout-billing',
'paypal-approve',
'plus-checkout-return',
'oauth-login',
'confirm-oauth',
'platform-verify',
]
);
assert.equal(plusSteps.some((step) => step.key === 'clear-login-cookies'), false);
assert.equal(plusSteps.some((step) => step.key === 'fetch-login-code'), false);
assert.deepStrictEqual(api.getStepIds({ plusModeEnabled: true }), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
assert.equal(api.getLastStepId({ plusModeEnabled: true }), 12);
});
test('sidepanel html loads shared step definitions before sidepanel bootstrap', () => {
@@ -41,3 +63,10 @@ test('sidepanel html loads shared step definitions before sidepanel bootstrap',
assert.notEqual(sidepanelIndex, -1);
assert.ok(definitionsIndex < sidepanelIndex);
});
test('sidepanel html exposes Plus mode and PayPal settings', () => {
const html = fs.readFileSync('sidepanel/sidepanel.html', 'utf8');
assert.match(html, /id="input-plus-mode-enabled"/);
assert.match(html, /id="input-paypal-email"/);
assert.match(html, /id="input-paypal-password"/);
});