feat: 同步管理端、用户端与后端业务,并接通线上 Web 接口
补齐平台订阅、外部登录、CRM 同步与用户端页面;Nginx 转发用户端接口,登录页使用 Google 与 Apple 标志。 Co-authored-by: Cursor <cursoragent@cursor.com>
这个提交包含在:
@@ -55,6 +55,36 @@ type StorageApi = {
|
||||
setStorageSync: (key: string, value: unknown) => void;
|
||||
};
|
||||
|
||||
type CardProfileFixture = {
|
||||
id?: string | number;
|
||||
name: string;
|
||||
title?: string;
|
||||
company?: string;
|
||||
department?: string;
|
||||
avatarUrl?: string;
|
||||
};
|
||||
|
||||
type OwnerPageQuery = {
|
||||
page: number;
|
||||
size: number;
|
||||
keyWord?: string;
|
||||
};
|
||||
|
||||
type OwnerPageData<T> = {
|
||||
list: T[];
|
||||
pagination: {
|
||||
page: number;
|
||||
size: number;
|
||||
total: number;
|
||||
};
|
||||
};
|
||||
|
||||
type LoadProfileAccountApi = {
|
||||
fetchOwnerCardPage: (
|
||||
query: OwnerPageQuery
|
||||
) => Promise<OwnerPageData<CardProfileFixture>>;
|
||||
};
|
||||
|
||||
type UseProfileModule = {
|
||||
PROFILE_ACCOUNT_STORAGE_KEY: string;
|
||||
PROFILE_NOTIFICATIONS_STORAGE_KEY: string;
|
||||
@@ -70,9 +100,17 @@ type UseProfileModule = {
|
||||
setPreferredLocale: (state: ProfileState, locale: string, storage?: StorageApi) => OmniLocale;
|
||||
calculateQuotaPercent: (used: number, limit: number) => number;
|
||||
resolveProfileText: (key: string) => string;
|
||||
displayOrgField: (value: string | null | undefined) => string;
|
||||
clearOrgFields: (state: ProfileState) => void;
|
||||
loadOwnerProfileAccount: (
|
||||
state: ProfileState,
|
||||
api?: LoadProfileAccountApi
|
||||
) => Promise<boolean>;
|
||||
};
|
||||
|
||||
const EMOJI_RE = /[\u2600-\u27BF\uFE0F]|[\uD83C-\uDBFF][\uDC00-\uDFFF]/;
|
||||
const SAMPLE_ORG_RE =
|
||||
/Nexus Tech Global|Overseas Business Dept|Cyberdyne Systems|Global Trade Co\.|示例(公司|组织|部门)/;
|
||||
|
||||
function loadUseProfile(): UseProfileModule {
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
@@ -102,14 +140,17 @@ describe('OmniCard AI 名片主个人中心与消息通知配置 (useProfile.uts
|
||||
});
|
||||
|
||||
describe('1. 配置读取与初始化 (loadProfileSettings)', () => {
|
||||
it('1.1 首次无缓存时,返回默认账户资料与通知开关开启', () => {
|
||||
const { loadProfileSettings } = loadUseProfile();
|
||||
it('1.1 首次无缓存时,公司/部门为空串,通知开关开启', () => {
|
||||
const { loadProfileSettings, getDefaultAccount } = loadUseProfile();
|
||||
const defaults = getDefaultAccount();
|
||||
const state = loadProfileSettings();
|
||||
|
||||
expect(state.account.name).toBeTruthy();
|
||||
expect(state.account.company).toBeTruthy();
|
||||
expect(state.account.department).toBeTruthy();
|
||||
expect(state.account.avatar).toBeTruthy();
|
||||
expect(defaults.company).toBe('');
|
||||
expect(defaults.department).toBe('');
|
||||
expect(SAMPLE_ORG_RE.test(defaults.company)).toBe(false);
|
||||
expect(SAMPLE_ORG_RE.test(defaults.department)).toBe(false);
|
||||
expect(state.account.company).toBe('');
|
||||
expect(state.account.department).toBe('');
|
||||
expect(state.notifications.radarPush).toBe(true);
|
||||
expect(state.notifications.leadNotice).toBe(true);
|
||||
expect(state.locale).toBe('zh-CN');
|
||||
@@ -125,7 +166,7 @@ describe('OmniCard AI 名片主个人中心与消息通知配置 (useProfile.uts
|
||||
|
||||
mockStorage[PROFILE_ACCOUNT_STORAGE_KEY] = JSON.stringify({
|
||||
name: 'Sarah Connor',
|
||||
company: 'Cyberdyne Systems',
|
||||
company: 'Acme Corp',
|
||||
department: 'Security Division',
|
||||
avatar: 'https://example.com/sarah.jpg',
|
||||
});
|
||||
@@ -136,14 +177,14 @@ describe('OmniCard AI 名片主个人中心与消息通知配置 (useProfile.uts
|
||||
|
||||
const state = loadProfileSettings();
|
||||
expect(state.account.name).toBe('Sarah Connor');
|
||||
expect(state.account.company).toBe('Cyberdyne Systems');
|
||||
expect(state.account.company).toBe('Acme Corp');
|
||||
expect(state.account.department).toBe('Security Division');
|
||||
expect(state.account.avatar).toBe('https://example.com/sarah.jpg');
|
||||
expect(state.notifications.radarPush).toBe(false);
|
||||
expect(state.notifications.leadNotice).toBe(true);
|
||||
});
|
||||
|
||||
it('1.3 防御保护:缓存数据损坏时不抛错,优雅回退默认值', () => {
|
||||
it('1.3 防御保护:缓存数据损坏时不抛错,公司/部门保持空串', () => {
|
||||
const {
|
||||
loadProfileSettings,
|
||||
PROFILE_ACCOUNT_STORAGE_KEY,
|
||||
@@ -156,14 +197,14 @@ describe('OmniCard AI 名片主个人中心与消息通知配置 (useProfile.uts
|
||||
mockStorage[PROFILE_NOTIFICATIONS_STORAGE_KEY] = 'not-an-object';
|
||||
|
||||
const state = loadProfileSettings();
|
||||
expect(state.account.name).toBeTruthy();
|
||||
expect(state.account.company).toBeTruthy();
|
||||
expect(state.account.company).toBe('');
|
||||
expect(state.account.department).toBe('');
|
||||
expect(state.notifications.radarPush).toBe(true);
|
||||
expect(state.notifications.leadNotice).toBe(true);
|
||||
expect(state.errorMessage).toBe('');
|
||||
});
|
||||
|
||||
it('1.4 防御保护:缓存字段部分缺失时自动补充缺省字段', () => {
|
||||
it('1.4 防御保护:缓存缺公司/部门时保持空串,不回填示例组织', () => {
|
||||
const {
|
||||
loadProfileSettings,
|
||||
PROFILE_ACCOUNT_STORAGE_KEY,
|
||||
@@ -179,8 +220,8 @@ describe('OmniCard AI 名片主个人中心与消息通知配置 (useProfile.uts
|
||||
|
||||
const state = loadProfileSettings();
|
||||
expect(state.account.name).toBe('John Doe');
|
||||
expect(state.account.company).toBeTruthy();
|
||||
expect(state.account.department).toBeTruthy();
|
||||
expect(state.account.company).toBe('');
|
||||
expect(state.account.department).toBe('');
|
||||
expect(state.notifications.radarPush).toBe(false);
|
||||
expect(state.notifications.leadNotice).toBe(true);
|
||||
});
|
||||
@@ -297,12 +338,12 @@ describe('OmniCard AI 名片主个人中心与消息通知配置 (useProfile.uts
|
||||
|
||||
updateAccount(state, {
|
||||
name: ' Elena Rostova ',
|
||||
company: 'Global Trade Co.',
|
||||
company: 'Northwind Ltd',
|
||||
department: 'Marketing',
|
||||
});
|
||||
|
||||
expect(state.account.name).toBe('Elena Rostova');
|
||||
expect(state.account.company).toBe('Global Trade Co.');
|
||||
expect(state.account.company).toBe('Northwind Ltd');
|
||||
expect(state.account.department).toBe('Marketing');
|
||||
|
||||
const saved = saveProfileSettings(state);
|
||||
@@ -312,22 +353,28 @@ describe('OmniCard AI 名片主个人中心与消息通知配置 (useProfile.uts
|
||||
mockStorage[PROFILE_ACCOUNT_STORAGE_KEY] as string
|
||||
) as UserProfileAccount;
|
||||
expect(parsed.name).toBe('Elena Rostova');
|
||||
expect(parsed.company).toBe('Global Trade Co.');
|
||||
expect(parsed.company).toBe('Northwind Ltd');
|
||||
});
|
||||
|
||||
it('4.2 防御保护:空值或非法输入不覆盖已有有效信息', () => {
|
||||
const { loadProfileSettings, updateAccount } = loadUseProfile();
|
||||
const state = loadProfileSettings();
|
||||
const originalName = state.account.name;
|
||||
updateAccount(state, {
|
||||
name: 'Elena',
|
||||
company: 'Northwind Ltd',
|
||||
department: 'Sales',
|
||||
});
|
||||
|
||||
updateAccount(state, {
|
||||
name: ' ',
|
||||
company: '',
|
||||
department: '',
|
||||
});
|
||||
|
||||
// 空白字符串不应覆盖已有名称与企业
|
||||
expect(state.account.name).toBe(originalName);
|
||||
expect(state.account.company).toBeTruthy();
|
||||
expect(state.account.name).toBe('Elena');
|
||||
expect(state.account.company).toBe('Northwind Ltd');
|
||||
expect(state.account.department).toBe('Sales');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -352,6 +399,133 @@ describe('OmniCard AI 名片主个人中心与消息通知配置 (useProfile.uts
|
||||
expect(resolveProfileText('upgradeQuota')).toBeTruthy();
|
||||
expect(resolveProfileText('confirmLogoutTitle')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('5.3 displayOrgField:缺失或空串走 i18n 空态,有值原样返回', () => {
|
||||
const { displayOrgField, resolveProfileText } = loadUseProfile();
|
||||
const emptyText = resolveProfileText('empty');
|
||||
expect(emptyText).toBeTruthy();
|
||||
expect(displayOrgField('')).toBe(emptyText);
|
||||
expect(displayOrgField(' ')).toBe(emptyText);
|
||||
expect(displayOrgField(null)).toBe(emptyText);
|
||||
expect(displayOrgField(undefined)).toBe(emptyText);
|
||||
expect(displayOrgField('Acme Corp')).toBe('Acme Corp');
|
||||
});
|
||||
});
|
||||
|
||||
describe('6. R39 公司/部门仅来自接口 (loadOwnerProfileAccount)', () => {
|
||||
it('6.1 成功时写入接口 company / department,缺字段为空串', async () => {
|
||||
const { createProfileState, loadOwnerProfileAccount } = loadUseProfile();
|
||||
const state = createProfileState();
|
||||
state.account.company = 'stale-company';
|
||||
state.account.department = 'stale-dept';
|
||||
|
||||
const fetchOwnerCardPage = jest.fn(
|
||||
async (): Promise<OwnerPageData<CardProfileFixture>> => ({
|
||||
list: [
|
||||
{
|
||||
id: 8,
|
||||
name: 'Elena',
|
||||
company: 'Acme Corp',
|
||||
},
|
||||
],
|
||||
pagination: { page: 1, size: 1, total: 1 },
|
||||
})
|
||||
);
|
||||
|
||||
const ok = await loadOwnerProfileAccount(state, { fetchOwnerCardPage });
|
||||
expect(ok).toBe(true);
|
||||
expect(fetchOwnerCardPage).toHaveBeenCalledTimes(1);
|
||||
expect(state.account.company).toBe('Acme Corp');
|
||||
expect(state.account.department).toBe('');
|
||||
});
|
||||
|
||||
it('6.1b 接口同时返回 company 与 department 时原样写入', async () => {
|
||||
const { createProfileState, loadOwnerProfileAccount } = loadUseProfile();
|
||||
const state = createProfileState();
|
||||
|
||||
await loadOwnerProfileAccount(state, {
|
||||
fetchOwnerCardPage: async () => ({
|
||||
list: [
|
||||
{
|
||||
id: 3,
|
||||
name: 'Elena',
|
||||
company: 'Acme Corp',
|
||||
department: 'APAC Sales',
|
||||
},
|
||||
],
|
||||
pagination: { page: 1, size: 1, total: 1 },
|
||||
}),
|
||||
});
|
||||
|
||||
expect(state.account.company).toBe('Acme Corp');
|
||||
expect(state.account.department).toBe('APAC Sales');
|
||||
});
|
||||
|
||||
it('6.2 接口返回空串时保持空串,不回填示例组织', async () => {
|
||||
const { createProfileState, loadOwnerProfileAccount, displayOrgField, resolveProfileText } =
|
||||
loadUseProfile();
|
||||
const state = createProfileState();
|
||||
state.account.company = 'stale';
|
||||
state.account.department = 'stale';
|
||||
|
||||
await loadOwnerProfileAccount(state, {
|
||||
fetchOwnerCardPage: async () => ({
|
||||
list: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Elena',
|
||||
company: '',
|
||||
department: ' ',
|
||||
},
|
||||
],
|
||||
pagination: { page: 1, size: 1, total: 1 },
|
||||
}),
|
||||
});
|
||||
|
||||
expect(state.account.company).toBe('');
|
||||
expect(state.account.department).toBe('');
|
||||
expect(displayOrgField(state.account.company)).toBe(resolveProfileText('empty'));
|
||||
expect(displayOrgField(state.account.department)).toBe(resolveProfileText('empty'));
|
||||
expect(resolveProfileText('empty')).toBe('暂无数据');
|
||||
});
|
||||
|
||||
it('6.3 接口失败时清空公司与部门,不保留上次或示例值', async () => {
|
||||
const { createProfileState, loadOwnerProfileAccount, clearOrgFields } = loadUseProfile();
|
||||
const state = createProfileState();
|
||||
state.account.company = 'stale-company';
|
||||
state.account.department = 'stale-dept';
|
||||
|
||||
const ok = await loadOwnerProfileAccount(state, {
|
||||
fetchOwnerCardPage: async () => {
|
||||
throw new Error('network down');
|
||||
},
|
||||
});
|
||||
|
||||
expect(ok).toBe(false);
|
||||
expect(state.account.company).toBe('');
|
||||
expect(state.account.department).toBe('');
|
||||
clearOrgFields(state);
|
||||
expect(state.account.company).toBe('');
|
||||
expect(state.account.department).toBe('');
|
||||
});
|
||||
|
||||
it('6.4 列表为空时同样清空公司与部门', async () => {
|
||||
const { createProfileState, loadOwnerProfileAccount } = loadUseProfile();
|
||||
const state = createProfileState();
|
||||
state.account.company = 'stale-company';
|
||||
state.account.department = 'stale-dept';
|
||||
|
||||
const ok = await loadOwnerProfileAccount(state, {
|
||||
fetchOwnerCardPage: async () => ({
|
||||
list: [],
|
||||
pagination: { page: 1, size: 1, total: 0 },
|
||||
}),
|
||||
});
|
||||
|
||||
expect(ok).toBe(true);
|
||||
expect(state.account.company).toBe('');
|
||||
expect(state.account.department).toBe('');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -379,13 +553,15 @@ describe('OmniCard AI 名片主个人中心视图契约 (index.uvue & pages.json
|
||||
expect(combined.includes('toggleRadarPush')).toBe(true);
|
||||
expect(combined.includes('toggleLeadNotice')).toBe(true);
|
||||
expect(combined.includes('setPreferredLocale')).toBe(true);
|
||||
expect(combined.includes('loadOwnerProfileAccount')).toBe(true);
|
||||
expect(combined.includes('displayOrgField')).toBe(true);
|
||||
|
||||
// 瑞士国际主义风格 Token 引用
|
||||
expect(pageSource.includes('#0B5CFF')).toBe(true); // primary
|
||||
expect(pageSource.includes('#F7F8FA')).toBe(true); // surface
|
||||
// OmniCard 设计 Token
|
||||
expect(pageSource.includes('#0088FF')).toBe(true); // primary
|
||||
expect(pageSource.includes('#F5F8FC')).toBe(true); // bg
|
||||
expect(pageSource.includes('#101828')).toBe(true); // text
|
||||
expect(pageSource.includes('#667085')).toBe(true); // text-2
|
||||
expect(pageSource.includes('#E3E7ED')).toBe(true); // border
|
||||
expect(pageSource.includes('#64748B')).toBe(true); // text-2
|
||||
expect(pageSource.includes('#EBF1F7')).toBe(true); // border
|
||||
|
||||
// Switch 触控区 >= 44x44 规范验证 (min-height >= 44px 或 height >= 44px)
|
||||
expect(
|
||||
@@ -397,7 +573,7 @@ describe('OmniCard AI 名片主个人中心视图契约 (index.uvue & pages.json
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('零 emoji、无 any,无硬编码中文主文案,符合瑞士国际主义约束', () => {
|
||||
it('零 emoji、无 any,公司/部门无写死示例组织', () => {
|
||||
const pageSource = fs.readFileSync(PROFILE_PAGE, 'utf8');
|
||||
const logicSource = fs.readFileSync(PROFILE_UTS, 'utf8');
|
||||
const testSource = fs.readFileSync(__filename, 'utf8');
|
||||
@@ -410,8 +586,17 @@ describe('OmniCard AI 名片主个人中心视图契约 (index.uvue & pages.json
|
||||
expect(pageSource.includes(': any') || pageSource.includes(' as any')).toBe(false);
|
||||
expect(logicSource.includes(': any') || logicSource.includes(' as any')).toBe(false);
|
||||
|
||||
// 模板中主文案走词典或 resolve 函数,无硬编码中文汉字
|
||||
expect(/[\u4e00-\u9fff]/.test(template)).toBe(false);
|
||||
// 公司/部门展示走 displayOrgField,禁止写死示例组织
|
||||
expect(template.includes('displayOrgField')).toBe(true);
|
||||
expect(template.includes('state.account.company }}')).toBe(false);
|
||||
expect(template.includes('state.account.department }}')).toBe(false);
|
||||
expect(SAMPLE_ORG_RE.test(pageSource)).toBe(false);
|
||||
expect(SAMPLE_ORG_RE.test(logicSource)).toBe(false);
|
||||
expect(logicSource.includes("company: 'Nexus")).toBe(false);
|
||||
expect(logicSource.includes('company: "Nexus')).toBe(false);
|
||||
expect(logicSource.includes('Overseas Business')).toBe(false);
|
||||
expect(logicSource.includes("resolveProfileText('empty')")).toBe(true);
|
||||
expect(logicSource.includes("getOmniText(locale, 'common.empty')")).toBe(true);
|
||||
});
|
||||
|
||||
it('mpuniapp/pages.json 中已成功注册 pages/owner/profile/index', () => {
|
||||
|
||||
在新工单中引用
屏蔽一个用户