diff --git a/.peppa/memory.md b/.peppa/memory.md
index 2c1a447..8629881 100644
--- a/.peppa/memory.md
+++ b/.peppa/memory.md
@@ -24,6 +24,7 @@
- TR-21: между `` и `
"));
+ const section = afterForm.match(/]*>([\s\S]*?)<\/section>/)?.[1] ?? "";
+ return {
+ title: plainText(section.match(/]*>(.*?)<\/h2>/)?.[1] ?? ""),
+ lines: [...section.matchAll(/ (.*?)<\/li>/g)].map((match) => plainText(match[1] ?? "")),
+ };
+ };
+ const numbers = (lines: string[]) => lines.join(" ").match(/\d+/g) ?? [];
+ /** Страница без переключателя языков: в нём названия языков всегда написаны на них самих. */
+ const withoutSwitcher = (html: string) => html.replace(//, "");
+
+ const BLOCKS = {
+ kk: {
+ name: "Қазақша",
+ title: "Қателессеңіз не болады",
+ attempts: "Қатарынан 5 рет қате енгізсеңіз, кіру жабылады.",
+ minutes: "Тыйым 15 минуттан кейін өзі алынады, ештеңе істеудің қажеті жоқ.",
+ message:
+ "Тыйым салынған пайдаланушы мына хабарды көреді: «Әрекет тым көп, 15 минут күтіңіз. Оған дейін дұрыс құпиясөзбен де кіру жабық.»",
+ },
+ en: {
+ name: "English",
+ title: "What happens if you make mistakes",
+ attempts: "Sign-in is closed after 5 wrong attempts in a row.",
+ minutes: "The block lifts by itself in 15 minutes, you don't need to do anything.",
+ message:
+ "A blocked user sees this message: “Too many attempts, please wait 15 minutes. Until then sign-in is closed even with the right password.”",
+ },
+ };
+
+ it.each(Object.entries(BLOCKS))(
+ "Scenario Outline: Блок на выбранном языке — %s",
+ async (lang, expected) => {
+ app = await startApp();
+ const start = await (await app.get("/login", { "accept-language": "ru" })).text();
+ const russian = infoBlock(start);
+ expect(russian.title).toBe("Что будет при ошибках");
+
+ // Ссылка языка стоит в переключателе внизу страницы, под блоком.
+ const nav = start.slice(start.indexOf("${expected.name}`),
+ )?.[1];
+ expect(href).toBe(`/login?lang=${lang}`);
+
+ const html = await (await app.get(href ?? "")).text();
+ expect(html).toContain(``);
+ const block = infoBlock(html);
+ expect(block.title).toBe(expected.title);
+ expect(block.lines).toHaveLength(russian.lines.length);
+ expect(block.lines.slice(2, 5)).toEqual([
+ expected.attempts,
+ expected.minutes,
+ expected.message,
+ ]);
+ // Ни одна строка не осталась русской, подстановки заполнены.
+ for (const [index, line] of block.lines.entries()) {
+ expect(line).not.toBe(russian.lines[index]);
+ expect(line).not.toMatch(/[{}]/);
+ }
+ // Числа те же, что в русской версии: 5 попыток, 15 минут, 15 минут в сообщении.
+ expect(numbers(block.lines)).toEqual(["5", "15", "15"]);
+ expect(numbers(block.lines)).toEqual(numbers(russian.lines));
+ },
+ );
+
+ it.each(["kk", "en"])(
+ "Scenario Outline: Сообщение в блоке — то же, что видит заблокированный — %s",
+ async (lang) => {
+ app = await startApp();
+ for (let i = 0; i < 5; i++) {
+ await app.post(`/login?lang=${lang}`, { login: "anna", password: `bad-${i}` });
+ }
+ const locked = await app.post(`/login?lang=${lang}`, {
+ login: "anna",
+ password: "s3cret-pass",
+ });
+ const html = await locked.text();
+ const shown = plainText(html.match(/(.*?)<\/p>/)?.[1] ?? "");
+ expect(shown).toContain("15");
+ const quoted = infoBlock(html).lines[4] ?? "";
+ expect(quoted).toMatch(
+ new RegExp(`[«“]${shown.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}[»”]$`),
+ );
+ },
+ );
+
+ it("Scenario Outline: На странице нет остатков русского текста — en", async () => {
+ app = await startApp();
+ const html = await (await app.get("/login?lang=en")).text();
+ expect(withoutSwitcher(html)).not.toMatch(/[Ѐ-ӿ]/);
+ });
+
+ it("Scenario Outline: На странице нет остатков русского текста — kk", async () => {
+ app = await startApp();
+ const page = plainText(withoutSwitcher(await (await app.get("/login?lang=kk")).text()));
+ // «Логин» по-казахски пишется так же, как по-русски: это не остаток перевода.
+ const same = ["Логин"];
+ const leftovers: string[] = [];
+ for (const russian of Object.values(locales.ru)) {
+ for (const piece of russian.split(/\{[^}]+\}/)) {
+ const text = piece.trim();
+ if (text.length > 3 && !same.includes(text) && page.includes(text)) leftovers.push(text);
+ }
+ }
+ expect(leftovers).toEqual([]);
+ expect(page).toContain("Қателессеңіз не болады");
+ });
+
+ it("Scenario: Язык не из списка", async () => {
+ app = await startApp();
+ const html = await (await app.get("/login?lang=xx", { "accept-language": "ru" })).text();
+ const block = infoBlock(html);
+ expect(block.title).toBe("Что будет при ошибках");
+ expect(block.lines[2]).toBe("Вход закрывается после 5 неверных попыток подряд.");
+ });
+});