@@ -674,5 +674,136 @@ def self.pro_attribution_comment; end
674674 end
675675 end
676676 end
677+
678+ describe "attribution comment inclusion in rendered output" do
679+ let ( :props ) { { name : "Test" } }
680+
681+ before do
682+ allow ( SecureRandom ) . to receive ( :uuid ) . and_return ( 0 )
683+ end
684+
685+ describe "#react_component" do
686+ context "when React on Rails Pro is installed" do
687+ before do
688+ allow ( ReactOnRails ::Utils ) . to receive ( :react_on_rails_pro? ) . and_return ( true )
689+ allow ( ReactOnRailsPro ::Utils ) . to receive ( :pro_attribution_comment )
690+ . and_return ( "<!-- Powered by React on Rails Pro (c) ShakaCode | Licensed -->" )
691+ end
692+
693+ it "includes the Pro attribution comment in the rendered output" do
694+ result = react_component ( "App" , props : props )
695+ expect ( result ) . to include ( "<!-- Powered by React on Rails Pro (c) ShakaCode | Licensed -->" )
696+ end
697+
698+ it "includes the attribution comment only once" do
699+ result = react_component ( "App" , props : props )
700+ comment_count = result . scan ( "<!-- Powered by React on Rails Pro" ) . length
701+ expect ( comment_count ) . to eq ( 1 )
702+ end
703+ end
704+
705+ context "when React on Rails Pro is NOT installed" do
706+ before do
707+ allow ( ReactOnRails ::Utils ) . to receive ( :react_on_rails_pro? ) . and_return ( false )
708+ end
709+
710+ it "includes the open source attribution comment in the rendered output" do
711+ result = react_component ( "App" , props : props )
712+ expect ( result ) . to include ( "<!-- Powered by React on Rails (c) ShakaCode | Open Source -->" )
713+ end
714+
715+ it "includes the attribution comment only once" do
716+ result = react_component ( "App" , props : props )
717+ comment_count = result . scan ( "<!-- Powered by React on Rails" ) . length
718+ expect ( comment_count ) . to eq ( 1 )
719+ end
720+ end
721+ end
722+
723+ describe "#redux_store" do
724+ context "when React on Rails Pro is installed" do
725+ before do
726+ allow ( ReactOnRails ::Utils ) . to receive ( :react_on_rails_pro? ) . and_return ( true )
727+ allow ( ReactOnRailsPro ::Utils ) . to receive ( :pro_attribution_comment )
728+ . and_return ( "<!-- Powered by React on Rails Pro (c) ShakaCode | Licensed -->" )
729+ end
730+
731+ it "includes the Pro attribution comment in the rendered output" do
732+ result = redux_store ( "TestStore" , props : props )
733+ expect ( result ) . to include ( "<!-- Powered by React on Rails Pro (c) ShakaCode | Licensed -->" )
734+ end
735+
736+ it "includes the attribution comment only once" do
737+ result = redux_store ( "TestStore" , props : props )
738+ comment_count = result . scan ( "<!-- Powered by React on Rails Pro" ) . length
739+ expect ( comment_count ) . to eq ( 1 )
740+ end
741+ end
742+
743+ context "when React on Rails Pro is NOT installed" do
744+ before do
745+ allow ( ReactOnRails ::Utils ) . to receive ( :react_on_rails_pro? ) . and_return ( false )
746+ end
747+
748+ it "includes the open source attribution comment in the rendered output" do
749+ result = redux_store ( "TestStore" , props : props )
750+ expect ( result ) . to include ( "<!-- Powered by React on Rails (c) ShakaCode | Open Source -->" )
751+ end
752+
753+ it "includes the attribution comment only once" do
754+ result = redux_store ( "TestStore" , props : props )
755+ comment_count = result . scan ( "<!-- Powered by React on Rails" ) . length
756+ expect ( comment_count ) . to eq ( 1 )
757+ end
758+ end
759+ end
760+
761+ describe "#react_component_hash" do
762+ before do
763+ allow ( ReactOnRails ::ServerRenderingPool ) . to receive ( :server_render_js_with_console_logging ) . and_return (
764+ "html" => { "componentHtml" => "<div>Test</div>" , "title" => "Test Title" } ,
765+ "consoleReplayScript" => ""
766+ )
767+ allow ( ReactOnRails ::ServerRenderingJsCode ) . to receive ( :js_code_renderer )
768+ . and_return ( ReactOnRails ::ServerRenderingJsCode )
769+ end
770+
771+ context "when React on Rails Pro is installed" do
772+ before do
773+ allow ( ReactOnRails ::Utils ) . to receive ( :react_on_rails_pro? ) . and_return ( true )
774+ allow ( ReactOnRailsPro ::Utils ) . to receive ( :pro_attribution_comment )
775+ . and_return ( "<!-- Powered by React on Rails Pro (c) ShakaCode | Licensed -->" )
776+ end
777+
778+ it "includes the Pro attribution comment in the componentHtml" do
779+ result = react_component_hash ( "App" , props : props , prerender : true )
780+ expect ( result [ "componentHtml" ] ) . to include ( "<!-- Powered by React on Rails Pro (c) ShakaCode | Licensed -->" )
781+ end
782+
783+ it "includes the attribution comment only once" do
784+ result = react_component_hash ( "App" , props : props , prerender : true )
785+ comment_count = result [ "componentHtml" ] . scan ( "<!-- Powered by React on Rails Pro" ) . length
786+ expect ( comment_count ) . to eq ( 1 )
787+ end
788+ end
789+
790+ context "when React on Rails Pro is NOT installed" do
791+ before do
792+ allow ( ReactOnRails ::Utils ) . to receive ( :react_on_rails_pro? ) . and_return ( false )
793+ end
794+
795+ it "includes the open source attribution comment in the componentHtml" do
796+ result = react_component_hash ( "App" , props : props , prerender : true )
797+ expect ( result [ "componentHtml" ] ) . to include ( "<!-- Powered by React on Rails (c) ShakaCode | Open Source -->" )
798+ end
799+
800+ it "includes the attribution comment only once" do
801+ result = react_component_hash ( "App" , props : props , prerender : true )
802+ comment_count = result [ "componentHtml" ] . scan ( "<!-- Powered by React on Rails" ) . length
803+ expect ( comment_count ) . to eq ( 1 )
804+ end
805+ end
806+ end
807+ end
677808end
678809# rubocop:enable Metrics/BlockLength
0 commit comments