fix(auth/user-center): 修复个人登录回跳并兼容旧入口

This commit is contained in:
zhanjunhao
2026-12-01 16:07:31 +08:00
parent 7e89edda5b
commit cd6eae5ed9
5 changed files with 60 additions and 42 deletions
+15 -2
View File
@@ -10,6 +10,7 @@ const StatusContext = {};
const UserContext = {};
let config;
let userGroup = 'default';
let location = { pathname: '/user-center/service-dashboard' };
const mocks = {
react: {
...React,
@@ -24,7 +25,7 @@ const mocks = {
Route: 'route',
Navigate: 'navigate',
Link: 'link',
useLocation: () => ({ pathname: '/user-center/service-dashboard' }),
useLocation: () => location,
useNavigate: () => () => {},
},
'react-i18next': { useTranslation: () => ({ t: (value) => value }) },
@@ -151,6 +152,11 @@ for (const [name, userCenter, group, visible] of [
}
test('service dashboard can be the only enabled default route without a redirect loop', () => {
location = {
pathname: '/user-center',
search: '?from=bookmark',
hash: '#top',
};
config = JSON.stringify({
userCenter: {
...Object.fromEntries(
@@ -164,7 +170,14 @@ test('service dashboard can be the only enabled default route without a redirect
});
const nodes = descendants(UserCenter({}));
const route = nodes.find((node) => node.props.path === '/');
assert.equal(route.props.element.props.to, '/user-center/service-dashboard');
assert.deepEqual(
{ ...route.props.element.props.to },
{
pathname: '/user-center/service-dashboard',
search: location.search,
hash: location.hash,
},
);
const service = nodes.find((node) => node.props.path === 'service-dashboard');
assert.ok(
descendants(service.props.element).some(