@@ -90,7 +90,58 @@ mod tests {
9090 . scripts ( vec ! [ "main.js" . to_owned( ) , "react.js" . to_owned( ) ] )
9191 . styles ( vec ! [ "style.css" . to_owned( ) ] ) ;
9292 let props = binding. build ( ) ;
93+ let html = HtmlBuilder :: new ( HtmlTemplate :: default ( ) , props)
94+ . generate ( )
95+ . to_string ( ) ;
96+
97+ assert ! ( html. contains( "<title>This is a static page</title>" ) ) ;
98+ assert ! ( html. contains( "<div id=\" root\" ></div>" ) ) ;
99+ assert ! ( html. contains( "<script src=\" main.js\" >" ) ) ;
100+ assert ! ( html. contains( "<script src=\" react.js\" >" ) ) ;
101+ assert ! ( html. contains( "<link rel=\" stylesheet\" href=\" style.css\" >" ) ) ;
102+ assert ! ( html. contains( "lang=\" en\" " ) ) ;
103+ }
104+
105+ #[ test]
106+ fn generating_html_without_scripts_or_styles ( ) {
107+ // This previously panicked before the fix in HtmlPropsBuilder::build()
108+ let props = HtmlPropsBuilder :: new ( )
109+ . lang ( "en" )
110+ . body ( "<div id=\" root\" ></div>" )
111+ . head ( "<title>Test</title>" )
112+ . build ( ) ;
93113 let html = HtmlBuilder :: new ( HtmlTemplate :: default ( ) , props) . generate ( ) ;
94- println ! ( "{html:?}" )
114+ let output = html. to_string ( ) ;
115+ assert ! ( output. contains( "<title>Test</title>" ) ) ;
116+ assert ! ( output. contains( "<div id=\" root\" ></div>" ) ) ;
117+ assert ! ( !output. contains( "<script" ) ) ; // no scripts injected
118+ assert ! ( !output. contains( "<link rel=\" stylesheet\" " ) ) ; // no styles injected
119+ }
120+
121+ #[ test]
122+ fn generating_html_contains_correct_script_tags ( ) {
123+ let props = HtmlPropsBuilder :: new ( )
124+ . scripts ( vec ! [ "app.js" . to_owned( ) ] )
125+ . styles ( vec ! [ "style.css" . to_owned( ) ] )
126+ . build ( ) ;
127+ let html = HtmlBuilder :: new ( HtmlTemplate :: default ( ) , props)
128+ . generate ( )
129+ . to_string ( ) ;
130+ assert ! ( html. contains( "<script src=\" app.js\" >" ) ) ;
131+ assert ! ( html. contains( "<link rel=\" stylesheet\" href=\" style.css\" >" ) ) ;
132+ }
133+
134+ #[ test]
135+ fn generating_html_with_empty_lang_defaults_gracefully ( ) {
136+ let props = HtmlPropsBuilder :: new ( ) . build ( ) ; // all defaults
137+ let html = HtmlBuilder :: new ( HtmlTemplate :: default ( ) , props)
138+ . generate ( )
139+ . to_string ( ) ;
140+ assert ! ( html. contains( "<html lang=\" \" >" ) ) ;
141+ assert ! ( !html. contains( "%LANG%" ) ) ;
142+ assert ! ( !html. contains( "%HEAD%" ) ) ;
143+ assert ! ( !html. contains( "%BODY%" ) ) ;
144+ assert ! ( !html. contains( "%SCRIPTS%" ) ) ;
145+ assert ! ( !html. contains( "%STYLES%" ) ) ;
95146 }
96147}
0 commit comments