52 lines
2.6 KiB
TypeScript
52 lines
2.6 KiB
TypeScript
function assert(condition: unknown, message = "assertion failed"): void {
|
|
if (!condition) throw new Error(message);
|
|
}
|
|
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
import DocumentationHelpLink, { DocumentationHelpProvider } from "../src/components/help/DocumentationHelpLink";
|
|
import FieldLabel from "../src/components/help/FieldLabel";
|
|
import { documentationHelpHref } from "../src/components/help/documentationHelp";
|
|
|
|
assert(
|
|
documentationHelpHref({ topicId: "campaigns.workflow.complete-review" }) ===
|
|
"/docs?type=user&topic=campaigns.workflow.complete-review",
|
|
"topic references use the stable Help Center query contract"
|
|
);
|
|
assert(
|
|
documentationHelpHref({ contextId: "campaign.review-send", documentationType: "admin" }) ===
|
|
"/docs?type=admin&context=campaign.review-send",
|
|
"context references retain the requested audience projection"
|
|
);
|
|
assert(
|
|
documentationHelpHref({ contextId: "calendar.field.title", fallbackContextId: "calendar.page", moduleId: "calendar" }) ===
|
|
"/docs?type=user&context=calendar.field.title&fallback_context=calendar.page&module=calendar",
|
|
"focused controls retain their page and module documentation fallback"
|
|
);
|
|
assert(
|
|
documentationHelpHref({ topicId: "topic", anchorId: "details" }) ===
|
|
"/docs?type=user&topic=topic#details",
|
|
"optional stable anchors are preserved"
|
|
);
|
|
assert(documentationHelpHref({}) === null, "an empty reference does not create a misleading link");
|
|
|
|
const hostedMarkup = renderToStaticMarkup(
|
|
<DocumentationHelpLink reference={{ contextId: "files.list" }} />
|
|
);
|
|
assert(hostedMarkup.includes("https://govoplan.add-ideas.de/?type=user&context=files.list"), "the link falls back to hosted documentation when Docs is absent");
|
|
assert(hostedMarkup.includes('target="_blank"'), "hosted documentation is clearly external");
|
|
|
|
const localMarkup = renderToStaticMarkup(
|
|
<DocumentationHelpProvider localDocsAvailable>
|
|
<DocumentationHelpLink reference={{ topicId: "docs.pattern.field-help" }} />
|
|
</DocumentationHelpProvider>
|
|
);
|
|
assert(localMarkup.includes("/docs?type=user&topic=docs.pattern.field-help"), "an enabled Docs module uses the local Help Center");
|
|
assert(!localMarkup.includes('target="_blank"'), "local documentation stays in the application");
|
|
|
|
const fieldMarkup = renderToStaticMarkup(
|
|
<DocumentationHelpProvider localDocsAvailable>
|
|
<FieldLabel documentation={{ topicId: "access.reference.admin-access-fields" }}>Role</FieldLabel>
|
|
</DocumentationHelpProvider>
|
|
);
|
|
assert(fieldMarkup.includes("topic=access.reference.admin-access-fields"), "field labels can link to stable reference topics");
|