feat: update desktop workflows and app center
This commit is contained in:
63
tests/unit/quick-tasks-store.test.ts
Normal file
63
tests/unit/quick-tasks-store.test.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
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('quick tasks store app-local preference sync', () => {
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
vi.clearAllMocks();
|
||||
window.localStorage.clear();
|
||||
});
|
||||
|
||||
it('hydrates quick capabilities from app-level local preferences', async () => {
|
||||
fetchAppLocalPreferencesMock.mockResolvedValue({
|
||||
quickTasks: [{
|
||||
id: 'quick-docx',
|
||||
name: '写word文章',
|
||||
description: '帮你写一个word文件',
|
||||
skills: [{ id: 'docx', name: 'docx' }],
|
||||
enabled: true,
|
||||
showInComposer: true,
|
||||
updatedAt: 1,
|
||||
}],
|
||||
});
|
||||
|
||||
const { useQuickTasksStore, syncQuickTasksWithAppLocalPreferences } = await import('@/stores/quick-tasks');
|
||||
useQuickTasksStore.setState({ tasks: [] });
|
||||
|
||||
await syncQuickTasksWithAppLocalPreferences();
|
||||
|
||||
expect(useQuickTasksStore.getState().tasks).toMatchObject([
|
||||
{ id: 'quick-docx', name: '写word文章', skills: [{ id: 'docx', name: 'docx' }] },
|
||||
]);
|
||||
});
|
||||
|
||||
it('pushes existing origin-local quick capabilities into app-level preferences', async () => {
|
||||
fetchAppLocalPreferencesMock.mockResolvedValue({});
|
||||
|
||||
const { useQuickTasksStore, syncQuickTasksWithAppLocalPreferences } = await import('@/stores/quick-tasks');
|
||||
useQuickTasksStore.setState({
|
||||
tasks: [{
|
||||
id: 'quick-design',
|
||||
name: '做网页',
|
||||
description: '用网页的方式帮你做介绍',
|
||||
skills: [{ id: 'ui-ux-pro-max', name: 'ui-ux-pro-max' }],
|
||||
enabled: true,
|
||||
showInComposer: true,
|
||||
updatedAt: 2,
|
||||
}],
|
||||
});
|
||||
|
||||
await syncQuickTasksWithAppLocalPreferences();
|
||||
|
||||
expect(updateAppLocalPreferencesMock).toHaveBeenCalledWith({
|
||||
quickTasks: [expect.objectContaining({ id: 'quick-design', name: '做网页' })],
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user