1+ const DocumentationGenerator = require ( '../functions/DocumentationGenerator' ) ;
2+ const FileParsing = require ( '../functions/FileParsing' ) ;
3+ const OutputTitle = require ( '../functions/OutputTitle' ) ;
4+ const OutputNameFilePDF = require ( '../functions/OutputNameFilePDF' ) ;
5+ const WritePDF = require ( '../functions/WritePDF' ) ;
6+ const OutputTitleMarkdown = require ( '../functions/OutputTitleMarkdown' ) ;
7+ const OutputNameFileMarkdown = require ( '../functions/OutputNameFileMarkdown' ) ;
8+ const WriteMarkdown = require ( '../functions/WriteMarkdown' ) ;
9+
10+ jest . mock ( '../functions/FileParsing' ) ;
11+ jest . mock ( '../functions/OutputTitle' ) ;
12+ jest . mock ( '../functions/OutputNameFilePDF' ) ;
13+ jest . mock ( '../functions/WritePDF' ) ;
14+ jest . mock ( '../functions/OutputTitleMarkdown' ) ;
15+ jest . mock ( '../functions/OutputNameFileMarkdown' ) ;
16+ jest . mock ( '../functions/WriteMarkdown' ) ;
17+
18+ describe ( 'DocumentationGenerator' , ( ) => {
19+ it ( 'should generate PDF documentation if format is pdf' , async ( ) => {
20+ const formData = {
21+ projectName : 'TestProject' ,
22+ formats : { pdf : true , markdown : false }
23+ } ;
24+ const rows = [ ] ;
25+ const filesParsed = [ { name : 'file1' , functions : [ ] } ] ;
26+
27+ FileParsing . mockResolvedValue ( filesParsed ) ;
28+ OutputTitle . mockReturnValue ( 'Test Project Documentation' ) ;
29+ OutputNameFilePDF . mockReturnValue ( 'TestProject.pdf' ) ;
30+
31+ await DocumentationGenerator ( formData , rows ) ;
32+
33+ expect ( FileParsing ) . toHaveBeenCalledWith ( formData , rows ) ;
34+ expect ( OutputTitle ) . toHaveBeenCalledWith ( 'TestProject' ) ;
35+ expect ( OutputNameFilePDF ) . toHaveBeenCalledWith ( 'TestProject' ) ;
36+ expect ( WritePDF ) . toHaveBeenCalledWith ( 'Test Project Documentation' , 'TestProject.pdf' , filesParsed ) ;
37+ } ) ;
38+
39+ it ( 'should generate Markdown documentation if format is markdown' , async ( ) => {
40+ const formData = {
41+ projectName : 'TestProject' ,
42+ formats : { pdf : false , markdown : true }
43+ } ;
44+ const rows = [ ] ;
45+ const filesParsed = [ { name : 'file1' , functions : [ ] } ] ;
46+
47+ FileParsing . mockResolvedValue ( filesParsed ) ;
48+ OutputTitleMarkdown . mockReturnValue ( 'Test Project Documentation' ) ;
49+ OutputNameFileMarkdown . mockReturnValue ( 'TestProject.md' ) ;
50+
51+ await DocumentationGenerator ( formData , rows ) ;
52+
53+ expect ( FileParsing ) . toHaveBeenCalledWith ( formData , rows ) ;
54+ expect ( OutputTitleMarkdown ) . toHaveBeenCalledWith ( 'TestProject' ) ;
55+ expect ( OutputNameFileMarkdown ) . toHaveBeenCalledWith ( 'TestProject' ) ;
56+ expect ( WriteMarkdown ) . toHaveBeenCalledWith ( 'Test Project Documentation' , 'TestProject.md' , filesParsed ) ;
57+ } ) ;
58+
59+ it ( 'should generate both PDF and Markdown documentation if both formats are specified' , async ( ) => {
60+ const formData = {
61+ projectName : 'TestProject' ,
62+ formats : { pdf : true , markdown : true }
63+ } ;
64+ const rows = [ ] ;
65+ const filesParsed = [ { name : 'file1' , functions : [ ] } ] ;
66+
67+ FileParsing . mockResolvedValue ( filesParsed ) ;
68+ OutputTitle . mockReturnValue ( 'Test Project Documentation' ) ;
69+ OutputNameFilePDF . mockReturnValue ( 'TestProject.pdf' ) ;
70+ OutputTitleMarkdown . mockReturnValue ( 'Test Project Documentation' ) ;
71+ OutputNameFileMarkdown . mockReturnValue ( 'TestProject.md' ) ;
72+
73+ await DocumentationGenerator ( formData , rows ) ;
74+
75+ expect ( FileParsing ) . toHaveBeenCalledWith ( formData , rows ) ;
76+ expect ( OutputTitle ) . toHaveBeenCalledWith ( 'TestProject' ) ;
77+ expect ( OutputNameFilePDF ) . toHaveBeenCalledWith ( 'TestProject' ) ;
78+ expect ( WritePDF ) . toHaveBeenCalledWith ( 'Test Project Documentation' , 'TestProject.pdf' , filesParsed ) ;
79+ expect ( OutputTitleMarkdown ) . toHaveBeenCalledWith ( 'TestProject' ) ;
80+ expect ( OutputNameFileMarkdown ) . toHaveBeenCalledWith ( 'TestProject' ) ;
81+ expect ( WriteMarkdown ) . toHaveBeenCalledWith ( 'Test Project Documentation' , 'TestProject.md' , filesParsed ) ;
82+ } ) ;
83+
84+ it ( 'should handle empty formats gracefully' , async ( ) => {
85+ const formData = {
86+ projectName : 'TestProject' ,
87+ formats : { }
88+ } ;
89+ const rows = [ ] ;
90+ const filesParsed = [ { name : 'file1' , functions : [ ] } ] ;
91+
92+ FileParsing . mockResolvedValue ( filesParsed ) ;
93+
94+ await DocumentationGenerator ( formData , rows ) ;
95+
96+ expect ( FileParsing ) . toHaveBeenCalledWith ( formData , rows ) ;
97+ expect ( OutputTitle ) . not . toHaveBeenCalled ( ) ;
98+ expect ( OutputNameFilePDF ) . not . toHaveBeenCalled ( ) ;
99+ expect ( WritePDF ) . not . toHaveBeenCalled ( ) ;
100+ expect ( OutputTitleMarkdown ) . not . toHaveBeenCalled ( ) ;
101+ expect ( OutputNameFileMarkdown ) . not . toHaveBeenCalled ( ) ;
102+ expect ( WriteMarkdown ) . not . toHaveBeenCalled ( ) ;
103+ } ) ;
104+ } ) ;
0 commit comments