|
| 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 | +}); |
0 commit comments