119 lines
5.2 KiB
JavaScript
119 lines
5.2 KiB
JavaScript
import { describe, expect, it } from "vitest";
|
|
import cityData from "@/data/city.json";
|
|
import stateData from "@/data/state.json";
|
|
import { buildAboutIntro, buildContactIntro } from "@/lib/staticPageIntro";
|
|
import { buildCanonicalUrl, buildMainCanonicalUrl } from "@/lib/getCanonicalUrl";
|
|
|
|
const CITIES = ["بهبهان", "یاسوج", "یزد", "تبریز", "اصفهان"];
|
|
|
|
describe("متن شهری صفحات استاتیک", () => {
|
|
it("دو شهر متن یکسان نمیگیرند", () => {
|
|
expect(buildAboutIntro("بهبهان", "خوزستان", "بهبهان نوبت")).not.toBe(
|
|
buildAboutIntro("یاسوج", "کهگیلویه و بویراحمد", "یاسوج نوبت")
|
|
);
|
|
});
|
|
|
|
it("یک شهر در دو فراخوانی همان متن را میدهد", () => {
|
|
expect(buildAboutIntro("بهبهان", "خوزستان", "بهبهان نوبت")).toBe(
|
|
buildAboutIntro("بهبهان", "خوزستان", "بهبهان نوبت")
|
|
);
|
|
});
|
|
|
|
it("درباره ما و تماس با ما برای یک شهر متن یکسان نمیگیرند", () => {
|
|
// seed هر دو از نام شهر میآید؛ اگر جابهجایی بیت نبود، یک ساختار میگرفتند.
|
|
const about = buildAboutIntro("یزد", "یزد", "یزد نوبت");
|
|
const contact = buildContactIntro("یزد", "یزد", "یزد نوبت");
|
|
|
|
expect(about).not.toBe(contact);
|
|
});
|
|
|
|
it("نام شهر و استان و برند در متن میآیند", () => {
|
|
const text = buildAboutIntro("بهبهان", "خوزستان", "بهبهان نوبت");
|
|
|
|
expect(text).toContain("بهبهان");
|
|
expect(text).toContain("خوزستان");
|
|
});
|
|
|
|
it("شهر بدون نام، متن خالی میدهد و صفحه را نمیشکند", () => {
|
|
expect(buildAboutIntro(undefined, "خوزستان", "نوبت 724")).toBe("");
|
|
expect(buildContactIntro(null, null, null)).toBe("");
|
|
});
|
|
|
|
it("استان نامشخص جای خالی و undefined در متن نمیگذارد", () => {
|
|
const text = buildContactIntro("شهر تازه", undefined, undefined);
|
|
|
|
expect(text).not.toContain("undefined");
|
|
expect(text).toContain("شهر تازه");
|
|
});
|
|
|
|
it("متنها روی شهرهای واقعی به یک قالب واحد نمیچسبند", () => {
|
|
const texts = CITIES.map((c) => buildAboutIntro(c, "استان", `${c} نوبت`));
|
|
|
|
expect(new Set(texts).size).toBeGreaterThan(1);
|
|
});
|
|
|
|
it("روی همهٔ شهرهای واقعی بدون خطا اجرا میشود", () => {
|
|
for (const city of cityData) {
|
|
const province = stateData.find((s) => s.id === city.province_id);
|
|
const text = buildAboutIntro(city.name, province?.name, city.site_name);
|
|
|
|
expect(typeof text).toBe("string");
|
|
expect(text).not.toContain("undefined");
|
|
}
|
|
});
|
|
|
|
it("دو شهرِ همvariant با جایگذاری نام تمایز نمیگیرند، با شعار میگیرند", () => {
|
|
// سنجیده شد: بهبهان و یاسوج روی هر دو صفحه یک variant میگرفتند و تفاوتشان
|
|
// فقط نام شهر بود — همان چیزی که duplicate را برنمیگرداند.
|
|
const cityOf = (name) => cityData.find((c) => c.name === name);
|
|
const behbahan = cityOf("بهبهان");
|
|
const yasuj = cityOf("یاسوج");
|
|
|
|
const strip = (text, city) => text.split(city).join("«شهر»");
|
|
|
|
const a = strip(
|
|
buildAboutIntro(behbahan.name, "خوزستان", behbahan.site_name, behbahan.slogan),
|
|
behbahan.name
|
|
);
|
|
const b = strip(
|
|
buildAboutIntro(yasuj.name, "کهگیلویه و بویراحمد", yasuj.site_name, yasuj.slogan),
|
|
yasuj.name
|
|
);
|
|
|
|
expect(a).not.toBe(b);
|
|
});
|
|
|
|
it("هیچ دو شهری روی هیچکدام از دو صفحه متن یکسان نمیگیرند", () => {
|
|
for (const build of [buildAboutIntro, buildContactIntro]) {
|
|
const texts = cityData.map((city) => {
|
|
const province = stateData.find((s) => s.id === city.province_id);
|
|
return build(city.name, province?.name, city.site_name, city.slogan);
|
|
});
|
|
|
|
expect(new Set(texts).size).toBe(cityData.length);
|
|
}
|
|
});
|
|
|
|
it("شهر بدون شعار، جملهٔ ناقص یا undefined نمیگیرد", () => {
|
|
const text = buildAboutIntro("شهر تازه", "استان", "برند", undefined);
|
|
|
|
expect(text).not.toContain("undefined");
|
|
expect(text).not.toContain("شعار ما همین است: .");
|
|
});
|
|
});
|
|
|
|
describe("canonical صفحات استاتیک", () => {
|
|
it("درباره ما و تماس با ما دیگر به دامنهٔ اصلی نمیروند", () => {
|
|
// این همان چیزی بود که Search Console «Alternate page with proper canonical»
|
|
// گزارش میکرد؛ صفحه روی هیچ دامنهٔ شهری ایندکس نمیشد.
|
|
for (const path of ["/about-us", "/contact-us"]) {
|
|
expect(buildCanonicalUrl("behbahan-nobat.ir", path)).toBe(
|
|
`https://behbahan-nobat.ir${path}`
|
|
);
|
|
expect(buildMainCanonicalUrl(path)).not.toBe(
|
|
buildCanonicalUrl("behbahan-nobat.ir", path)
|
|
);
|
|
}
|
|
});
|
|
});
|