feat: 增强认证页恢复逻辑,处理 405 错误页面,更新相关测试
This commit is contained in:
@@ -18,11 +18,11 @@ function createRetryButton() {
|
||||
function createRecoveryApi(state) {
|
||||
const retryButton = createRetryButton();
|
||||
global.location = {
|
||||
pathname: '/log-in',
|
||||
href: 'https://auth.openai.com/log-in',
|
||||
pathname: state.pathname || '/log-in',
|
||||
href: state.href || `https://auth.openai.com${state.pathname || '/log-in'}`,
|
||||
};
|
||||
global.document = {
|
||||
title: 'Something went wrong',
|
||||
title: state.title ?? 'Something went wrong',
|
||||
querySelector(selector) {
|
||||
if (selector === 'button[data-dd-action-name="Try again"]' && state.retryVisible) {
|
||||
return retryButton;
|
||||
@@ -42,6 +42,7 @@ function createRecoveryApi(state) {
|
||||
isActionEnabled: (element) => Boolean(element) && !element.disabled && element.getAttribute('aria-disabled') !== 'true',
|
||||
isVisibleElement: () => true,
|
||||
log: () => {},
|
||||
routeErrorPattern: /405\s+method\s+not\s+allowed|route\s+error.*405/i,
|
||||
simulateClick: () => {
|
||||
state.clickCount += 1;
|
||||
if (typeof state.onClick === 'function') {
|
||||
@@ -78,9 +79,30 @@ test('auth page recovery detects retry page state', () => {
|
||||
assert.equal(snapshot.retryEnabled, true);
|
||||
assert.equal(snapshot.titleMatched, true);
|
||||
assert.equal(snapshot.detailMatched, false);
|
||||
assert.equal(snapshot.routeErrorMatched, false);
|
||||
assert.equal(snapshot.maxCheckAttemptsBlocked, false);
|
||||
});
|
||||
|
||||
test('auth page recovery detects route error retry page on email verification route', () => {
|
||||
const state = {
|
||||
clickCount: 0,
|
||||
pageText: 'Route Error (405 Method Not Allowed): email-verification action missing.',
|
||||
pathname: '/email-verification',
|
||||
retryVisible: true,
|
||||
title: '',
|
||||
};
|
||||
const api = createRecoveryApi(state);
|
||||
|
||||
const snapshot = api.getAuthTimeoutErrorPageState({
|
||||
pathPatterns: [/\/email-verification(?:[/?#]|$)/i],
|
||||
});
|
||||
|
||||
assert.equal(Boolean(snapshot), true);
|
||||
assert.equal(snapshot.titleMatched, false);
|
||||
assert.equal(snapshot.detailMatched, false);
|
||||
assert.equal(snapshot.routeErrorMatched, true);
|
||||
});
|
||||
|
||||
test('auth page recovery clicks retry and waits until page recovers', async () => {
|
||||
const state = {
|
||||
clickCount: 0,
|
||||
|
||||
@@ -140,3 +140,53 @@ return {
|
||||
retryButton: { textContent: 'Try again' },
|
||||
});
|
||||
});
|
||||
|
||||
test('signup verification state treats email-verification retry page as error instead of verification', () => {
|
||||
const api = new Function(`
|
||||
const location = {
|
||||
pathname: '/email-verification',
|
||||
};
|
||||
|
||||
function getAuthTimeoutErrorPageState(options) {
|
||||
return options.pathPatterns.some((pattern) => pattern.test(location.pathname))
|
||||
? { retryButton: { textContent: 'Try again' } }
|
||||
: null;
|
||||
}
|
||||
|
||||
function isStep5Ready() {
|
||||
return false;
|
||||
}
|
||||
|
||||
function isVerificationPageStillVisible() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function isSignupEmailAlreadyExistsPage() {
|
||||
return false;
|
||||
}
|
||||
|
||||
function getSignupPasswordInput() {
|
||||
return null;
|
||||
}
|
||||
|
||||
function getSignupPasswordSubmitButton() {
|
||||
return null;
|
||||
}
|
||||
|
||||
${extractFunction('getSignupAuthRetryPathPatterns')}
|
||||
${extractFunction('getSignupPasswordTimeoutErrorPageState')}
|
||||
${extractFunction('isSignupPasswordErrorPage')}
|
||||
${extractFunction('inspectSignupVerificationState')}
|
||||
|
||||
return {
|
||||
run() {
|
||||
return inspectSignupVerificationState();
|
||||
},
|
||||
};
|
||||
`)();
|
||||
|
||||
assert.deepStrictEqual(api.run(), {
|
||||
state: 'error',
|
||||
retryButton: { textContent: 'Try again' },
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user