-
-
- <% if content_for? :masthead %>
- <%= content_for :masthead %>
- <% else %>
- <%= masthead_heading_content %>
- <% end %>
-
-
- <% if masthead_subheading_content %>
- <%= masthead_subheading_content %>
- <% end %>
-
-
+ <%= render MastheadTitleComponent.new(title: content_for(:masthead) || masthead_heading_content, subtitle: masthead_subheading_content) %>
+
diff --git a/spec/components/masthead_title_component_spec.rb b/spec/components/masthead_title_component_spec.rb
new file mode 100644
index 000000000..1ef52047c
--- /dev/null
+++ b/spec/components/masthead_title_component_spec.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe MastheadTitleComponent, type: :component do
+ subject(:rendered) do
+ Capybara::Node::Simple.new(render_inline(described_class.new(title: 'Exhibit Title',
+ subtitle: 'Exhibit Subtitle')).to_s)
+ end
+
+ context 'when there is no current exhibit' do
+ it { expect(rendered).to have_link('Exhibit Title', href: '/') }
+ it { expect(rendered).to have_link('Exhibit Subtitle', href: '/') }
+ end
+
+ context 'when there is a current exhibit' do
+ before do
+ allow(vc_test_controller).to receive(:current_exhibit)
+ .and_return(create(:exhibit, slug: 'exhibit-slug'))
+ end
+
+ it { expect(rendered).to have_link('Exhibit Title', href: '/exhibit-slug') }
+ it { expect(rendered).to have_link('Exhibit Subtitle', href: '/exhibit-slug') }
+ end
+end