Skip to content

Commit bde72da

Browse files
committed
fix: update test assertions and mock implementation for translation tests
1 parent 91cb11b commit bde72da

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/lib/services/__tests__/ftb-quest-logic.e2e.test.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,25 @@ describe('FTB Quest Translation Logic E2E', () => {
6868

6969
// Mock translation service to return predictable translations
7070
jest.spyOn(translationService, 'translateChunk').mockImplementation(
71-
async (chunk: Record<string, string>, targetLanguage: string) => {
71+
async (chunk: any, targetLanguage: string) => {
7272
const translations: Record<string, string> = {
7373
'Welcome to the Modpack': 'モッドパックへようこそ',
7474
'Complete your first quest to get started.': '最初のクエストを完了して始めましょう。',
7575
'Mining Adventure': '採掘アドベンチャー',
7676
'Collect 64 stone blocks': '64個の石ブロックを集めよう'
7777
};
7878

79-
// If chunk is a string (JSON), parse it
79+
// Handle SNBT content (raw string)
80+
if (typeof chunk === 'string' && chunk.includes('title:')) {
81+
// For SNBT, return the translated string
82+
let translated = chunk;
83+
for (const [en, ja] of Object.entries(translations)) {
84+
translated = translated.replace(en, ja);
85+
}
86+
return translated;
87+
}
88+
89+
// Handle JSON content
8090
const content = typeof chunk === 'string' ? JSON.parse(chunk) : chunk;
8191
const result: Record<string, string> = {};
8292

@@ -186,8 +196,8 @@ describe('FTB Quest Translation Logic E2E', () => {
186196
expect(outputPath).toBe('/test/modpack/kubejs/assets/kubejs/lang/');
187197

188198
// Verify translated content structure
189-
expect(content).toHaveProperty('ftbquests.quest.starter.title', 'モッドパックへようこそ');
190-
expect(content).toHaveProperty('ftbquests.quest.starter.description', '最初のクエストを完了して始めましょう。');
199+
expect(content['ftbquests.quest.starter.title']).toBe('モッドパックへようこそ');
200+
expect(content['ftbquests.quest.starter.description']).toBe('最初のクエストを完了して始めましょう。');
191201

192202
// Mock file write
193203
await invoke('write_text_file', {
@@ -356,13 +366,12 @@ describe('FTB Quest Translation Logic E2E', () => {
356366
getOutputPath: () => '/test/modpack/config/ftbquests/quests/chapters/starter.snbt',
357367
getResultContent: (job) => {
358368
// For SNBT files, return the translated SNBT content as a string
359-
let result = job.chunks[0]?.content || '';
360-
if (job.chunks[0]?.translatedContent) {
361-
// Translate the content
362-
result = result.replace('Welcome to the Modpack', 'モッドパックへようこそ');
363-
result = result.replace('Complete your first quest to get started.', '最初のクエストを完了して始めましょう。');
369+
const translatedContent = job.chunks[0]?.translatedContent;
370+
if (translatedContent) {
371+
return translatedContent;
364372
}
365-
return result;
373+
// Fallback to original content
374+
return job.chunks[0]?.content || '';
366375
},
367376
writeOutput: async (job, outputPath, content) => {
368377
// Verify in-place translation (same file path)

0 commit comments

Comments
 (0)