feat: 增强手机号注册流程,确保手机号输入页就绪后再申请号码并提交
This commit is contained in:
@@ -440,6 +440,191 @@ return {
|
||||
assert.equal(api.run()?.kind, 'localized-email');
|
||||
});
|
||||
|
||||
test('ensureSignupPhoneEntryReady opens free signup before switching to the phone entry', async () => {
|
||||
const api = new Function(`
|
||||
const logs = [];
|
||||
const clicks = [];
|
||||
let phase = 'entry';
|
||||
let now = 0;
|
||||
|
||||
const signupButton = {
|
||||
textContent: '免费注册',
|
||||
value: '',
|
||||
disabled: false,
|
||||
getAttribute(name) {
|
||||
if (name === 'type') return 'button';
|
||||
return '';
|
||||
},
|
||||
getBoundingClientRect() {
|
||||
return { width: 120, height: 36 };
|
||||
},
|
||||
};
|
||||
|
||||
const switchButton = {
|
||||
textContent: 'Continue with phone number',
|
||||
value: '',
|
||||
disabled: false,
|
||||
getAttribute(name) {
|
||||
if (name === 'type') return 'button';
|
||||
return '';
|
||||
},
|
||||
getBoundingClientRect() {
|
||||
return { width: 200, height: 48 };
|
||||
},
|
||||
};
|
||||
|
||||
const emailInput = {
|
||||
kind: 'email',
|
||||
getAttribute(name) {
|
||||
if (name === 'type') return 'email';
|
||||
return '';
|
||||
},
|
||||
};
|
||||
|
||||
const phoneInput = {
|
||||
kind: 'phone',
|
||||
getAttribute(name) {
|
||||
if (name === 'type') return 'tel';
|
||||
return '';
|
||||
},
|
||||
};
|
||||
|
||||
const document = {
|
||||
querySelector(selector) {
|
||||
if (selector === SIGNUP_EMAIL_INPUT_SELECTOR) {
|
||||
return phase === 'email' ? emailInput : null;
|
||||
}
|
||||
if (selector === SIGNUP_PHONE_INPUT_SELECTOR) {
|
||||
return phase === 'phone' ? phoneInput : null;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
querySelectorAll(selector) {
|
||||
if (selector === 'button, a, [role="button"], [role="link"]') {
|
||||
return phase === 'email' ? [switchButton] : [];
|
||||
}
|
||||
if (selector === 'a, button, [role="button"], [role="link"]') {
|
||||
return phase === 'entry' ? [signupButton] : [];
|
||||
}
|
||||
if (selector === 'input') {
|
||||
if (phase === 'email') return [emailInput];
|
||||
if (phase === 'phone') return [phoneInput];
|
||||
return [];
|
||||
}
|
||||
return [];
|
||||
},
|
||||
};
|
||||
|
||||
const location = {
|
||||
href: 'https://chatgpt.com/',
|
||||
};
|
||||
|
||||
const Date = {
|
||||
now() {
|
||||
return now;
|
||||
},
|
||||
};
|
||||
|
||||
${extractConst('SIGNUP_ENTRY_TRIGGER_PATTERN')}
|
||||
${extractConst('SIGNUP_EMAIL_INPUT_SELECTOR')}
|
||||
${extractConst('SIGNUP_PHONE_INPUT_SELECTOR')}
|
||||
${extractConst('SIGNUP_SWITCH_TO_EMAIL_PATTERN')}
|
||||
${extractConst('SIGNUP_SWITCH_ACTION_PATTERN')}
|
||||
${extractConst('SIGNUP_EMAIL_ACTION_PATTERN')}
|
||||
${extractConst('SIGNUP_WORK_EMAIL_PATTERN')}
|
||||
${extractConst('SIGNUP_PHONE_ACTION_PATTERN')}
|
||||
${extractConst('SIGNUP_SWITCH_TO_PHONE_PATTERN')}
|
||||
${extractConst('SIGNUP_MORE_OPTIONS_PATTERN')}
|
||||
|
||||
function isVisibleElement(el) {
|
||||
return Boolean(el);
|
||||
}
|
||||
|
||||
function isActionEnabled(el) {
|
||||
return Boolean(el) && !el.disabled && el.getAttribute('aria-disabled') !== 'true';
|
||||
}
|
||||
|
||||
function getActionText(el) {
|
||||
return [el?.textContent, el?.value, el?.getAttribute?.('aria-label'), el?.getAttribute?.('title')]
|
||||
.filter(Boolean)
|
||||
.join(' ')
|
||||
.replace(/\\s+/g, ' ')
|
||||
.trim();
|
||||
}
|
||||
|
||||
function getSignupPasswordInput() {
|
||||
return null;
|
||||
}
|
||||
|
||||
function isSignupPasswordPage() {
|
||||
return false;
|
||||
}
|
||||
|
||||
function getSignupPasswordSubmitButton() {
|
||||
return null;
|
||||
}
|
||||
|
||||
function getSignupPasswordDisplayedEmail() {
|
||||
return '';
|
||||
}
|
||||
|
||||
function getPageTextSnapshot() {
|
||||
return phase === 'entry' ? '登录 免费注册' : '';
|
||||
}
|
||||
|
||||
function throwIfStopped() {}
|
||||
|
||||
function log(message, level = 'info') {
|
||||
logs.push({ message, level });
|
||||
}
|
||||
|
||||
async function humanPause() {}
|
||||
|
||||
function simulateClick(target) {
|
||||
clicks.push(getActionText(target));
|
||||
if (target === signupButton) {
|
||||
phase = 'email';
|
||||
} else if (target === switchButton) {
|
||||
phase = 'phone';
|
||||
}
|
||||
}
|
||||
|
||||
async function sleep(ms) {
|
||||
now += ms;
|
||||
}
|
||||
|
||||
${extractFunction('getSignupEmailInput')}
|
||||
${extractFunction('getSignupPhoneInput')}
|
||||
${extractFunction('findSignupUseEmailTrigger')}
|
||||
${extractFunction('findSignupUsePhoneTrigger')}
|
||||
${extractFunction('findSignupMoreOptionsTrigger')}
|
||||
${extractFunction('getSignupEmailContinueButton')}
|
||||
${extractFunction('findSignupEntryTrigger')}
|
||||
${extractFunction('inspectSignupEntryState')}
|
||||
${extractFunction('waitForSignupPhoneEntryState')}
|
||||
function getSignupEntryDiagnostics() { return {}; }
|
||||
${extractFunction('ensureSignupPhoneEntryReady')}
|
||||
|
||||
return {
|
||||
async run() {
|
||||
return ensureSignupPhoneEntryReady();
|
||||
},
|
||||
getClicks() {
|
||||
return clicks.slice();
|
||||
},
|
||||
};
|
||||
`)();
|
||||
|
||||
const result = await api.run();
|
||||
|
||||
assert.deepEqual(result, {
|
||||
ready: true,
|
||||
state: 'phone_entry',
|
||||
url: 'https://chatgpt.com/',
|
||||
});
|
||||
assert.deepEqual(api.getClicks(), ['免费注册', 'Continue with phone number']);
|
||||
});
|
||||
|
||||
test('submitSignupPhoneNumberAndContinue switches from email mode to phone mode and submits local number', async () => {
|
||||
const api = new Function(`
|
||||
const logs = [];
|
||||
|
||||
Reference in New Issue
Block a user