SEO: drop noindex order steps from sitemap + per-dataset detail metadata
CI (SIAX Cloud) / sonar (pull_request) Skipped
masterplan-lock / check (pull_request) Successful in 9s
CI (SIAX Cloud) / Component conformance (blocking) (pull_request) Successful in 13s
CI (SIAX Cloud) / security (pull_request) Successful in 20s
security / scan (pull_request) Failing after 43s
CI (SIAX Cloud) / quality (pull_request) Failing after 3m11s
CI (SIAX Cloud) / integration (pull_request) Successful in 3m41s

- sitemap now lists only public landing pages; /bestall* (noindex per PR #622)
  is no longer announced to crawlers.
- /katalog/[id] gets route-level generateMetadata with a unique title,
  description and canonical per dataset instead of inheriting /katalog's
  canonical. Unknown ids are explicitly noindex with canonical back to catalog.
- Dataset seed extracted to app/katalog/datasets.ts so the client detail page
  and server metadata share one source of truth.
- 10 regression tests covering home/catalog/two datasets/order step and
  sitemap+robots.
This commit is contained in:
2026-11-17 18:22:35 +01:00
parent 80d51a43cd
commit 860bb22aef
5 changed files with 289 additions and 120 deletions
@@ -0,0 +1,121 @@
/**
* SEO regression guard: sitemap vs. indexation policy, and per-dataset
* canonicals on /katalog/[id].
*
* PR #622 made /bestall*, noindex via app/bestall/layout.tsx but left those
* steps in app/sitemap.ts, and the new /katalog layout canonical leaked down
* to every dataset detail. These tests exercise the public surfaces together:
* home (sitemap root), catalog, two datasets, an order step, sitemap + robots.
*/
import { describe, it, expect } from "vitest";
import type { Metadata } from "next";
import sitemap from "@/app/sitemap";
import robots from "@/app/robots";
import { metadata as catalogMetadata } from "@/app/katalog/layout";
import { metadata as bestallMetadata } from "@/app/bestall/layout";
import { generateMetadata as datasetGenerateMetadata } from "@/app/katalog/[id]/layout";
import { CATALOG } from "@/app/katalog/datasets";
const BASE = "https://0pt.app";
function canonicalOf(m: Metadata): unknown {
return m.alternates?.canonical;
}
// Next's Metadata.robots is `string | Robots`; the root layout sets
// index:true, so an unset value means the detail stays indexable.
function isIndexed(m: Metadata): boolean {
const r = m.robots;
if (r === undefined || r === null) return true;
if (typeof r === "string") return r !== "noindex" && r !== "none";
return r.index !== false;
}
function datasetMeta(id: string): Promise<Metadata> {
// Next 16 passes dynamic route params as a Promise to generateMetadata.
return datasetGenerateMetadata({ params: Promise.resolve({ id }) });
}
describe("sitemap — public pages only", () => {
const urls = () => sitemap().map((entry) => entry.url);
it("lists home, tjanster, katalog and kallor — and nothing else", () => {
expect(urls()).toEqual([
`${BASE}`,
`${BASE}/tjanster`,
`${BASE}/katalog`,
`${BASE}/kallor`,
]);
});
it("never lists the noindex order flow (/bestall*)", () => {
expect(urls().filter((url) => url.startsWith(`${BASE}/bestall`))).toEqual([]);
});
it("keeps home as the top-priority entry", () => {
const home = sitemap().find((entry) => entry.url === `${BASE}`);
expect(home).toBeDefined();
expect(home?.priority).toBe(1);
for (const entry of sitemap().filter((e) => e.url !== `${BASE}`)) {
expect(entry.priority).toBeLessThan(1);
}
});
});
describe("robots + order-step indexation", () => {
it("allows public crawling, disallows auth surfaces and advertises the sitemap", () => {
const rules = robots().rules as Array<{
userAgent: string;
allow?: string;
disallow?: string | string[];
}>;
expect(rules[0].userAgent).toBe("*");
expect(rules[0].allow).toBe("/");
expect(rules[0].disallow).toEqual(["/portal/", "/admin/", "/order/", "/api/"]);
expect(robots().sitemap).toBe(`${BASE}/sitemap.xml`);
});
it("the order step is noindex/follow and stays out of the sitemap", () => {
expect(bestallMetadata.robots).toMatchObject({ index: false, follow: true });
expect(sitemap().map((e) => e.url).some((u) => u.includes("/bestall"))).toBe(false);
});
});
describe("catalog + dataset detail canonicals", () => {
it("the catalog index keeps its own canonical", () => {
expect(canonicalOf(catalogMetadata)).toBe(`${BASE}/katalog`);
});
it("every indexable dataset detail carries its own canonical, title and description", async () => {
expect(CATALOG).toHaveLength(6);
for (const dataset of CATALOG) {
const meta = await datasetMeta(dataset.id);
expect(canonicalOf(meta)).toBe(`${BASE}/katalog/${dataset.id}`);
expect(canonicalOf(meta)).not.toBe(canonicalOf(catalogMetadata));
expect(String(meta.title)).toContain(dataset.title.en);
expect(String(meta.description ?? "")).toContain(dataset.blurb.en);
// Root layout declares index:true; details must not silently opt out.
expect(isIndexed(meta)).toBe(true);
}
});
it("two different datasets resolve to distinct canonicals and titles", async () => {
const a = await datasetMeta("nordic-companies");
const b = await datasetMeta("tech-decisionmakers");
expect(canonicalOf(a)).toBe(`${BASE}/katalog/nordic-companies`);
expect(canonicalOf(b)).toBe(`${BASE}/katalog/tech-decisionmakers`);
expect(canonicalOf(a)).not.toBe(canonicalOf(b));
expect(a.title).not.toBe(b.title);
});
it("canonical uses the stable catalogue id even for a non-normalized request", async () => {
const meta = await datasetMeta("Nordic-Companies");
expect(canonicalOf(meta)).toBe(`${BASE}/katalog/nordic-companies`);
});
it("an unknown dataset id is explicitly noindex and canonicals to the catalog", async () => {
const meta = await datasetMeta("does-not-exist");
expect(meta.robots).toMatchObject({ index: false, follow: true });
expect(canonicalOf(meta)).toBe(`${BASE}/katalog`);
});
});