Skip to content

Commit 27c2597

Browse files
committed
fix(i18n): apply i18n to name field validation error message
Name field error message was always shown in English regardless of language setting - Changed to use i18n translation key instead of hardcoded Zod schema message - Added E2E tests for i18n consistency validation
1 parent 3b790ed commit 27c2597

4 files changed

Lines changed: 104 additions & 1 deletion

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { expect, test } from "@playwright/test";
2+
3+
test.describe("Test 3: Form Validation i18n Consistency", () => {
4+
test.beforeEach(async ({ page }) => {
5+
await page.goto("/");
6+
});
7+
8+
test("should show English validation error when language is English (default)", async ({
9+
page,
10+
}) => {
11+
// Given: Language is English (default)
12+
await expect(page.getByRole("button", { name: "Add new command" })).toBeVisible();
13+
14+
// When: Open add command dialog and click save without filling fields
15+
await page.getByRole("button", { name: "Add new command" }).click();
16+
17+
const dialog = page.getByRole("dialog");
18+
await expect(dialog).toBeVisible();
19+
20+
await page.getByRole("button", { name: "Save" }).click();
21+
22+
// Then: English validation errors should be displayed
23+
await expect(page.getByRole("alert").filter({ hasText: "Command name is required" })).toBeVisible();
24+
await expect(page.getByRole("alert").filter({ hasText: "Command is required" })).toBeVisible();
25+
26+
// Dialog should remain open
27+
await expect(dialog).toBeVisible();
28+
});
29+
30+
test("should show Korean validation error when language is Korean", async ({
31+
page,
32+
}) => {
33+
// Given: Switch language to Korean
34+
await page.getByRole("button", { name: "Change language" }).click();
35+
await page.getByText("한국어").click();
36+
37+
// Wait for language switch - check visible text content
38+
await expect(page.getByText("추가").first()).toBeVisible();
39+
40+
// When: Open add command dialog and click save without filling fields
41+
await page.getByRole("button", { name: "Add new command" }).click();
42+
43+
const dialog = page.getByRole("dialog");
44+
await expect(dialog).toBeVisible();
45+
46+
await dialog.getByRole("button", { name: /|Save/ }).click();
47+
48+
// Then: Korean validation errors should be displayed
49+
await expect(page.getByRole("alert").filter({ hasText: "명령 이름을 입력해주세요" })).toBeVisible();
50+
await expect(page.getByRole("alert").filter({ hasText: "명령어를 입력해주세요" })).toBeVisible();
51+
52+
// Dialog should remain open
53+
await expect(dialog).toBeVisible();
54+
});
55+
56+
test("should show English group validation error when language is English", async ({
57+
page,
58+
}) => {
59+
// Given: English language (default)
60+
await page.getByRole("button", { name: "Add new command" }).click();
61+
62+
// Fill name and switch to group mode
63+
await page.getByRole("textbox", { name: "Command Name" }).fill("Test Group");
64+
await page.getByRole("radio", { name: "Group Commands" }).click();
65+
66+
// When: Try to save empty group
67+
const dialog = page.getByRole("dialog");
68+
await dialog.getByRole("button", { name: "Save" }).click();
69+
70+
// Then: English group validation error should be displayed
71+
await expect(page.getByText("Group must have at least one command")).toBeVisible();
72+
await expect(dialog).toBeVisible();
73+
});
74+
75+
test("should show Korean group validation error when language is Korean", async ({
76+
page,
77+
}) => {
78+
// Given: Switch to Korean
79+
await page.getByRole("button", { name: "Change language" }).click();
80+
await page.getByText("한국어").click();
81+
await expect(page.getByText("추가").first()).toBeVisible();
82+
83+
// Open dialog and switch to group mode
84+
await page.getByRole("button", { name: "Add new command" }).click();
85+
86+
const dialog = page.getByRole("dialog");
87+
await dialog.locator("#displayText").fill("테스트 그룹");
88+
await dialog.getByRole("radio", { name: /|Group/ }).click();
89+
90+
// When: Try to save empty group
91+
await dialog.getByRole("button", { name: /|Save/ }).click();
92+
93+
// Then: Korean group validation error should be displayed
94+
await expect(page.getByText("그룹에 최소 하나의 커맨드가 필요합니다")).toBeVisible();
95+
await expect(dialog).toBeVisible();
96+
});
97+
});

src/view/src/components/command-form.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ export const CommandForm = ({
199199
return (
200200
<form className="space-y-6" id={formId} onSubmit={onSubmit}>
201201
<div className="space-y-6">
202-
<FormField error={!!errors.name} errorMessage={errors.name?.message} id="displayText">
202+
<FormField
203+
error={!!errors.name}
204+
errorMessage={errors.name ? t("commandForm.errors.nameRequired") : undefined}
205+
id="displayText"
206+
>
203207
<FormLabel htmlFor="displayText">{t("commandForm.commandName")}</FormLabel>
204208
<div
205209
aria-describedby={errors.name ? "displayText-error" : undefined}

src/view/src/i18n/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"shortcut": "Shortcut (optional)",
5353
"shortcutPlaceholder": "e.g., t",
5454
"errors": {
55+
"nameRequired": "Command name is required",
5556
"commandRequired": "Command is required",
5657
"groupEmpty": "Group must have at least one command",
5758
"groupCommandRequired": "All commands in group must have a command",

src/view/src/i18n/locales/ko.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"shortcut": "단축키 (optional)",
5353
"shortcutPlaceholder": "예: t",
5454
"errors": {
55+
"nameRequired": "명령 이름을 입력해주세요",
5556
"commandRequired": "명령어를 입력해주세요",
5657
"groupEmpty": "그룹에 최소 하나의 커맨드가 필요합니다",
5758
"groupCommandRequired": "그룹 내 모든 커맨드에 명령어를 입력해주세요",

0 commit comments

Comments
 (0)