* chore: updated todo with translation ideas * feat: first take at the implementation of translations * fix: small addition for the translation feature * feat: support language switching in the editor and preview * feat: better handling of long bodies by not running them through a json envelope * fix: unknown macros have better fallback * feat: api for python to get translations * fix: strip dumb prefix of content in translation * feat: extend meta diff for translations * feat: hook up translations to rebuild-from-disk * feat: generation of the website prefers project language, falling back to canonical language * fix: crashes during rendering * feat: translation validation report * fix: made the translation validation actually work * chore: reorganization of menu * fix: some topics cleanup * chore: updated doc * feat: translations for media * feat: more aligned in UI/UX * feat: edit translations possible * chore: added full multi-language todo * chore: updated todo for clarity * feat: implementation of full multi-linguality * fix: page creation creates pages * fix: flags on every page * fix: better prompt * feat: made MCP server aware of language content * feat: python tools for translations * fix: better fill-in-translations * fix: better prompt for translation. maybe. * fix: losing posts from search due to translation process * fix: translation validation handles in-db content and fill-in of missing translations fixed to flush * fix: faster scanning for infilling of missing translations * chore: updated agent instructions * feat: calendar and tag cloud respect current language now * fix: retries going up * fix: got metadata-diff and rebuild into sync * fix: extended meta-diff for timestamps * fix: made website validation look at translated content, too * fix: multi-lingual search * chore: refactor Editor.tsx into two separate editors * feat: do language detection when no explicit language given --------- Co-authored-by: hugo <hugoms@me.com>
101 lines
3.6 KiB
TypeScript
101 lines
3.6 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
import { invokePythonApiMethodV1 } from '../../../src/renderer/python/pythonApiInvokerV1';
|
|
|
|
describe('invokePythonApiMethodV1', () => {
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
it('invokes posts.get via electronAPI with validated args', async () => {
|
|
const getPost = vi.fn().mockResolvedValue({ id: 'p1', title: 'Post 1' });
|
|
|
|
vi.stubGlobal('window', {
|
|
electronAPI: {
|
|
posts: {
|
|
get: getPost,
|
|
},
|
|
},
|
|
});
|
|
|
|
await expect(invokePythonApiMethodV1('posts.get', { postId: 'p1' })).resolves.toEqual({
|
|
id: 'p1',
|
|
title: 'Post 1',
|
|
});
|
|
expect(getPost).toHaveBeenCalledWith('p1');
|
|
});
|
|
|
|
it('invokes methods from multiple namespaces via contract metadata', async () => {
|
|
const searchPosts = vi.fn().mockResolvedValue([{ id: 'p1', title: 'Hit' }]);
|
|
const getProjectMetadata = vi.fn().mockResolvedValue({ name: 'My Project' });
|
|
const getAllProjects = vi.fn().mockResolvedValue([{ id: 'prj-1', name: 'Main' }]);
|
|
const getAllPosts = vi.fn().mockResolvedValue({ items: [], hasMore: false, total: 0 });
|
|
|
|
vi.stubGlobal('window', {
|
|
electronAPI: {
|
|
projects: {
|
|
getAll: getAllProjects,
|
|
},
|
|
posts: {
|
|
search: searchPosts,
|
|
getAll: getAllPosts,
|
|
},
|
|
meta: {
|
|
getProjectMetadata,
|
|
},
|
|
},
|
|
});
|
|
|
|
await expect(invokePythonApiMethodV1('projects.getAll', {})).resolves.toEqual([{ id: 'prj-1', name: 'Main' }]);
|
|
await expect(invokePythonApiMethodV1('posts.getAll', { options: { limit: 10, offset: 5 } })).resolves.toEqual({ items: [], hasMore: false, total: 0 });
|
|
await expect(invokePythonApiMethodV1('posts.search', { query: 'hit' })).resolves.toEqual([{ id: 'p1', title: 'Hit' }]);
|
|
await expect(invokePythonApiMethodV1('meta.getProjectMetadata', {})).resolves.toEqual({ name: 'My Project' });
|
|
expect(getAllProjects).toHaveBeenCalledWith();
|
|
expect(getAllPosts).toHaveBeenCalledWith({ limit: 10, offset: 5 });
|
|
expect(searchPosts).toHaveBeenCalledWith('hit');
|
|
expect(getProjectMetadata).toHaveBeenCalledWith();
|
|
});
|
|
|
|
it('invokes chat.translatePost via electronAPI with validated args', async () => {
|
|
const translatePost = vi.fn().mockResolvedValue({
|
|
success: true,
|
|
translation: { id: 'tr-1', language: 'de' },
|
|
});
|
|
|
|
vi.stubGlobal('window', {
|
|
electronAPI: {
|
|
chat: {
|
|
translatePost,
|
|
},
|
|
},
|
|
});
|
|
|
|
await expect(invokePythonApiMethodV1('chat.translatePost', { postId: 'p1', targetLanguage: 'de' })).resolves.toEqual({
|
|
success: true,
|
|
translation: { id: 'tr-1', language: 'de' },
|
|
});
|
|
expect(translatePost).toHaveBeenCalledWith('p1', 'de');
|
|
});
|
|
|
|
it('rejects unknown methods and malformed args', async () => {
|
|
vi.stubGlobal('window', {
|
|
electronAPI: {
|
|
posts: {
|
|
get: vi.fn(),
|
|
search: vi.fn(),
|
|
getAll: vi.fn(),
|
|
},
|
|
projects: {
|
|
getAll: vi.fn(),
|
|
},
|
|
meta: {
|
|
getProjectMetadata: vi.fn(),
|
|
},
|
|
},
|
|
});
|
|
|
|
await expect(invokePythonApiMethodV1('posts.unknown', {})).rejects.toThrow('Unsupported Python API method');
|
|
await expect(invokePythonApiMethodV1('posts.get', {})).rejects.toThrow('posts.get requires string arg postId');
|
|
await expect(invokePythonApiMethodV1('posts.search', { query: 1 })).rejects.toThrow('posts.search requires string arg query');
|
|
await expect(invokePythonApiMethodV1('posts.getAll', { options: 1 })).rejects.toThrow('posts.getAll requires object arg options');
|
|
});
|
|
}); |