@@ -21,6 +21,10 @@ class PlainReactOnRailsHelper
2121 { "HTTP_ACCEPT_LANGUAGE" => "en" }
2222 )
2323 }
24+
25+ allow ( ReactOnRails ::Utils ) . to receive_messages (
26+ react_on_rails_pro_licence_valid? : true
27+ )
2428 end
2529
2630 let ( :hash ) do
@@ -370,10 +374,137 @@ def helper.append_javascript_pack_tag(name, **options)
370374 it { is_expected . to include force_load_script }
371375 end
372376 end
377+
378+ describe "with Pro license warning" do
379+ let ( :badge_html_string ) { "React On Rails Pro Required" }
380+
381+ before do
382+ allow ( Rails . logger ) . to receive ( :warn )
383+ end
384+
385+ context "when Pro license is NOT installed and force_load is true" do
386+ subject ( :react_app ) { react_component ( "App" , props : props , force_load : true ) }
387+
388+ before do
389+ allow ( ReactOnRails ::Utils ) . to receive ( :react_on_rails_pro_licence_valid? ) . and_return ( false )
390+ end
391+
392+ it { is_expected . to include ( badge_html_string ) }
393+
394+ it "logs a warning" do
395+ react_app
396+ expect ( Rails . logger ) . to have_received ( :warn ) . with ( a_string_matching ( /The 'force_load' feature requires/ ) )
397+ end
398+ end
399+
400+ context "when Pro license is NOT installed and global force_load is true" do
401+ subject ( :react_app ) { react_component ( "App" , props : props ) }
402+
403+ before do
404+ allow ( ReactOnRails ::Utils ) . to receive ( :react_on_rails_pro_licence_valid? ) . and_return ( false )
405+ end
406+
407+ around do |example |
408+ ReactOnRails . configure { |config | config . force_load = true }
409+ example . run
410+ ReactOnRails . configure { |config | config . force_load = false }
411+ end
412+
413+ it { is_expected . to include ( badge_html_string ) }
414+ end
415+
416+ context "when Pro license is NOT installed and force_load is false" do
417+ subject ( :react_app ) { react_component ( "App" , props : props , force_load : false ) }
418+
419+ before do
420+ allow ( ReactOnRails ::Utils ) . to receive ( :react_on_rails_pro_licence_valid? ) . and_return ( false )
421+ end
422+
423+ it { is_expected . not_to include ( badge_html_string ) }
424+
425+ it "does not log a warning" do
426+ react_app
427+ expect ( Rails . logger ) . not_to have_received ( :warn )
428+ end
429+ end
430+
431+ context "when Pro license IS installed and force_load is true" do
432+ subject ( :react_app ) { react_component ( "App" , props : props , force_load : true ) }
433+
434+ before do
435+ allow ( ReactOnRails ::Utils ) . to receive_messages (
436+ react_on_rails_pro_licence_valid? : true
437+ )
438+ end
439+
440+ it { is_expected . not_to include ( badge_html_string ) }
441+
442+ it "does not log a warning" do
443+ react_app
444+ expect ( Rails . logger ) . not_to have_received ( :warn )
445+ end
446+ end
447+ end
448+ end
449+
450+ describe "#react_component_hash" do
451+ subject ( :react_app ) { react_component_hash ( "App" , props : props ) }
452+
453+ let ( :props ) { { name : "My Test Name" } }
454+
455+ before do
456+ allow ( SecureRandom ) . to receive ( :uuid ) . and_return ( 0 )
457+ allow ( ReactOnRails ::ServerRenderingPool ) . to receive ( :server_render_js_with_console_logging ) . and_return (
458+ "html" => { "componentHtml" => "<div>Test</div>" , "title" => "Test Title" } ,
459+ "consoleReplayScript" => ""
460+ )
461+ allow ( ReactOnRails ::ServerRenderingJsCode ) . to receive ( :js_code_renderer )
462+ . and_return ( ReactOnRails ::ServerRenderingJsCode )
463+ end
464+
465+ it "returns a hash with component and other keys" do
466+ expect ( react_app ) . to be_a ( Hash )
467+ expect ( react_app ) . to have_key ( "componentHtml" )
468+ expect ( react_app ) . to have_key ( "title" )
469+ end
470+
471+ context "with Pro license warning" do
472+ let ( :badge_html_string ) { "React On Rails Pro Required" }
473+
474+ before do
475+ allow ( Rails . logger ) . to receive ( :warn )
476+ end
477+
478+ context "when Pro license is NOT installed and force_load is true" do
479+ subject ( :react_app ) { react_component_hash ( "App" , props : props , force_load : true ) }
480+
481+ before do
482+ allow ( ReactOnRails ::Utils ) . to receive ( :react_on_rails_pro_licence_valid? ) . and_return ( false )
483+ end
484+
485+ it "adds badge to componentHtml" do
486+ expect ( react_app [ "componentHtml" ] ) . to include ( badge_html_string )
487+ end
488+ end
489+
490+ context "when Pro license IS installed and force_load is true" do
491+ subject ( :react_app ) { react_component_hash ( "App" , props : props , force_load : true ) }
492+
493+ before do
494+ allow ( ReactOnRails ::Utils ) . to receive_messages (
495+ react_on_rails_pro_licence_valid? : true
496+ )
497+ end
498+
499+ it "does not add badge to componentHtml" do
500+ expect ( react_app [ "componentHtml" ] ) . not_to include ( badge_html_string )
501+ end
502+ end
503+ end
373504 end
374505
375506 describe "#redux_store" do
376- subject ( :store ) { redux_store ( "reduxStore" , props : props ) }
507+ subject ( :store ) { redux_store ( "reduxStore" , props : props , force_load : true ) }
377508
378509 let ( :props ) do
379510 { name : "My Test Name" }
@@ -394,6 +525,51 @@ def helper.append_javascript_pack_tag(name, **options)
394525 it {
395526 expect ( expect ( store ) . target ) . to script_tag_be_included ( react_store_script )
396527 }
528+
529+ context "with Pro license warning" do
530+ let ( :badge_html_string ) { "React On Rails Pro Required" }
531+
532+ before do
533+ allow ( Rails . logger ) . to receive ( :warn )
534+ end
535+
536+ context "when Pro license is NOT installed and force_load is true" do
537+ subject ( :store ) { redux_store ( "reduxStore" , props : props , force_load : true ) }
538+
539+ before do
540+ allow ( ReactOnRails ::Utils ) . to receive ( :react_on_rails_pro_licence_valid? ) . and_return ( false )
541+ end
542+
543+ it { is_expected . to include ( badge_html_string ) }
544+
545+ it "logs a warning" do
546+ store
547+ expect ( Rails . logger ) . to have_received ( :warn ) . with ( a_string_matching ( /The 'force_load' feature requires/ ) )
548+ end
549+ end
550+
551+ context "when Pro license is NOT installed and force_load is false" do
552+ subject ( :store ) { redux_store ( "reduxStore" , props : props , force_load : false ) }
553+
554+ before do
555+ allow ( ReactOnRails ::Utils ) . to receive ( :react_on_rails_pro_licence_valid? ) . and_return ( false )
556+ end
557+
558+ it { is_expected . not_to include ( badge_html_string ) }
559+ end
560+
561+ context "when Pro license IS installed and force_load is true" do
562+ subject ( :store ) { redux_store ( "reduxStore" , props : props , force_load : true ) }
563+
564+ before do
565+ allow ( ReactOnRails ::Utils ) . to receive_messages (
566+ react_on_rails_pro_licence_valid? : true
567+ )
568+ end
569+
570+ it { is_expected . not_to include ( badge_html_string ) }
571+ end
572+ end
397573 end
398574
399575 describe "#server_render_js" , :js , type : :system do
0 commit comments