Commit 73442198 by PLN (Algolia)

tests: blog suites own their fixtures — synthetic draft + EN-only posts, dynamic live roster

The owner edits content freely; accessors are what the suite pins.
Co-Authored-By: 's avatarClaude Opus 5 <noreply@anthropic.com>
parent 81cf8759
...@@ -71,6 +71,9 @@ const FIXTURE_DIR = path.join(process.cwd(), "content", "blog", FIXTURE_SLUG); ...@@ -71,6 +71,9 @@ const FIXTURE_DIR = path.join(process.cwd(), "content", "blog", FIXTURE_SLUG);
const DRAFT_SLUG = "_fixture-draft"; const DRAFT_SLUG = "_fixture-draft";
const DRAFT_DIR = path.join(process.cwd(), "content", "blog", DRAFT_SLUG); const DRAFT_DIR = path.join(process.cwd(), "content", "blog", DRAFT_SLUG);
const EN_SLUG = "_fixture-en-only";
const EN_DIR = path.join(process.cwd(), "content", "blog", EN_SLUG);
beforeAll(() => { beforeAll(() => {
fs.rmSync(FIXTURE_DIR, { recursive: true, force: true }); fs.rmSync(FIXTURE_DIR, { recursive: true, force: true });
fs.mkdirSync(FIXTURE_DIR, { recursive: true }); fs.mkdirSync(FIXTURE_DIR, { recursive: true });
...@@ -96,11 +99,18 @@ beforeAll(() => { ...@@ -96,11 +99,18 @@ beforeAll(() => {
path.join(DRAFT_DIR, "fr.md"), path.join(DRAFT_DIR, "fr.md"),
"---\ntitle: Brouillon\n---\n\nCorps de brouillon.\n", "---\ntitle: Brouillon\n---\n\nCorps de brouillon.\n",
); );
fs.rmSync(EN_DIR, { recursive: true, force: true });
fs.mkdirSync(EN_DIR, { recursive: true });
fs.writeFileSync(
path.join(EN_DIR, "en.md"),
"---\ntitle: EN Fixture\n---\n\nEnglish only body.\n",
);
}); });
afterAll(() => { afterAll(() => {
fs.rmSync(FIXTURE_DIR, { recursive: true, force: true }); fs.rmSync(FIXTURE_DIR, { recursive: true, force: true });
fs.rmSync(DRAFT_DIR, { recursive: true, force: true }); fs.rmSync(DRAFT_DIR, { recursive: true, force: true });
fs.rmSync(EN_DIR, { recursive: true, force: true });
}); });
describe("blog public accessors (prod rule untouched)", () => { describe("blog public accessors (prod rule untouched)", () => {
...@@ -161,7 +171,7 @@ describe("blog public accessors (prod rule untouched)", () => { ...@@ -161,7 +171,7 @@ describe("blog public accessors (prod rule untouched)", () => {
describe("bilingual accessors", () => { describe("bilingual accessors", () => {
it("reports available languages from the folder contents", () => { it("reports available languages from the folder contents", () => {
expect(getBlogLanguages("hello-world-again")).toEqual(["fr"]); expect(getBlogLanguages("hello-world-again")).toEqual(["fr"]);
expect(getBlogLanguages("next")).toEqual(["en"]); expect(getBlogLanguages(EN_SLUG)).toEqual(["en"]);
expect(getBlogLanguages(FIXTURE_SLUG)).toEqual(["fr", "en"]); expect(getBlogLanguages(FIXTURE_SLUG)).toEqual(["fr", "en"]);
}); });
...@@ -194,10 +204,10 @@ describe("bilingual accessors", () => { ...@@ -194,10 +204,10 @@ describe("bilingual accessors", () => {
expect(en.untranslated).toBe("en"); expect(en.untranslated).toBe("en");
// fr requested on an en-only post: en renders, banner data present. // fr requested on an en-only post: en renders, banner data present.
const next = await getBlogPost("next"); const next = await getBlogPost(EN_SLUG);
expect(next.lang).toBe("en"); expect(next.lang).toBe("en");
expect(next.untranslated).toBe("fr"); expect(next.untranslated).toBe("fr");
expect(next.title).toBe("NextJs Tutorial"); expect(next.title).toBe("EN Fixture");
}); });
it("throws for unknown slugs", async () => { it("throws for unknown slugs", async () => {
...@@ -218,13 +228,13 @@ describe("buildLanguageNav — banner and switcher data", () => { ...@@ -218,13 +228,13 @@ describe("buildLanguageNav — banner and switcher data", () => {
it("links the available language when the requested one is missing", () => { it("links the available language when the requested one is missing", () => {
const frMissing = buildLanguageNav({ const frMissing = buildLanguageNav({
slug: "next", lang: "en", untranslated: "fr", languages: ["en"], slug: EN_SLUG, lang: "en", untranslated: "fr", languages: ["en"],
}); });
expect(frMissing.switcher).toEqual([]); expect(frMissing.switcher).toEqual([]);
expect(frMissing.banner.text).toBe( expect(frMissing.banner.text).toBe(
"Cet article n'existe pas (encore) en français — voici la version anglaise.", "Cet article n'existe pas (encore) en français — voici la version anglaise.",
); );
expect(frMissing.banner.href).toBe("/blog/next/en"); expect(frMissing.banner.href).toBe(`/blog/${EN_SLUG}/en`);
const enMissing = buildLanguageNav({ const enMissing = buildLanguageNav({
slug: "foo", lang: "fr", untranslated: "en", languages: ["fr"], slug: "foo", lang: "fr", untranslated: "en", languages: ["fr"],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment