feat: prepare Zhinian desktop client for pilot release
This commit is contained in:
93
tests/unit/yinian-skills-store.test.ts
Normal file
93
tests/unit/yinian-skills-store.test.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { useYinianSkillsStore } from '@/stores/yinian-skills';
|
||||
|
||||
describe('useYinianSkillsStore', () => {
|
||||
beforeEach(() => {
|
||||
useYinianSkillsStore.setState({
|
||||
localSkills: [],
|
||||
lastSync: null,
|
||||
loading: false,
|
||||
error: null,
|
||||
});
|
||||
vi.mocked(window.yinian.skills.listLocal).mockReset();
|
||||
vi.mocked(window.yinian.skills.sync).mockReset();
|
||||
vi.mocked(window.yinian.skills.getRegistry).mockReset();
|
||||
});
|
||||
|
||||
it('loads local skills through preload API', async () => {
|
||||
vi.mocked(window.yinian.skills.listLocal).mockResolvedValueOnce([
|
||||
{
|
||||
skillId: 'daily-report',
|
||||
name: '日报生成助手',
|
||||
version: '0.1.0',
|
||||
enabled: true,
|
||||
installedAt: 1,
|
||||
lastSyncedAt: 2,
|
||||
status: 'installed',
|
||||
source: 'mock',
|
||||
},
|
||||
]);
|
||||
|
||||
await useYinianSkillsStore.getState().listLocal();
|
||||
|
||||
expect(useYinianSkillsStore.getState().localSkills).toHaveLength(1);
|
||||
expect(useYinianSkillsStore.getState().localSkills[0].skillId).toBe('daily-report');
|
||||
});
|
||||
|
||||
it('syncs skills and stores last sync result', async () => {
|
||||
vi.mocked(window.yinian.skills.sync).mockResolvedValueOnce({
|
||||
hotelId: 'workspace_hangzhou_ops',
|
||||
syncedAt: 10,
|
||||
skills: [
|
||||
{
|
||||
skillId: 'data-check',
|
||||
name: '数据检查助手',
|
||||
version: '1.0.0',
|
||||
enabled: true,
|
||||
installedAt: 1,
|
||||
lastSyncedAt: 10,
|
||||
status: 'installed',
|
||||
source: 'mock',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await useYinianSkillsStore.getState().sync();
|
||||
|
||||
expect(useYinianSkillsStore.getState().lastSync?.hotelId).toBe('workspace_hangzhou_ops');
|
||||
expect(useYinianSkillsStore.getState().localSkills[0].skillId).toBe('data-check');
|
||||
});
|
||||
|
||||
it('loads a specific workspace registry', async () => {
|
||||
vi.mocked(window.yinian.skills.getRegistry).mockResolvedValueOnce({
|
||||
hotelId: 'workspace_shanghai_growth',
|
||||
updatedAt: 20,
|
||||
skills: [
|
||||
{
|
||||
skillId: 'customer-reply-helper',
|
||||
name: '客户回复助手',
|
||||
version: '0.1.0',
|
||||
enabled: true,
|
||||
installedAt: 1,
|
||||
lastSyncedAt: 20,
|
||||
status: 'installed',
|
||||
source: 'mock',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const registry = await useYinianSkillsStore.getState().getRegistry('workspace_shanghai_growth');
|
||||
|
||||
expect(registry && 'hotelId' in registry ? registry.hotelId : undefined).toBe('workspace_shanghai_growth');
|
||||
expect(useYinianSkillsStore.getState().localSkills[0].skillId).toBe('customer-reply-helper');
|
||||
});
|
||||
|
||||
it('records an error when registry loading fails', async () => {
|
||||
vi.mocked(window.yinian.skills.getRegistry).mockRejectedValueOnce(new Error('registry unavailable'));
|
||||
|
||||
const registry = await useYinianSkillsStore.getState().getRegistry('workspace_hangzhou_ops');
|
||||
|
||||
expect(registry).toBeUndefined();
|
||||
expect(useYinianSkillsStore.getState().error).toBe('registry unavailable');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user