feat: update desktop workflows and app center
This commit is contained in:
60
tests/unit/yinian-local-prefs.test.ts
Normal file
60
tests/unit/yinian-local-prefs.test.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
const fetchAppLocalPreferencesMock = vi.fn();
|
||||
const updateAppLocalPreferencesMock = vi.fn();
|
||||
|
||||
vi.mock('@/lib/app-local-preferences', () => ({
|
||||
fetchAppLocalPreferences: (...args: unknown[]) => fetchAppLocalPreferencesMock(...args),
|
||||
updateAppLocalPreferences: (...args: unknown[]) => updateAppLocalPreferencesMock(...args),
|
||||
}));
|
||||
|
||||
describe('YINIAN local preferences app-level sync', () => {
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
vi.clearAllMocks();
|
||||
window.localStorage.clear();
|
||||
});
|
||||
|
||||
it('hydrates account remarks from app-level local preferences', async () => {
|
||||
fetchAppLocalPreferencesMock.mockResolvedValue({
|
||||
desktopUserName: '徐明',
|
||||
workspaceDisplayName: '智念科技',
|
||||
channelAccountRemarks: {
|
||||
'wechat:20732884aa30-im-bot': '徐明微信',
|
||||
'feishu:default': '徐明飞书',
|
||||
},
|
||||
});
|
||||
|
||||
const {
|
||||
getEffectiveChannelAccountName,
|
||||
getEffectiveUserName,
|
||||
getEffectiveWorkspaceName,
|
||||
syncYinianLocalPrefsWithAppLocalPreferences,
|
||||
} = await import('@/lib/yinian-local-prefs');
|
||||
|
||||
await syncYinianLocalPrefsWithAppLocalPreferences();
|
||||
|
||||
expect(getEffectiveUserName('王管理员')).toBe('徐明');
|
||||
expect(getEffectiveWorkspaceName('默认组织')).toBe('智念科技');
|
||||
expect(getEffectiveChannelAccountName('wechat', '20732884aa30-im-bot', '原微信')).toBe('徐明微信');
|
||||
expect(getEffectiveChannelAccountName('feishu', 'default', '原飞书')).toBe('徐明飞书');
|
||||
});
|
||||
|
||||
it('pushes existing origin-local account remarks into app-level preferences', async () => {
|
||||
fetchAppLocalPreferencesMock.mockResolvedValue({});
|
||||
|
||||
const {
|
||||
setChannelAccountRemark,
|
||||
syncYinianLocalPrefsWithAppLocalPreferences,
|
||||
} = await import('@/lib/yinian-local-prefs');
|
||||
|
||||
setChannelAccountRemark('wechat', '20732884aa30-im-bot', '徐明微信');
|
||||
await syncYinianLocalPrefsWithAppLocalPreferences();
|
||||
|
||||
expect(updateAppLocalPreferencesMock).toHaveBeenCalledWith({
|
||||
channelAccountRemarks: expect.objectContaining({
|
||||
'wechat:20732884aa30-im-bot': '徐明微信',
|
||||
}),
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user