"use strict";
/**
 * Tests for MarkdownDocumentationGenerator
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const markdown_generator_1 = require("./markdown-generator");
const workflow_parser_1 = require("../../parser/workflow-parser");
const workflow_engine_1 = require("../../engine/workflow-engine");
const path = __importStar(require("path"));
describe('MarkdownDocumentationGenerator', () => {
    let generator;
    beforeEach(() => {
        generator = new markdown_generator_1.MarkdownDocumentationGenerator();
    });
    it('should have correct metadata', () => {
        expect(generator.id).toBe('markdown-docs');
        expect(generator.name).toBe('Markdown Documentation Generator');
        expect(generator.format).toBe('markdown');
    });
    it('should generate empty result for workflow without documentation', async () => {
        const workflow = {
            workflow: {
                id: 'test',
                name: 'Test',
                version: '1.0.0',
                description: 'Test workflow',
            },
            stack: {
                app: {
                    type: 'frontend',
                    technology: 'react',
                },
            },
        };
        const engine = new workflow_engine_1.WorkflowEngine();
        const executionPlan = engine.analyze(workflow);
        const result = await generator.generate({
            workflow: workflow,
            executionPlan,
            outputDirectory: '/test',
        });
        expect(result.files).toHaveLength(0);
    });
    it('should generate documentation from user-authentication workflow', async () => {
        const parser = new workflow_parser_1.WorkflowParser();
        const workflowPath = path.join(__dirname, '../../../examples/user-authentication.workflow.yaml');
        const result = await parser.parseFile(workflowPath);
        const engine = new workflow_engine_1.WorkflowEngine();
        const executionPlan = engine.analyze(result.workflow);
        const genResult = await generator.generate({
            workflow: result.workflow,
            executionPlan,
            outputDirectory: '/test',
        });
        // Should generate files
        expect(genResult.files.length).toBeGreaterThan(0);
        // Should generate main README
        const mainReadme = genResult.files.find(f => f.path === '/test/docs/README.md');
        expect(mainReadme).toBeDefined();
        expect(mainReadme?.content).toContain('# User Authentication');
        expect(mainReadme?.content).toContain('## Stack Components');
        // Should generate user docs if they exist
        if (result.workflow.documentation?.user_docs) {
            const userReadme = genResult.files.find(f => f.path === '/test/docs/user/README.md');
            expect(userReadme).toBeDefined();
            expect(userReadme?.content).toContain('# User Documentation');
        }
        // Should generate developer docs if they exist
        if (result.workflow.documentation?.developer_docs) {
            const devReadme = genResult.files.find(f => f.path === '/test/docs/developer/README.md');
            expect(devReadme).toBeDefined();
            expect(devReadme?.content).toContain('# Developer Documentation');
        }
    });
    it('should generate user documentation files', async () => {
        const workflow = {
            workflow: {
                id: 'test',
                name: 'Test Workflow',
                version: '1.0.0',
                description: 'Test workflow description',
            },
            stack: {
                app: {
                    type: 'frontend',
                    technology: 'react',
                },
            },
            documentation: {
                user_docs: [
                    {
                        title: 'Getting Started',
                        sections: [
                            {
                                heading: 'Introduction',
                                content: 'Welcome to the app',
                                steps: ['Step 1', 'Step 2'],
                                examples: [
                                    {
                                        language: 'javascript',
                                        code: 'console.log("Hello");',
                                    },
                                ],
                            },
                        ],
                    },
                ],
            },
        };
        const engine = new workflow_engine_1.WorkflowEngine();
        const executionPlan = engine.analyze(workflow);
        const result = await generator.generate({
            workflow: workflow,
            executionPlan,
            outputDirectory: '/test',
        });
        // Should generate user doc file
        const userDoc = result.files.find(f => f.path === '/test/docs/user/getting-started.md');
        expect(userDoc).toBeDefined();
        expect(userDoc?.content).toContain('# Getting Started');
        expect(userDoc?.content).toContain('## Introduction');
        expect(userDoc?.content).toContain('Welcome to the app');
        expect(userDoc?.content).toContain('### Steps');
        expect(userDoc?.content).toContain('1. Step 1');
        expect(userDoc?.content).toContain('### Examples');
        expect(userDoc?.content).toContain('```javascript');
        expect(userDoc?.content).toContain('console.log("Hello");');
        // Should generate user docs index
        const userIndex = result.files.find(f => f.path === '/test/docs/user/README.md');
        expect(userIndex).toBeDefined();
        expect(userIndex?.content).toContain('# User Documentation');
        expect(userIndex?.content).toContain('[Getting Started](./getting-started.md)');
    });
    it('should generate developer documentation files', async () => {
        const workflow = {
            workflow: {
                id: 'test',
                name: 'Test Workflow',
                version: '1.0.0',
                description: 'Test workflow description',
            },
            stack: {
                api: {
                    type: 'backend',
                    technology: 'typescript/express',
                },
            },
            documentation: {
                developer_docs: [
                    {
                        title: 'API Reference',
                        sections: [
                            {
                                heading: 'Authentication',
                                content: 'How to authenticate',
                                examples: [
                                    {
                                        language: 'typescript',
                                        code: 'const token = getToken();',
                                    },
                                ],
                            },
                        ],
                    },
                ],
            },
        };
        const engine = new workflow_engine_1.WorkflowEngine();
        const executionPlan = engine.analyze(workflow);
        const result = await generator.generate({
            workflow: workflow,
            executionPlan,
            outputDirectory: '/test',
        });
        // Should generate developer doc file
        const devDoc = result.files.find(f => f.path === '/test/docs/developer/api-reference.md');
        expect(devDoc).toBeDefined();
        expect(devDoc?.content).toContain('# API Reference');
        expect(devDoc?.content).toContain('## Authentication');
        expect(devDoc?.content).toContain('How to authenticate');
        expect(devDoc?.content).toContain('```typescript');
        // Should generate developer docs index
        const devIndex = result.files.find(f => f.path === '/test/docs/developer/README.md');
        expect(devIndex).toBeDefined();
        expect(devIndex?.content).toContain('# Developer Documentation');
        expect(devIndex?.content).toContain('[API Reference](./api-reference.md)');
    });
    it('should slugify titles correctly', async () => {
        const workflow = {
            workflow: {
                id: 'test',
                name: 'Test',
                version: '1.0.0',
                description: 'Test',
            },
            stack: {
                app: {
                    type: 'frontend',
                    technology: 'react',
                },
            },
            documentation: {
                user_docs: [
                    {
                        title: 'Getting Started Guide!',
                        sections: [
                            {
                                heading: 'Test',
                                content: 'Test content',
                            },
                        ],
                    },
                ],
            },
        };
        const engine = new workflow_engine_1.WorkflowEngine();
        const executionPlan = engine.analyze(workflow);
        const result = await generator.generate({
            workflow: workflow,
            executionPlan,
            outputDirectory: '/test',
        });
        // Should slugify the title
        const userDoc = result.files.find(f => f.path === '/test/docs/user/getting-started-guide.md');
        expect(userDoc).toBeDefined();
    });
});
//# sourceMappingURL=markdown-generator.test.js.map