Skip to content

Commit 47c3c8e

Browse files
committed
fix(i18n): fix interpolation mock, use extensionState mock, strengthen regression tests
1 parent 7363ef7 commit 47c3c8e

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

‎webview-ui/src/i18n/__tests__/TranslationContext.spec.tsx‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import TranslationProvider, { useAppTranslation } from "../TranslationContext"
88
const mockTranslations = vi.hoisted((): Record<string, Record<string, string>> => ({
99
en: {
1010
"settings.autoApprove.title": "Auto-Approve",
11-
"notifications.error": "Operation failed",
11+
"notifications.error": "Operation failed: {{message}}",
1212
"common:confirmation.editMessage": "Edit Message",
1313
"common:confirmation.deleteMessage": "Delete Message",
1414
"common:confirmation.editWarning":
@@ -20,7 +20,7 @@ const mockTranslations = vi.hoisted((): Record<string, Record<string, string>> =
2020
},
2121
ru: {
2222
"settings.autoApprove.title": "Авто-Одобрение",
23-
"notifications.error": "Ошибка операции",
23+
"notifications.error": "Ошибка операции: {{message}}",
2424
"common:confirmation.editMessage": "Редактировать Сообщение",
2525
"common:confirmation.deleteMessage": "Удалить Сообщение",
2626
"common:confirmation.editWarning":
@@ -58,7 +58,7 @@ const mockI18n = vi.hoisted(() => ({
5858

5959
vi.mock("@/context/ExtensionStateContext", () => ({
6060
useExtensionState: () => ({
61-
language: mockI18n.language,
61+
language: mockLanguageState.current,
6262
}),
6363
}))
6464

@@ -105,10 +105,10 @@ describe("TranslationContext", () => {
105105
</TranslationProvider>,
106106
)
107107

108-
expect(getByTestId("translation-interpolation")).toHaveTextContent("Operation failed")
108+
expect(getByTestId("translation-interpolation")).toHaveTextContent("Operation failed: Test error")
109109
})
110110

111-
it("should re-render consumers when language changes (regression for memoized components)", () => {
111+
it("should re-render consumers when language changes via extensionState (regression for memoized components)", () => {
112112
const MemoizedConsumer = React.memo(() => {
113113
const { t } = useAppTranslation()
114114
return (
@@ -147,12 +147,12 @@ describe("TranslationContext", () => {
147147
expect(getByTestId("memo-proceed")).toHaveTextContent("Proceed")
148148
expect(getByTestId("normal-title")).toHaveTextContent("Edit Message")
149149

150-
// Change language to Russian
150+
// Simulate language change via extensionState (production path)
151+
// This triggers useEffect → i18n.changeLanguage() → i18n.language update → useCallback recreation
151152
act(() => {
152-
mockI18n.changeLanguage("ru")
153+
mockLanguageState.current = "ru"
153154
})
154155

155-
// Re-render to pick up context change
156156
rerender(
157157
<TranslationProvider>
158158
<MemoizedConsumer />
@@ -170,7 +170,7 @@ describe("TranslationContext", () => {
170170
expect(getByTestId("normal-title")).toHaveTextContent("Редактировать Сообщение")
171171
})
172172

173-
it("should re-render delete dialog with correct translations after language switch", () => {
173+
it("should re-render delete dialog with correct translations after language switch via extensionState", () => {
174174
const DeleteDialog = React.memo(() => {
175175
const { t } = useAppTranslation()
176176
return (
@@ -192,8 +192,9 @@ describe("TranslationContext", () => {
192192
"Deleting this message will delete all subsequent messages",
193193
)
194194

195+
// Simulate language change via extensionState (production path)
195196
act(() => {
196-
mockI18n.changeLanguage("ru")
197+
mockLanguageState.current = "ru"
197198
})
198199

199200
rerender(

0 commit comments

Comments
 (0)