dika/test/src-note.test.js
peppa-bot 4df6699534
All checks were successful
peppa/lint lint: success за 1с
peppa/test test: success за 0с
peppa/build build: success за 0с
ci / checks (pull_request) Successful in 10s
deploy / deploy (pull_request) Successful in 33s
DIK-66: источник описания и фото на карточке, «Фото пока нет» у заглушки
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 12:15:59 +00:00

35 lines
2.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import { srcParts } from "../public/src-note.js";
const L = Object.fromEntries(["ru", "kk", "en"].map((l) => [l, JSON.parse(fs.readFileSync(`public/i18n/${l}.json`, "utf8"))]));
const app = fs.readFileSync("public/app.js", "utf8");
const base = fs.readFileSync("public/base.js", "utf8");
test("Сценарий: Описание из 2ГИС — «Источник описания: 2ГИС» ссылкой", () => {
assert.deepEqual(srcParts("2ГИС — https://2gis.kz/astana/firm/70000001018081639", L.ru),
{ name: "2ГИС", href: "https://2gis.kz/astana/firm/70000001018081639" });
assert.equal(L.ru.srcDescLabel, "Источник описания:");
for (const l of ["kk", "en"]) assert.ok(L[l].srcDescLabel && L[l].srcDescLabel !== L.ru.srcDescLabel, l);
// одна и та же подпись на главной и на «Все заведения»
assert.match(app, /srcNode\(t\.srcDescLabel, v\.description && v\.descriptionSource/);
assert.match(base, /t\.srcDescLabel, v\.description && v\.descriptionSource/);
});
test("Сценарий: Фото от владельца — «Источник фото: добавлено владельцем»", () => {
assert.deepEqual(srcParts("владелец", L.ru), { name: "добавлено владельцем", href: null });
assert.deepEqual(srcParts("владелец", L.en), { name: L.en.srcOwner, href: null });
assert.match(app, /srcNode\(t\.srcPhotoLabel, v\.photo && v\.photoSource/);
assert.match(base, /t\.srcPhotoLabel, v\.photo && v\.photoSource/);
});
test("Сценарий: Фото нет — «Фото пока нет», подписи источника нет", () => {
assert.equal(srcParts(null, L.ru), null);
assert.equal(srcParts("", L.ru), null);
assert.equal(L.ru.noPhoto, "Фото пока нет");
assert.match(app, /n\.textContent = t\.noPhoto/);
assert.match(base, /v\.photo \? t\.photoOf : t\.noPhoto,/);
assert.doesNotMatch(base, /noPhotoBase/); // служебное слово «заглушка» на экран не выводим
});