diff --git a/app/components/embed/media/embed_this_form_component.html.erb b/app/components/embed/media/embed_this_form_component.html.erb new file mode 100644 index 000000000..cbd2b3c8c --- /dev/null +++ b/app/components/embed/media/embed_this_form_component.html.erb @@ -0,0 +1,42 @@ +
+
+ +
+ +
+
+ +
+ +
+ +
+

Select options:

+
+ + /> + +
+ <%= content %> +
+ + /> + +
+
+
diff --git a/app/components/embed/media/embed_this_form_component.rb b/app/components/embed/media/embed_this_form_component.rb new file mode 100644 index 000000000..1d126d935 --- /dev/null +++ b/app/components/embed/media/embed_this_form_component.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Embed + module Media + class EmbedThisFormComponent < ViewComponent::Base + def initialize(viewer:) + @viewer = viewer + end + + delegate :request, :purl_object, to: :viewer + delegate :title, to: :purl_object, prefix: true + delegate :purl_url, to: :purl_object + + attr_reader :viewer + end + end +end diff --git a/app/components/embed/media_with_companion_windows_component.html.erb b/app/components/embed/media_with_companion_windows_component.html.erb index 856ae7039..74e8b0cf1 100644 --- a/app/components/embed/media_with_companion_windows_component.html.erb +++ b/app/components/embed/media_with_companion_windows_component.html.erb @@ -122,7 +122,7 @@ Share - <%= render EmbedThisFormComponent.new(viewer:) %> + <%= render Embed::Media::EmbedThisFormComponent.new(viewer:) %>
diff --git a/app/components/embed_this_form_component.html.erb b/app/components/embed_this_form_component.html.erb index cbd2b3c8c..fe2e05524 100644 --- a/app/components/embed_this_form_component.html.erb +++ b/app/components/embed_this_form_component.html.erb @@ -1,42 +1,33 @@
-
- -
- -
-
- -
- -
- -
-

Select options:

-
- Select options: +
+ - /> - + /> + +
+ <%= content %> +
+ + /> + +
+
+
+
- <%= content %>
- - /> - +
-
-
+ + \ No newline at end of file diff --git a/spec/components/embed/media/embed_this_form_component_spec.rb b/spec/components/embed/media/embed_this_form_component_spec.rb new file mode 100644 index 000000000..92b8aa515 --- /dev/null +++ b/spec/components/embed/media/embed_this_form_component_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Embed::Media::EmbedThisFormComponent, type: :component do + let(:request) do + Embed::Request.new(url: 'http://purl.stanford.edu/abc123') + end + let(:object) do + instance_double(Embed::Purl, title: '', druid: '', all_resource_files: [], embargoed?: false, purl_url: 'https://stanford.edu/') + end + let(:viewer) { Embed::Viewer::File.new(request) } + + before do + allow(request).to receive(:purl_object).and_return(object) + end + + context 'without any content' do + before do + render_inline(described_class.new(viewer:)) + end + + it 'has the form elements for updating the embed code' do + expect(page.find('.sul-embed-options-label#select-options')).to have_content('Select options:') + expect(page).to have_css('input#sul-embed-embed-title[type="checkbox"]') + expect(page).to have_css('input#sul-embed-embed[type="checkbox"]') + expect(page).to have_css('textarea#sul-embed-iframe-code') + end + end + + context 'with content' do + before do + with_controller_class EmbedController do + render_inline(described_class.new(viewer:)) do + vc_test_controller.helpers.tag :input, type: 'checkbox', id: 'sul-embed-embed-search' + end + end + end + + it 'has the form elements for updating the embed code' do + expect(page.find('.sul-embed-options-label#select-options')).to have_content('Select options:') + expect(page).to have_css('input#sul-embed-embed-title[type="checkbox"]') + expect(page).to have_css('input#sul-embed-embed-search[type="checkbox"]') + expect(page).to have_css('input#sul-embed-embed[type="checkbox"]') + expect(page).to have_css('textarea#sul-embed-iframe-code') + end + end +end diff --git a/spec/components/embed_this_form_component_spec.rb b/spec/components/embed_this_form_component_spec.rb index 07ac1fe05..7a2368d00 100644 --- a/spec/components/embed_this_form_component_spec.rb +++ b/spec/components/embed_this_form_component_spec.rb @@ -6,9 +6,7 @@ let(:request) do Embed::Request.new(url: 'http://purl.stanford.edu/abc123') end - let(:object) do - instance_double(Embed::Purl, title: '', druid: '', all_resource_files: [], embargoed?: false, purl_url: 'https://stanford.edu/') - end + let(:object) { instance_double(Embed::Purl, title: '', druid: '', all_resource_files: [], embargoed?: false) } let(:viewer) { Embed::Viewer::File.new(request) } before do