Implement WP-26 features for Section-Types, Block-IDs, and Edge Suggestions
- Enhanced the interview configuration parsing to support section_type, block_id, and generate_block_id properties. - Updated the renderer to incorporate Section-Types and Block-IDs, allowing for automatic edge suggestions during markdown rendering. - Introduced new RenderOptions for improved handling of graph schema and vocabulary in the rendering process. - Implemented tracking of Section-Info during the wizard flow, including updates for loop items and nested steps. - Enhanced the InterviewWizardModal to support Block-ID selection for intra-note links, improving user experience and functionality.
This commit is contained in:
1 parent
3be7d617fe
commit
b99416b67d
6 files changed
+1379
-122
No files matched your search
@@ -0,0 +1,305 @@
|
||||
/**
|
||||
* Tests für WP-26 Interview-Wizard Renderer
|
||||
* Prüft Section-Types, Block-IDs, automatische Edge-Vorschläge und Selbstreferenz-Prüfung
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { renderProfileToMarkdown, type RenderAnswers, type RenderOptions } from "./renderer";
|
||||
import type { InterviewProfile } from "./types";
|
||||
import type { GraphSchema, EdgeTypeHints } from "../mapping/graphSchema";
|
||||
import { Vocabulary } from "../vocab/Vocabulary";
|
||||
import { parseEdgeVocabulary } from "../vocab/parseEdgeVocabulary";
|
||||
|
||||
describe("WP-26 Interview Renderer", () => {
|
||||
// Mock Vocabulary
|
||||
const mockVocabularyText = `| System-Typ (Canonical) | Inverser Typ | Erlaubte Aliasse (User) | Beschreibung |
|
||||
|------------------------|--------------|-------------------------|-------------|
|
||||
| resulted_in | resulted_from| führt zu, bewirkt | Forward edge |
|
||||
| resulted_from | resulted_in | stammt aus, kommt von | Inverse edge |
|
||||
| related_to | related_to | verbunden mit | Bidirectional |`;
|
||||
|
||||
const mockVocabulary = new Vocabulary(parseEdgeVocabulary(mockVocabularyText));
|
||||
|
||||
// Mock GraphSchema
|
||||
const mockGraphSchema: GraphSchema = {
|
||||
schema: new Map<string, Map<string, EdgeTypeHints>>([
|
||||
[
|
||||
"experience",
|
||||
new Map<string, EdgeTypeHints>([
|
||||
[
|
||||
"insight",
|
||||
{
|
||||
typical: ["resulted_in"],
|
||||
prohibited: [],
|
||||
},
|
||||
],
|
||||
]),
|
||||
],
|
||||
]),
|
||||
};
|
||||
|
||||
const mockOptions: RenderOptions = {
|
||||
graphSchema: mockGraphSchema,
|
||||
vocabulary: mockVocabulary,
|
||||
noteType: "experience",
|
||||
};
|
||||
|
||||
it("sollte keine Selbstreferenz bei automatischen Edges generieren", () => {
|
||||
const profile: InterviewProfile = {
|
||||
version: "2.0",
|
||||
frontmatterWhitelist: [],
|
||||
key: "test",
|
||||
label: "Test",
|
||||
note_type: "experience",
|
||||
steps: [
|
||||
{
|
||||
type: "capture_text",
|
||||
key: "context",
|
||||
section: "## Kontext",
|
||||
section_type: "experience",
|
||||
generate_block_id: true,
|
||||
},
|
||||
{
|
||||
type: "capture_text",
|
||||
key: "insight",
|
||||
section: "## Einsicht",
|
||||
section_type: "insight",
|
||||
generate_block_id: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const answers: RenderAnswers = {
|
||||
collectedData: new Map([
|
||||
["context", "Kontext-Text"],
|
||||
["insight", "Einsicht-Text"],
|
||||
]),
|
||||
loopContexts: new Map(),
|
||||
};
|
||||
|
||||
const result = renderProfileToMarkdown(profile, answers, mockOptions);
|
||||
|
||||
// Prüfe, dass keine Selbstreferenz vorhanden ist
|
||||
const contextSection = result.match(/## Kontext.*?## Einsicht/s)?.[0];
|
||||
expect(contextSection).toBeDefined();
|
||||
|
||||
// Prüfe, dass keine Edge auf sich selbst zeigt
|
||||
const selfReference = contextSection?.match(/\[\[#\^context\]\]/);
|
||||
expect(selfReference).toBeNull();
|
||||
|
||||
// Prüfe, dass Edges generiert wurden
|
||||
const edges = result.match(/> \[!edge\]/g);
|
||||
expect(edges?.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("sollte Edge-Types aus graph_schema verwenden", () => {
|
||||
const profile: InterviewProfile = {
|
||||
version: "2.0",
|
||||
frontmatterWhitelist: [],
|
||||
key: "test",
|
||||
label: "Test",
|
||||
note_type: "experience",
|
||||
steps: [
|
||||
{
|
||||
type: "capture_text",
|
||||
key: "experience",
|
||||
section: "## Erfahrung",
|
||||
section_type: "experience",
|
||||
generate_block_id: true,
|
||||
},
|
||||
{
|
||||
type: "capture_text",
|
||||
key: "insight",
|
||||
section: "## Einsicht",
|
||||
section_type: "insight",
|
||||
generate_block_id: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const answers: RenderAnswers = {
|
||||
collectedData: new Map([
|
||||
["experience", "Erfahrungs-Text"],
|
||||
["insight", "Einsicht-Text"],
|
||||
]),
|
||||
loopContexts: new Map(),
|
||||
};
|
||||
|
||||
const result = renderProfileToMarkdown(profile, answers, mockOptions);
|
||||
|
||||
// Debug: Zeige das Ergebnis
|
||||
console.log("Render-Ergebnis:", result);
|
||||
|
||||
// Prüfe, dass Edges generiert wurden
|
||||
const edges = result.match(/> \[!edge\]/g);
|
||||
expect(edges?.length).toBeGreaterThan(0);
|
||||
|
||||
// Prüfe, dass "resulted_in" oder "resulted_from" verwendet wird (aus graph_schema)
|
||||
// Falls graph_schema nicht verfügbar ist, wird "related_to" verwendet (Fallback)
|
||||
const hasResultedEdge = result.match(/resulted_(in|from)/);
|
||||
const hasRelatedEdge = result.match(/related_to/);
|
||||
|
||||
// Mindestens eine Edge sollte vorhanden sein
|
||||
expect(hasResultedEdge || hasRelatedEdge).toBeTruthy();
|
||||
|
||||
// Wenn graph_schema verfügbar ist, sollte "resulted_in" oder "resulted_from" verwendet werden
|
||||
if (mockOptions.graphSchema) {
|
||||
expect(hasResultedEdge).toBeTruthy();
|
||||
}
|
||||
});
|
||||
|
||||
it("sollte Backlinks automatisch generieren", () => {
|
||||
const profile: InterviewProfile = {
|
||||
version: "2.0",
|
||||
frontmatterWhitelist: [],
|
||||
key: "test",
|
||||
label: "Test",
|
||||
note_type: "experience",
|
||||
steps: [
|
||||
{
|
||||
type: "capture_text",
|
||||
key: "context",
|
||||
section: "## Kontext",
|
||||
section_type: "experience",
|
||||
generate_block_id: true,
|
||||
},
|
||||
{
|
||||
type: "capture_text",
|
||||
key: "insight",
|
||||
section: "## Einsicht",
|
||||
section_type: "insight",
|
||||
generate_block_id: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const answers: RenderAnswers = {
|
||||
collectedData: new Map([
|
||||
["context", "Kontext-Text"],
|
||||
["insight", "Einsicht-Text"],
|
||||
]),
|
||||
loopContexts: new Map(),
|
||||
};
|
||||
|
||||
const result = renderProfileToMarkdown(profile, answers, mockOptions);
|
||||
|
||||
// Prüfe, dass beide Edge-Types vorhanden sind (Forward und Backward)
|
||||
const forwardEdge = result.match(/resulted_in/);
|
||||
const backwardEdge = result.match(/resulted_from/);
|
||||
|
||||
expect(forwardEdge).toBeDefined();
|
||||
expect(backwardEdge).toBeDefined();
|
||||
});
|
||||
|
||||
it("sollte keine Selbstreferenz bei expliziten Referenzen erlauben", () => {
|
||||
const profile: InterviewProfile = {
|
||||
version: "2.0",
|
||||
frontmatterWhitelist: [],
|
||||
key: "test",
|
||||
label: "Test",
|
||||
note_type: "experience",
|
||||
steps: [
|
||||
{
|
||||
type: "capture_text",
|
||||
key: "context",
|
||||
section: "## Kontext",
|
||||
section_type: "experience",
|
||||
block_id: "context",
|
||||
references: [
|
||||
{
|
||||
block_id: "context", // Selbstreferenz - sollte verhindert werden
|
||||
edge_type: "related_to",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const answers: RenderAnswers = {
|
||||
collectedData: new Map([
|
||||
["context", "Kontext-Text"],
|
||||
]),
|
||||
loopContexts: new Map(),
|
||||
};
|
||||
|
||||
const result = renderProfileToMarkdown(profile, answers, mockOptions);
|
||||
|
||||
// Prüfe, dass keine Selbstreferenz generiert wurde
|
||||
const selfReference = result.match(/\[\[#\^context\]\]/);
|
||||
// Sollte null sein, da Selbstreferenz verhindert wird
|
||||
expect(selfReference).toBeNull();
|
||||
});
|
||||
|
||||
it("sollte Section-Type-Callout direkt nach Heading platzieren", () => {
|
||||
const profile: InterviewProfile = {
|
||||
version: "2.0",
|
||||
frontmatterWhitelist: [],
|
||||
key: "test",
|
||||
label: "Test",
|
||||
note_type: "experience",
|
||||
steps: [
|
||||
{
|
||||
type: "capture_text",
|
||||
key: "context",
|
||||
section: "## Kontext",
|
||||
section_type: "experience",
|
||||
generate_block_id: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const answers: RenderAnswers = {
|
||||
collectedData: new Map([
|
||||
["context", "Kontext-Text"],
|
||||
]),
|
||||
loopContexts: new Map(),
|
||||
};
|
||||
|
||||
const result = renderProfileToMarkdown(profile, answers, mockOptions);
|
||||
|
||||
// Prüfe, dass Section-Type-Callout direkt nach Heading steht
|
||||
const sectionPattern = /## Kontext.*?\n> \[!section\] experience/s;
|
||||
expect(result).toMatch(sectionPattern);
|
||||
});
|
||||
|
||||
it("sollte Edges am Ende der Sektion platzieren", () => {
|
||||
const profile: InterviewProfile = {
|
||||
version: "2.0",
|
||||
frontmatterWhitelist: [],
|
||||
key: "test",
|
||||
label: "Test",
|
||||
note_type: "experience",
|
||||
steps: [
|
||||
{
|
||||
type: "capture_text",
|
||||
key: "context",
|
||||
section: "## Kontext",
|
||||
section_type: "experience",
|
||||
generate_block_id: true,
|
||||
},
|
||||
{
|
||||
type: "capture_text",
|
||||
key: "insight",
|
||||
section: "## Einsicht",
|
||||
section_type: "insight",
|
||||
generate_block_id: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const answers: RenderAnswers = {
|
||||
collectedData: new Map([
|
||||
["context", "Kontext-Text"],
|
||||
["insight", "Einsicht-Text"],
|
||||
]),
|
||||
loopContexts: new Map(),
|
||||
};
|
||||
|
||||
const result = renderProfileToMarkdown(profile, answers, mockOptions);
|
||||
|
||||
// Prüfe, dass Edges am Ende der Einsicht-Sektion stehen (nach dem Text)
|
||||
const insightSection = result.match(/## Einsicht.*?Einsicht-Text\n\n(> \[!edge\].*)/s)?.[1];
|
||||
expect(insightSection).toBeDefined();
|
||||
expect(insightSection).toMatch(/> \[!edge\]/);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user