fix: 修复强制重置密码流程与表单状态

- 修正强制改密跳转及免旧密码的服务端校验

- 统一双端表单错误布局与更新按钮加载状态

- 补充认证服务和强制改密路由测试
This commit is contained in:
2026-07-30 15:03:53 +08:00
parent 03f45212ef
commit 1b40829135
20 changed files with 535 additions and 117 deletions

View File

@@ -0,0 +1,65 @@
import { createMemoryHistory, createRouter } from 'vue-router';
import { describe, expect, it, vi } from 'vitest';
import {
buildForcePasswordRoute,
isForcePasswordRoute,
isPasswordResetRequired,
resolveForcePasswordPath,
} from '#/utils/password-reset';
vi.mock('element-plus', () => ({
ElMessage: vi.fn(),
}));
vi.mock('#/locales', () => ({
$t: (key: string) => key,
}));
function createTestRouter() {
return createRouter({
history: createMemoryHistory(),
routes: [
{
name: 'FallbackNotFound',
path: '/:path(.*)*',
component: { template: '<div />' },
},
],
});
}
describe('password reset route', () => {
it('can resolve the forced password path before Profile is registered', () => {
const router = createTestRouter();
const route = router.resolve(buildForcePasswordRoute());
expect(route.fullPath).toBe('/profile?force=1&tab=password');
expect(isForcePasswordRoute(route)).toBe(true);
expect(resolveForcePasswordPath(router)).toBe(
'/profile?force=1&tab=password',
);
});
it('matches Profile after the dynamic route is registered', () => {
const router = createTestRouter();
const targetPath = router.resolve(buildForcePasswordRoute()).fullPath;
router.addRoute({
name: 'Profile',
path: '/profile',
component: { template: '<div />' },
});
expect(router.resolve(targetPath).name).toBe('Profile');
});
it('uses the account state as the authoritative password reset signal', () => {
expect(isPasswordResetRequired({ passwordResetRequired: true })).toBe(true);
expect(isPasswordResetRequired({ passwordResetRequired: false })).toBe(
false,
);
expect(isPasswordResetRequired()).toBe(false);
});
});