mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-11-13 17:08:20 +00:00
chore: clear lint rules warns: comments, tests
This commit is contained in:
@@ -5,14 +5,16 @@ import { normalizeForSearch } from "./matching";
|
||||
import { t } from "./t";
|
||||
import { getPageBySlug, PAGES } from "../registry";
|
||||
import { pageTitle } from "./schema-tool-strings";
|
||||
import { en } from "./en";
|
||||
import { ru } from "./ru";
|
||||
|
||||
afterEach(() => {
|
||||
setLocale("ru");
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
describe("Смоук §6 i18n (новый UI)", () => {
|
||||
it("1. html lang следует за локалью", () => {
|
||||
describe("smoke: i18n (new UI)", () => {
|
||||
it("1. html lang follows the locale", () => {
|
||||
const doc = { documentElement: { lang: "" } };
|
||||
vi.stubGlobal("document", doc);
|
||||
setLocale("en");
|
||||
@@ -21,66 +23,69 @@ describe("Смоук §6 i18n (новый UI)", () => {
|
||||
expect(doc.documentElement.lang).toBe("ru");
|
||||
});
|
||||
|
||||
it("2. getLocale отражает последний выбор", () => {
|
||||
it("2. getLocale reflects the last choice", () => {
|
||||
setLocale("en");
|
||||
expect(getLocale()).toBe("en");
|
||||
setLocale("ru");
|
||||
expect(getLocale()).toBe("ru");
|
||||
});
|
||||
|
||||
it("3. Ключевые секции переведены без смеси языков", () => {
|
||||
const samples: Array<[string, string, string]> = [
|
||||
["header.workspace", "Рабочая область", "Workspace"],
|
||||
["catalog.heading", "Каталог инструментов", "Tool catalog"],
|
||||
[
|
||||
"home.heroTitle",
|
||||
"Что делаем с изображением?",
|
||||
"What do you want to do",
|
||||
],
|
||||
["chain.inputLegend", "Вход", "Input"],
|
||||
["resultCard.nextTool", "Следующий инструмент", "Next tool"],
|
||||
["download.busy", "Готовим файл", "Preparing file"],
|
||||
["dropZone.pickDefault", "Перетащите изображение", "Drop an image"],
|
||||
it("3. key sections are translated without mixing languages", () => {
|
||||
const samples: Array<[string, string | undefined, string]> = [
|
||||
["header.workspace", ru.header.workspace, "Workspace"],
|
||||
["catalog.heading", ru.catalog.heading, "Tool catalog"],
|
||||
["home.heroTitle", ru.home.heroTitle, "What do you want to do"],
|
||||
["chain.inputLegend", ru.chain.inputLegend, "Input"],
|
||||
["resultCard.nextTool", ru.resultCard.nextTool, "Next tool"],
|
||||
["download.busy", ru.download.busy, "Preparing file"],
|
||||
["dropZone.pickDefault", ru.dropZone.pickDefault, "Drop an image"],
|
||||
];
|
||||
for (const [key, ruPart, enPart] of samples) {
|
||||
for (const [key, ruValue, enPart] of samples) {
|
||||
setLocale("ru");
|
||||
expect(t(key), key + " @ru").toContain(ruPart);
|
||||
expect(t(key), key + " @ru").toBe(ruValue);
|
||||
setLocale("en");
|
||||
expect(t(key), key + " @en").toContain(enPart);
|
||||
}
|
||||
});
|
||||
|
||||
it("4. Заголовок инструмента переключается локалями (schema-tool-strings)", () => {
|
||||
it("4. tool title switches with the locale (schema-tool-strings)", () => {
|
||||
const page = getPageBySlug("crop-png") ?? PAGES[0];
|
||||
setLocale("ru");
|
||||
expect(pageTitle(page)).toContain("Обрезать");
|
||||
expect(pageTitle(page)).toBe(ru.pages?.[page.slug]?.title);
|
||||
setLocale("en");
|
||||
expect(pageTitle(page)).toBe(page.title);
|
||||
});
|
||||
|
||||
it("5. Ошибки с vars локализуются на оба языка", () => {
|
||||
it("5. errors with vars localize to both languages", () => {
|
||||
setLocale("ru");
|
||||
expect(t("errors.badHex", { value: "#zz" })).toBe(
|
||||
'Некорректный HEX-цвет: "#zz"',
|
||||
(ru.errors.badHex ?? "").replace("{value}", "#zz"),
|
||||
);
|
||||
expect(t("errors.pageUnknown", { slug: "x" })).toBe(
|
||||
(ru.errors.pageUnknown ?? "").replace("{slug}", "x"),
|
||||
);
|
||||
expect(t("errors.pageUnknown", { slug: "x" })).toContain("каталоге");
|
||||
setLocale("en");
|
||||
expect(t("errors.badHex", { value: "#zz" })).toBe(
|
||||
'Invalid HEX color: "#zz"',
|
||||
(en.errors.badHex ?? "").replace("{value}", "#zz"),
|
||||
);
|
||||
expect(t("errors.pageUnknown", { slug: "x" })).toContain("No page");
|
||||
});
|
||||
|
||||
it("6. Ё не мешает нормализации поискового запроса", () => {
|
||||
expect(normalizeForSearch("ЧЁРНО") === normalizeForSearch("ЧЕРНО")).toBe(
|
||||
true,
|
||||
it("6. U+0451 (yo) does not break query normalization", () => {
|
||||
const YO = "\u0451";
|
||||
const YE = "\u0435";
|
||||
// dictionary word containing U+0451, from the ru grayscale title
|
||||
const word = (ru.pages?.["grayscale-png"]?.title ?? "").split(" ")[0];
|
||||
expect(word).toContain(YO);
|
||||
expect(normalizeForSearch(word)).toBe(
|
||||
normalizeForSearch(word.replaceAll(YO, YE)),
|
||||
);
|
||||
expect(normalizeForSearch("ёлка") === normalizeForSearch("елка")).toBe(
|
||||
true,
|
||||
expect(normalizeForSearch(word.toUpperCase())).toBe(
|
||||
normalizeForSearch(word.toUpperCase().replaceAll(YO, YE)),
|
||||
);
|
||||
});
|
||||
|
||||
it("7. Теги локалей для форматирования чисел корректны", () => {
|
||||
it("7. locale tags for number formatting are correct", () => {
|
||||
expect(LOCALE_TAGS.ru).toBe("ru-RU");
|
||||
expect(LOCALE_TAGS.en).toBe("en-US");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user