-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Override ViewComponent::Base#sidecar_files instead of the compiler.
- Loading branch information
Showing
2 changed files
with
36 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Blacklight::Component do | ||
let(:component_class) { Blacklight::DocumentTitleComponent } | ||
RSpec.describe Blacklight::Component, type: :component do | ||
let(:component_class) { Blacklight::System::ModalComponent } | ||
|
||
context "subclassed" do | ||
it "returns our Compiler implementation" do | ||
expect(component_class.ancestors).to include described_class | ||
expect(component_class.compiler).to be_a Blacklight::Component::EngineCompiler | ||
before do | ||
ViewComponent::CompileCache.invalidate! | ||
|
||
component_class.class_eval do | ||
undef :call if method_defined?(:call) | ||
end | ||
end | ||
|
||
describe Blacklight::Component::EngineCompiler do | ||
subject(:compiler) { described_class.new(component_class) } | ||
|
||
let(:original_compiler) { ViewComponent::Compiler.new(component_class) } | ||
let(:original_path) { original_compiler.send(:templates).first[:path] } | ||
let(:resolved_path) { compiler.templates.first[:path] } | ||
|
||
context "without overrides" do | ||
it "links to engine template" do | ||
expect(resolved_path).not_to include(".internal_test_app") | ||
expect(resolved_path).to eql(original_path) | ||
end | ||
context "without overrides" do | ||
it "renders the engine template" do | ||
render_inline(component_class.new) | ||
expect(page).to have_css('.modal-header') | ||
end | ||
end | ||
|
||
context "with overrides" do | ||
let(:path_match) do | ||
Regexp.new(Regexp.escape(File.join(".internal_test_app", component_class.view_component_path))) | ||
context "with overrides" do | ||
around do |ex| | ||
FileUtils.mkdir_p(Rails.root.join('app/components/blacklight/system')) | ||
Rails.root.join("app/components/blacklight/system/modal_component.html.erb").open("w") do |f| | ||
f.puts '<div class="custom-modal">Overridden</div>' | ||
end | ||
|
||
before do | ||
allow(File).to receive(:exist?).and_call_original | ||
allow(File).to receive(:exist?).with(path_match).and_return(true) | ||
end | ||
ex.run | ||
ensure | ||
Rails.root.join('app/components/blacklight/system/modal_component.html.erb').unlink | ||
end | ||
|
||
it "links to application template" do | ||
expect(resolved_path).to include(".internal_test_app") | ||
expect(resolved_path).not_to eql(original_path) | ||
end | ||
it "renders to application template" do | ||
render_inline(component_class.new) | ||
expect(page).to have_css('.custom-modal') | ||
end | ||
end | ||
end |