|
3 | 3 | * |
4 | 4 | * Tests boundary conditions, unicode edge cases, performance, |
5 | 5 | * and error recovery that the happy-path tests don't cover. |
| 6 | + * |
| 7 | + * The default demo mode calls api.interscript.org, so output |
| 8 | + * assertions must poll (debounce + network round-trip) rather than |
| 9 | + * sleep for a fixed interval. |
6 | 10 | */ |
7 | | -import { test, expect } from "@playwright/test" |
| 11 | +import { test, expect, type Page } from "@playwright/test" |
| 12 | + |
| 13 | +async function ready(page: Page) { |
| 14 | + await expect(page.locator(".rail-status")).toContainText("ready", { timeout: 20000 }) |
| 15 | +} |
8 | 16 |
|
9 | 17 | test.describe("demo edge cases", () => { |
10 | 18 | test("handles empty input", async ({ page }) => { |
11 | 19 | await page.goto("/demo") |
12 | | - await expect(page.locator(".rail-status")).toContainText("ready", { timeout: 20000 }) |
| 20 | + await ready(page) |
13 | 21 |
|
14 | 22 | const textarea = page.locator("textarea.pane-body") |
15 | 23 | await textarea.fill("") |
16 | | - await page.waitForTimeout(300) |
17 | 24 |
|
18 | 25 | const output = page.locator(".pane-result") |
19 | 26 | const text = await output.textContent() |
20 | 27 | expect(text).toBeTruthy() |
| 28 | + await expect(page.locator(".error-banner")).not.toBeVisible() |
21 | 29 | }) |
22 | 30 |
|
23 | 31 | test("handles single character", async ({ page }) => { |
24 | 32 | await page.goto("/demo") |
25 | | - await expect(page.locator(".rail-status")).toContainText("ready", { timeout: 20000 }) |
| 33 | + await ready(page) |
26 | 34 |
|
27 | 35 | const textarea = page.locator("textarea.pane-body") |
28 | 36 | await textarea.fill("А") |
29 | | - await page.waitForTimeout(300) |
30 | 37 |
|
31 | | - const output = page.locator(".pane-result") |
32 | | - const text = (await output.textContent())?.trim() |
33 | | - expect(text?.length).toBeGreaterThan(0) |
| 38 | + await expect(page.locator(".pane-result")).toContainText("A", { timeout: 8000 }) |
34 | 39 | }) |
35 | 40 |
|
36 | 41 | test("handles very long input (1000+ chars)", async ({ page }) => { |
37 | 42 | await page.goto("/demo") |
38 | | - await expect(page.locator(".rail-status")).toContainText("ready", { timeout: 20000 }) |
| 43 | + await ready(page) |
39 | 44 |
|
40 | 45 | const longText = "Антон ".repeat(200) // ~1200 chars |
41 | 46 | const textarea = page.locator("textarea.pane-body") |
42 | 47 | await textarea.fill(longText) |
43 | | - await page.waitForTimeout(500) |
44 | 48 |
|
45 | 49 | const output = page.locator(".pane-result") |
| 50 | + // "Anton Anton" can only come from the repeated long input, not the |
| 51 | + // page's default single-word sample. |
| 52 | + await expect(output).toContainText("Anton Anton", { timeout: 15000 }) |
46 | 53 | const text = (await output.textContent())?.trim() |
47 | 54 | expect(text?.length).toBeGreaterThan(100) |
48 | | - expect(text).toContain("Anton") |
49 | 55 | }) |
50 | 56 |
|
51 | 57 | test("handles rapid typing without errors", async ({ page }) => { |
52 | 58 | await page.goto("/demo") |
53 | | - await expect(page.locator(".rail-status")).toContainText("ready", { timeout: 20000 }) |
| 59 | + await ready(page) |
54 | 60 |
|
55 | 61 | const textarea = page.locator("textarea.pane-body") |
56 | 62 | // Type rapidly character by character |
57 | 63 | for (const char of "АнтонМир") { |
58 | 64 | await textarea.type(char, { delay: 10 }) |
59 | 65 | } |
60 | | - await page.waitForTimeout(500) |
61 | 66 |
|
62 | | - const errorBanner = page.locator(".error-banner") |
63 | | - await expect(errorBanner).not.toBeVisible() |
| 67 | + await expect(page.locator(".pane-result")).toContainText("Anton", { timeout: 8000 }) |
| 68 | + await expect(page.locator(".error-banner")).not.toBeVisible() |
64 | 69 | }) |
65 | 70 |
|
66 | 71 | test("handles mixed scripts", async ({ page }) => { |
67 | 72 | await page.goto("/demo") |
68 | | - await expect(page.locator(".rail-status")).toContainText("ready", { timeout: 20000 }) |
| 73 | + await ready(page) |
69 | 74 |
|
70 | 75 | const textarea = page.locator("textarea.pane-body") |
71 | 76 | await textarea.fill("Hello Антон мир 123") |
72 | | - await page.waitForTimeout(300) |
73 | 77 |
|
74 | | - const output = page.locator(".pane-result") |
75 | | - const text = (await output.textContent())?.trim() |
76 | | - expect(text?.length).toBeGreaterThan(0) |
77 | 78 | // Latin chars should pass through |
78 | | - expect(text).toContain("Hello") |
| 79 | + await expect(page.locator(".pane-result")).toContainText("Hello", { timeout: 8000 }) |
79 | 80 | }) |
80 | 81 |
|
81 | 82 | test("handles special characters (newlines, tabs)", async ({ page }) => { |
82 | 83 | await page.goto("/demo") |
83 | | - await expect(page.locator(".rail-status")).toContainText("ready", { timeout: 20000 }) |
| 84 | + await ready(page) |
84 | 85 |
|
85 | 86 | const textarea = page.locator("textarea.pane-body") |
86 | 87 | await textarea.fill("Антон\nМир\tПривет") |
87 | | - await page.waitForTimeout(300) |
88 | 88 |
|
89 | | - const output = page.locator(".pane-result") |
90 | | - const text = (await output.textContent())?.trim() |
91 | | - expect(text?.length).toBeGreaterThan(0) |
| 89 | + await expect(page.locator(".pane-result")).toContainText("Anton", { timeout: 8000 }) |
92 | 90 | }) |
93 | 91 |
|
94 | 92 | test("handles numbers and punctuation", async ({ page }) => { |
95 | 93 | await page.goto("/demo") |
96 | | - await expect(page.locator(".rail-status")).toContainText("ready", { timeout: 20000 }) |
| 94 | + await ready(page) |
97 | 95 |
|
98 | 96 | const textarea = page.locator("textarea.pane-body") |
99 | 97 | await textarea.fill("Антон123!@#") |
100 | | - await page.waitForTimeout(300) |
101 | 98 |
|
102 | | - const output = page.locator(".pane-result") |
103 | | - const text = (await output.textContent())?.trim() |
104 | | - expect(text).toContain("123") |
| 99 | + await expect(page.locator(".pane-result")).toContainText("123", { timeout: 8000 }) |
105 | 100 | }) |
106 | 101 |
|
107 | 102 | test("handles unicode surrogate pairs (emoji)", async ({ page }) => { |
108 | 103 | await page.goto("/demo") |
109 | | - await expect(page.locator(".rail-status")).toContainText("ready", { timeout: 20000 }) |
| 104 | + await ready(page) |
110 | 105 |
|
111 | 106 | const textarea = page.locator("textarea.pane-body") |
112 | 107 | await textarea.fill("Антон 🎉 мир") |
113 | | - await page.waitForTimeout(300) |
114 | 108 |
|
115 | | - const output = page.locator(".pane-result") |
116 | | - const text = (await output.textContent())?.trim() |
117 | 109 | // Emoji should pass through (not crash) |
118 | | - expect(text).toBeTruthy() |
| 110 | + await expect(page.locator(".pane-result")).toContainText("Anton", { timeout: 8000 }) |
| 111 | + await expect(page.locator(".error-banner")).not.toBeVisible() |
119 | 112 | }) |
120 | 113 |
|
121 | 114 | test("system switching preserves input", async ({ page }) => { |
122 | 115 | await page.goto("/demo") |
123 | | - await expect(page.locator(".rail-status")).toContainText("ready", { timeout: 20000 }) |
| 116 | + await ready(page) |
124 | 117 |
|
125 | 118 | const textarea = page.locator("textarea.pane-body") |
126 | 119 | const select = page.locator("select.field-input") |
127 | 120 |
|
128 | 121 | // Type in Ukrainian |
129 | 122 | await textarea.fill("Антон") |
130 | | - await page.waitForTimeout(300) |
| 123 | + await expect(page.locator(".pane-result")).toContainText("Anton", { timeout: 8000 }) |
131 | 124 |
|
132 | 125 | // Switch to Russian |
133 | 126 | await select.selectOption("odni-rus-Cyrl-Latn-2015") |
134 | | - await page.waitForTimeout(300) |
135 | 127 |
|
136 | | - // Input should be preserved |
| 128 | + // Input should be preserved; output should change (different system) |
137 | 129 | const inputValue = await textarea.inputValue() |
138 | 130 | expect(inputValue).toBe("Антон") |
139 | | - |
140 | | - // Output should change (different system) |
141 | | - const output = page.locator(".pane-result") |
142 | | - const text = (await output.textContent())?.trim() |
143 | | - expect(text?.length).toBeGreaterThan(0) |
| 131 | + await expect(page.locator(".pane-result")).toContainText("Anton", { timeout: 8000 }) |
144 | 132 | }) |
145 | 133 |
|
146 | 134 | test("handles input that produces no transformation", async ({ page }) => { |
147 | 135 | await page.goto("/demo") |
148 | | - await expect(page.locator(".rail-status")).toContainText("ready", { timeout: 20000 }) |
| 136 | + await ready(page) |
149 | 137 |
|
150 | 138 | const textarea = page.locator("textarea.pane-body") |
151 | 139 | // Pure Latin text — should pass through unchanged for Cyrillic→Latin map |
152 | 140 | await textarea.fill("Hello World") |
153 | | - await page.waitForTimeout(300) |
154 | 141 |
|
155 | | - const output = page.locator(".pane-result") |
156 | | - const text = (await output.textContent())?.trim() |
157 | | - expect(text).toBe("Hello World") |
| 142 | + await expect(page.locator(".pane-result")).toHaveText("Hello World", { timeout: 8000 }) |
158 | 143 | }) |
159 | 144 |
|
160 | 145 | test("character counter updates correctly", async ({ page }) => { |
161 | 146 | await page.goto("/demo") |
162 | | - await expect(page.locator(".rail-status")).toContainText("ready", { timeout: 20000 }) |
| 147 | + await ready(page) |
163 | 148 |
|
164 | 149 | const textarea = page.locator("textarea.pane-body") |
165 | 150 | await textarea.fill("Hi") |
166 | | - await page.waitForTimeout(300) |
167 | 151 |
|
168 | 152 | // Look for character count indicator |
169 | 153 | const meta = page.locator(".pane-meta").first() |
|
0 commit comments