Skip to content

Commit 8a639dc

Browse files
Add Pro license warning tests for react_component and redux_store helpers
1 parent 2ee4c78 commit 8a639dc

File tree

1 file changed

+182
-1
lines changed

1 file changed

+182
-1
lines changed

spec/dummy/spec/helpers/react_on_rails_helper_spec.rb

Lines changed: 182 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ class PlainReactOnRailsHelper
2121
{ "HTTP_ACCEPT_LANGUAGE" => "en" }
2222
)
2323
}
24+
25+
allow(ReactOnRails::Utils).to receive_messages(
26+
react_on_rails_pro?: true,
27+
react_on_rails_pro_version: "4.0.0",
28+
rsc_support_enabled?: false
29+
)
2430
end
2531

2632
let(:hash) do
@@ -370,10 +376,139 @@ def helper.append_javascript_pack_tag(name, **options)
370376
it { is_expected.to include force_load_script }
371377
end
372378
end
379+
380+
describe "with Pro license warning" do
381+
let(:badge_html_string) { "React On Rails Pro Required" }
382+
383+
before do
384+
allow(Rails.logger).to receive(:warn)
385+
end
386+
387+
context "when Pro license is NOT installed and force_load is true" do
388+
subject(:react_app) { react_component("App", props: props, force_load: true) }
389+
390+
before do
391+
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro?).and_return(false)
392+
end
393+
394+
it { is_expected.to include(badge_html_string) }
395+
396+
it "logs a warning" do
397+
react_app
398+
expect(Rails.logger).to have_received(:warn).with(a_string_matching(/The 'force_load' feature requires/))
399+
end
400+
end
401+
402+
context "when Pro license is NOT installed and global force_load is true" do
403+
subject(:react_app) { react_component("App", props: props) }
404+
405+
before do
406+
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro?).and_return(false)
407+
end
408+
409+
around do |example|
410+
ReactOnRails.configure { |config| config.force_load = true }
411+
example.run
412+
ReactOnRails.configure { |config| config.force_load = false }
413+
end
414+
415+
it { is_expected.to include(badge_html_string) }
416+
end
417+
418+
context "when Pro license is NOT installed and force_load is false" do
419+
subject(:react_app) { react_component("App", props: props, force_load: false) }
420+
421+
before do
422+
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro?).and_return(false)
423+
end
424+
425+
it { is_expected.not_to include(badge_html_string) }
426+
427+
it "does not log a warning" do
428+
react_app
429+
expect(Rails.logger).not_to have_received(:warn)
430+
end
431+
end
432+
433+
context "when Pro license IS installed and force_load is true" do
434+
subject(:react_app) { react_component("App", props: props, force_load: true) }
435+
436+
before do
437+
allow(ReactOnRails::Utils).to receive_messages(
438+
react_on_rails_pro?: true,
439+
react_on_rails_pro_version: "4.0.0"
440+
)
441+
end
442+
443+
it { is_expected.not_to include(badge_html_string) }
444+
445+
it "does not log a warning" do
446+
react_app
447+
expect(Rails.logger).not_to have_received(:warn)
448+
end
449+
end
450+
end
451+
end
452+
453+
describe "#react_component_hash" do
454+
subject(:react_app) { react_component_hash("App", props: props) }
455+
456+
let(:props) { { name: "My Test Name" } }
457+
458+
before do
459+
allow(SecureRandom).to receive(:uuid).and_return(0)
460+
allow(ReactOnRails::ServerRenderingPool).to receive(:server_render_js_with_console_logging).and_return(
461+
"html" => { "componentHtml" => "<div>Test</div>", "title" => "Test Title" },
462+
"consoleReplayScript" => ""
463+
)
464+
allow(ReactOnRails::ServerRenderingJsCode).to receive(:js_code_renderer)
465+
.and_return(ReactOnRails::ServerRenderingJsCode)
466+
end
467+
468+
it "returns a hash with component and other keys" do
469+
expect(react_app).to be_a(Hash)
470+
expect(react_app).to have_key("componentHtml")
471+
expect(react_app).to have_key("title")
472+
end
473+
474+
context "with Pro license warning" do
475+
let(:badge_html_string) { "React On Rails Pro Required" }
476+
477+
before do
478+
allow(Rails.logger).to receive(:warn)
479+
end
480+
481+
context "when Pro license is NOT installed and force_load is true" do
482+
subject(:react_app) { react_component_hash("App", props: props, force_load: true) }
483+
484+
before do
485+
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro?).and_return(false)
486+
end
487+
488+
it "adds badge to componentHtml" do
489+
expect(react_app["componentHtml"]).to include(badge_html_string)
490+
end
491+
end
492+
493+
context "when Pro license IS installed and force_load is true" do
494+
subject(:react_app) { react_component_hash("App", props: props, force_load: true) }
495+
496+
before do
497+
allow(ReactOnRails::Utils).to receive_messages(
498+
react_on_rails_pro?: true,
499+
react_on_rails_pro_version: "4.0.0"
500+
)
501+
end
502+
503+
it "does not add badge to componentHtml" do
504+
expect(react_app["componentHtml"]).not_to include(badge_html_string)
505+
end
506+
end
507+
end
373508
end
374509

375510
describe "#redux_store" do
376-
subject(:store) { redux_store("reduxStore", props: props) }
511+
subject(:store) { redux_store("reduxStore", props: props, force_load: true) }
377512

378513
let(:props) do
379514
{ name: "My Test Name" }
@@ -394,6 +529,52 @@ def helper.append_javascript_pack_tag(name, **options)
394529
it {
395530
expect(expect(store).target).to script_tag_be_included(react_store_script)
396531
}
532+
533+
context "with Pro license warning" do
534+
let(:badge_html_string) { "React On Rails Pro Required" }
535+
536+
before do
537+
allow(Rails.logger).to receive(:warn)
538+
end
539+
540+
context "when Pro license is NOT installed and force_load is true" do
541+
subject(:store) { redux_store("reduxStore", props: props, force_load: true) }
542+
543+
before do
544+
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro?).and_return(false)
545+
end
546+
547+
it { is_expected.to include(badge_html_string) }
548+
549+
it "logs a warning" do
550+
store
551+
expect(Rails.logger).to have_received(:warn).with(a_string_matching(/The 'force_load' feature requires/))
552+
end
553+
end
554+
555+
context "when Pro license is NOT installed and force_load is false" do
556+
subject(:store) { redux_store("reduxStore", props: props, force_load: false) }
557+
558+
before do
559+
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro?).and_return(false)
560+
end
561+
562+
it { is_expected.not_to include(badge_html_string) }
563+
end
564+
565+
context "when Pro license IS installed and force_load is true" do
566+
subject(:store) { redux_store("reduxStore", props: props, force_load: true) }
567+
568+
before do
569+
allow(ReactOnRails::Utils).to receive_messages(
570+
react_on_rails_pro?: true,
571+
react_on_rails_pro_version: "4.0.0"
572+
)
573+
end
574+
575+
it { is_expected.not_to include(badge_html_string) }
576+
end
577+
end
397578
end
398579

399580
describe "#server_render_js", :js, type: :system do

0 commit comments

Comments
 (0)