diff --git a/admin/app/components/solidus_admin/ui/forms/fieldset/component.erb b/admin/app/components/solidus_admin/ui/forms/fieldset/component.erb deleted file mode 100644 index 7b05c129a8f..00000000000 --- a/admin/app/components/solidus_admin/ui/forms/fieldset/component.erb +++ /dev/null @@ -1,4 +0,0 @@ -<%= tag.fieldset(**fieldset_html_attributes) do %> - <%= legend_and_toggletip_tags %> - <%= content %> -<% end %> diff --git a/admin/app/components/solidus_admin/ui/forms/fieldset/component.rb b/admin/app/components/solidus_admin/ui/forms/fieldset/component.rb deleted file mode 100644 index 17a32b6710a..00000000000 --- a/admin/app/components/solidus_admin/ui/forms/fieldset/component.rb +++ /dev/null @@ -1,64 +0,0 @@ -# frozen_string_literal: true - -class SolidusAdmin::UI::Forms::Fieldset::Component < SolidusAdmin::BaseComponent - # @param legend [String, nil] The legend of the fieldset. - # @param fieldset_attributes [Hash] Attributes to pass to the fieldset tag. - # @param legend_attributes [Hash, nil] Attributes to pass to the legend tag. - # @param toggletip_attributes [Hash, nil] Attributes to pass to a toggletip - # component that will be rendered after the legend. - def initialize( - legend: nil, - attributes: {}, - legend_attributes: {}, - toggletip_attributes: {} - ) - @legend = legend - @attributes = attributes - @legend_attributes = legend_attributes - @toggletip_attributes = toggletip_attributes - end - - def fieldset_html_attributes - { - class: fieldset_classes, - **@attributes.except(:class) - } - end - - def fieldset_classes - %w[p-6 mb-6 border border-gray-100 rounded-lg] + Array(@attributes[:class]).compact - end - - def legend_and_toggletip_tags - return "" unless @legend || @toggletip_attributes.any? - - tag.div(class: "flex mb-4") do - legend_tag + toggletip_tag - end - end - - def legend_tag - return "".html_safe unless @legend - - tag.legend(@legend, **legend_html_attributes) - end - - def legend_html_attributes - { - class: legend_classes, - **@legend_attributes.except(:class) - } - end - - def legend_classes - %w[body-title mr-2] + Array(@legend_attributes[:class]).compact - end - - def toggletip_tag - return "" unless @toggletip_attributes.any? - - tag.div do - render component("ui/toggletip").new(**@toggletip_attributes) - end - end -end diff --git a/admin/app/components/solidus_admin/ui/forms/form/component.erb b/admin/app/components/solidus_admin/ui/forms/form/component.erb deleted file mode 100644 index 7ea4458e700..00000000000 --- a/admin/app/components/solidus_admin/ui/forms/form/component.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= form_with(**@attributes) do |builder| %> - <%= render_elements(@elements, builder) %> -<% end %> diff --git a/admin/app/components/solidus_admin/ui/forms/form/component.rb b/admin/app/components/solidus_admin/ui/forms/form/component.rb deleted file mode 100644 index ca5e2b51742..00000000000 --- a/admin/app/components/solidus_admin/ui/forms/form/component.rb +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -class SolidusAdmin::UI::Forms::Form::Component < SolidusAdmin::BaseComponent - # @param elements [Array<#call(form, builder)>] Builders of renderable - # elements within a form context. They need to implement `#call(form, - # builder)`, where the arguments are an instance of this class and an - # instance of `ActionView::Helpers::FormBuilder`. The method needs to return - # something responding to `#render_in(view_context)`. See the following - # classes for examples: - # - {SolidusAdmin::Form::Elements::Field} - # - {SolidusAdmin::Form::Elements::Fieldset} - # - {SolidusAdmin::Form::Elements::Component} - # - {SolidusAdmin::Form::Elements::HTML} - # @param attributes [Hash] Attributes to pass to the Rails `form_with` helper, - # which is used to render the form. - def initialize(elements:, **attributes) - @elements = elements - @attributes = attributes - end - - # @return [Hash{Symbol => SolidusAdmin::BaseComponent}] Hash of component - # classes dependencies given on initialization. - def dependencies - { - fieldset: component("ui/forms/fieldset"), - text_field: component("ui/forms/text_field"), - text_area: component("ui/forms/text_area") - } - end - - # @api private - def render_elements(elements, builder) - safe_join( - elements.map do |element| - render_element(element, builder) - end - ) - end - - # @api private - def render_element(element, builder) - render element.call(self, builder) - end -end diff --git a/admin/app/components/solidus_admin/ui/forms/guidance/component.rb b/admin/app/components/solidus_admin/ui/forms/guidance/component.rb deleted file mode 100644 index 67d88cb189a..00000000000 --- a/admin/app/components/solidus_admin/ui/forms/guidance/component.rb +++ /dev/null @@ -1,70 +0,0 @@ -# frozen_string_literal: true - -# @api private -class SolidusAdmin::UI::Forms::Guidance::Component < SolidusAdmin::BaseComponent - def initialize(field:, builder:, hint:, errors:, disabled: false) - @field = field - @builder = builder - @hint = hint - @disabled = disabled - @errors = errors || @builder.object&.errors || raise(ArgumentError, <<~MSG - When the form builder is not bound to a model instance, you must pass an - errors Hash (`{ field_name: [errors] }`) to the component. - MSG - ) - end - - def call - return "" unless needed? - - tag.div(class: "mt-2") do - hint_tag + error_tag - end - end - - def hint_tag - return "".html_safe unless @hint - - tag.p(id: hint_id, class: "body-tiny #{hint_text_color_class}") do - @hint - end - end - - def hint_text_color_class - @disabled ? "text-gray-300" : "text-gray-500" - end - - def hint_id - "#{prefix}_hint" - end - - def error_tag - return "".html_safe unless errors? - - tag.p(id: error_id, class: "body-tiny text-red-400") do - @errors[@field].map do |error| - tag.span(class: "block") { error.capitalize } - end.reduce(&:+) - end - end - - def errors? - @errors[@field].present? - end - - def error_id - "#{prefix}_error" - end - - def prefix - "#{@builder.object_name}_#{@field}" - end - - def aria_describedby - "#{hint_id if @hint} #{error_id if errors?}" - end - - def needed? - @hint || errors? - end -end diff --git a/admin/app/components/solidus_admin/ui/forms/label/component.rb b/admin/app/components/solidus_admin/ui/forms/label/component.rb deleted file mode 100644 index 072042cc811..00000000000 --- a/admin/app/components/solidus_admin/ui/forms/label/component.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -# @api private -class SolidusAdmin::UI::Forms::Label::Component < SolidusAdmin::BaseComponent - def initialize(field:, builder:) - @field = field - @builder = builder - end - - def call - @builder.label(@field, class: "block mb-0.5 body-tiny-bold") - end -end diff --git a/admin/lib/solidus_admin/form/element/component.rb b/admin/lib/solidus_admin/form/element/component.rb deleted file mode 100644 index c46751808ab..00000000000 --- a/admin/lib/solidus_admin/form/element/component.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -module SolidusAdmin - module Form - module Element - # Builds an arbitrary component in a form context. - # - # This class can be used to render an arbitrary components in a form. - # - # This is useful when there's the need to render a component that's not - # strictly related to a form definition, but still needs to be within the - # form tags. - class Component - # @param component [ViewComponent::Base] the component instance to - # render. - def initialize(component:) - @component = component - end - - # @api private - def call(_form, _builder) - @component - end - end - end - end -end diff --git a/admin/lib/solidus_admin/form/element/field.rb b/admin/lib/solidus_admin/form/element/field.rb deleted file mode 100644 index 9b54f22679e..00000000000 --- a/admin/lib/solidus_admin/form/element/field.rb +++ /dev/null @@ -1,45 +0,0 @@ -# frozen_string_literal: true - -module SolidusAdmin - module Form - module Element - # Builds a form field component. - # - # This class encapsulates a form field definition and its resolution to a - # component. - class Field - # @param component [Symbol, ViewComponent::Base] the component to be - # used when rendering. It can be a component class (which needs to - # accept the `builder:` parameter on initialization) or a Symbol. When - # the latter, it's used to infer the one configured in the form - # instance. For instance, for a `:text_field` type, the component used - # will be the one given to the form component as the - # `text_field_component` keyword argument on initialization. - # @param attributes [Hash] attributes to pass to the field component. - def initialize(component:, **attributes) - @component = component - @attributes = attributes - end - - # @api private - def call(form, builder) - component_class(form).new( - builder: builder, - **@attributes - ) - end - - private - - def component_class(form) - case @component - when Symbol - form.dependencies[@component] - else - @component - end - end - end - end - end -end diff --git a/admin/lib/solidus_admin/form/element/fieldset.rb b/admin/lib/solidus_admin/form/element/fieldset.rb deleted file mode 100644 index 08f01e4674d..00000000000 --- a/admin/lib/solidus_admin/form/element/fieldset.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -module SolidusAdmin - module Form - module Element - # Builds a form fieldset component. - # - # This class encapsulates a form fieldset definition and its resolution to - # a component. - class Fieldset - # @param elements [Array<#call(form, builder)>] See - # {SolidusAdmin::UI::Forms::Form::Component#initialize}. - # @param component [ViewComponent::Base, nil] the component to be - # used when rendering. When `nil`, the component configured in the form - # `fieldset_component` keyword argument on initialization is used. - # @param attributes [Hash] Attributes to pass to the fieldset - # component. - def initialize(elements:, component: nil, **attributes) - @elements = elements - @component = component - @attributes = attributes - end - - # @api private - def call(form, builder) - component_class(form).new( - **@attributes - ).with_content( - render_elements(form, builder) - ) - end - - private - - def component_class(form) - @component || form.dependencies[:fieldset] - end - - def render_elements(form, builder) - return "" if @elements.empty? - - form.render_elements(@elements, builder) - end - end - end - end -end diff --git a/admin/lib/solidus_admin/form/element/html.rb b/admin/lib/solidus_admin/form/element/html.rb deleted file mode 100644 index e9c681507b2..00000000000 --- a/admin/lib/solidus_admin/form/element/html.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -module SolidusAdmin - module Form - module Element - # Builds arbitrary HTML in a form. - # - # This class can be used to render arbitrary content in a form. - # - # This is useful when there's the need to render content that's not - # strictly related to a form definition, but still needs to be within the - # form tags. If the content is a component, it's better to use - # {SolidusAdmin::Form::Element::Component} instead. - class HTML - # @param html [String] the HTML to render. - def initialize(html:) - @html = html - end - - # @api private - def call(_form, _builder) - self - end - - # @api private - def render_in(_view_context) - @html - end - end - end - end -end diff --git a/admin/spec/components/previews/solidus_admin/ui/forms/fieldset/component_preview.rb b/admin/spec/components/previews/solidus_admin/ui/forms/fieldset/component_preview.rb deleted file mode 100644 index 98ba84cb3f7..00000000000 --- a/admin/spec/components/previews/solidus_admin/ui/forms/fieldset/component_preview.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -# @component "ui/forms/fieldset" -class SolidusAdmin::UI::Forms::Fieldset::ComponentPreview < ViewComponent::Preview - include SolidusAdmin::Preview - - # The fieldset component is used to render a set of fields in a form. - # - # Most commonly, it'll be used indirectly through the definition given to a - # [form component](../form/overview). - # - # For standalone usage, it wraps the yielded content in a fieldset tag: - # - # ```erb - # <%= render components('ui/forms/fieldset').new do %> - # <%= # ... %> - # <% end %> - # ``` - # - # The legend of the fieldset can be set with the `legend` option: - # - # ```erb - # <%= render components('ui/forms/fieldset').new( - # legend: "My fieldset" - # ) do %> - # <%= # ... %> - # <% end %> - # ``` - # - # Lastly, a toggletip can be added to the legend with the - # `toggletip_attributes`, which will be passed to the [toggletip - # component](../../toggletip): - # - # ```erb - # <%= render components('ui/forms/fieldset').new( - # legend: "My fieldset", - # toggletip_attributes: { - # text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", - # position: :right - # } - # ) do %> - # <%= # ... %> - # <% end %> - # ``` - def overview - end -end diff --git a/admin/spec/components/previews/solidus_admin/ui/forms/fieldset/component_preview/overview.html.erb b/admin/spec/components/previews/solidus_admin/ui/forms/fieldset/component_preview/overview.html.erb deleted file mode 100644 index 8376955d631..00000000000 --- a/admin/spec/components/previews/solidus_admin/ui/forms/fieldset/component_preview/overview.html.erb +++ /dev/null @@ -1,48 +0,0 @@ -<%= form_with(url: "#", scope: :overview, method: :get, class: "w-full") do |form| %> -
-
- <%= render current_component.new do %> - <%= - render component('ui/forms/text_field').new( - field: :name, - builder: form, - errors: {} - ) - %> - <% end %> -
-
- <%= render current_component.new(legend: "Legend") do %> - <%= - render component('ui/forms/text_field').new( - field: :name, - builder: form, - errors: {} - ) - %> - <% end %> -
-
- <%= render current_component.new(toggletip_attributes: { text: "Lorem ipsum dolor est." }) do %> - <%= - render component('ui/forms/text_field').new( - field: :name, - builder: form, - errors: {} - ) - %> - <% end %> -
-
- <%= render current_component.new(legend: "Legend & tip", toggletip_attributes: { text: "Lorem ipsum dolor est.", position: :left, theme: :dark }) do %> - <%= - render component('ui/forms/text_field').new( - field: :name, - builder: form, - errors: {} - ) - %> - <% end %> -
-
-<% end %> diff --git a/admin/spec/components/previews/solidus_admin/ui/forms/form/component_preview.rb b/admin/spec/components/previews/solidus_admin/ui/forms/form/component_preview.rb deleted file mode 100644 index 10786cf5a41..00000000000 --- a/admin/spec/components/previews/solidus_admin/ui/forms/form/component_preview.rb +++ /dev/null @@ -1,170 +0,0 @@ -# frozen_string_literal: true - -require "solidus_admin/form/element/field" -require "solidus_admin/form/element/fieldset" -require "solidus_admin/form/element/component" -require "solidus_admin/form/element/html" - -# @component "ui/forms/form" -class SolidusAdmin::UI::Forms::Form::ComponentPreview < ViewComponent::Preview - include SolidusAdmin::Preview - - # The form component is used to render a form tag along with its content, most - # commonly form fields. - # - # Internally, the - # [`form_with`](https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_with) - # Rails helper is used to render the form tag, and the component will dispatch - # given arguments to it. - # - # The definition of the form is provided from the outside through the - # `elements` parameter. This parameter is an array of builders of renderable - # elements, and Solidus Admin provides all the necessary ones to build a form - # following its UI: - # - # ## SolidusAdmin::Form::Element::Field - # - # This element renders a form field: - # - # ```erb - # <%= - # render components('ui/forms/form', - # model: Spree::Product.new, - # elements: [ - # SolidusAdmin::Form::Element::Field.new( - # component: :text_field, - # field: :name - # ) - # ] - # ) - # %> - # ``` - # - # The previous example will use the [`text_field` - # component](../text_field/overview), but you can use any of the available - # field component. - # - # ## SolidusAdmin::Form::Element::Fieldset - # - # Wraps a set of fields in a fieldset. - # - # You need to provide the inner fields akin to how it's done with the form - # component. [The fieldet component](../fieldset/overview) is used under the - # hood, and you can pass any of its attributes through the `attributes` - # parameter. - # - # ```erb - # <%= - # render components('ui/forms/form', - # model: Spree::Product.new, - # elements: [ - # SolidusAdmin::Form::Element::Fieldset.new( - # elements: [ - # SolidusAdmin::Form::Element::Field.new( - # component: :text_field, - # field: :name - # ) - # ], - # legend: "Product details", - # toggletip_attributes: { text: "Minimal info", position: :right } - # ) - # ] - # ) - # %> - # ``` - # - # ## SolidusAdmin::Form::Element::Component - # - # This element allows you to render any component inside the form. - # - # ```erb - # <%= - # render components('ui/forms/form', - # model: Spree::Product.new, - # elements: [ - # SolidusAdmin::Form::Element::Component.new( - # component: MyCustomComponent.new - # ) - # ] - # ) - # %> - # ``` - # - # ## SolidusAdmin::Form::Element::HTML - # - # This element allows you to render any HTML inside the form. - # - # ```erb - # <%= - # render components('ui/forms/form', - # model: Spree::Product.new, - # elements: [ - # SolidusAdmin::Form::Element::HTML.new( - # html: "

Whatever HTML you want

".html_safe - # ) - # ] - # ) - # %> - # ``` - def overview - render_with_template( - locals: { - elements: elements - } - ) - end - - private - - def elements - [ - field_element, - fieldset_element, - component_element, - html_element - ] - end - - def field_element - SolidusAdmin::Form::Element::Field.new( - component: :text_field, - field: :name, - placeholder: "SolidusAdmin::Form::Element::Field", - errors: {} - ) - end - - def fieldset_element - SolidusAdmin::Form::Element::Fieldset.new( - elements: [ - SolidusAdmin::Form::Element::Field.new( - component: :text_field, - field: :name, - placeholder: "SolidusAdmin::Form::Element::Field", - errors: {} - ) - ], - legend: "SolidusAdmin::Form::Element::Fieldset" - ) - end - - def component_element - SolidusAdmin::Form::Element::Component.new( - component: Class.new(SolidusAdmin::BaseComponent) do - def self.name - "MyCustomComponent" - end - - def call - tag.p(class: "body-text-bold mb-2 italic") { "SolidusAdmin::Form::Element::Component" } - end - end.new - ) - end - - def html_element - SolidusAdmin::Form::Element::HTML.new( - html: "

SolidusAdmin::Form::Element::HTML

".html_safe - ) - end -end diff --git a/admin/spec/components/previews/solidus_admin/ui/forms/form/component_preview/overview.html.erb b/admin/spec/components/previews/solidus_admin/ui/forms/form/component_preview/overview.html.erb deleted file mode 100644 index 40dee9a8220..00000000000 --- a/admin/spec/components/previews/solidus_admin/ui/forms/form/component_preview/overview.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -
- <%= - render current_component.new(url: "#", scope: :overview, method: :get, class: "m-auto", elements: elements) - %> -
diff --git a/admin/spec/components/solidus_admin/ui/forms/fieldset/component_spec.rb b/admin/spec/components/solidus_admin/ui/forms/fieldset/component_spec.rb deleted file mode 100644 index cfb51bf07e9..00000000000 --- a/admin/spec/components/solidus_admin/ui/forms/fieldset/component_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -RSpec.describe SolidusAdmin::UI::Forms::Fieldset::Component, type: :component do - it "renders the overview preview" do - render_preview(:overview) - end -end diff --git a/admin/spec/components/solidus_admin/ui/forms/form/component_spec.rb b/admin/spec/components/solidus_admin/ui/forms/form/component_spec.rb deleted file mode 100644 index 87d5382ba0c..00000000000 --- a/admin/spec/components/solidus_admin/ui/forms/form/component_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -RSpec.describe SolidusAdmin::UI::Forms::Form::Component, type: :component do - it "renders the overview preview" do - render_preview(:overview) - end -end diff --git a/admin/spec/components/solidus_admin/ui/forms/guidance/component_spec.rb b/admin/spec/components/solidus_admin/ui/forms/guidance/component_spec.rb deleted file mode 100644 index f5092e16c0d..00000000000 --- a/admin/spec/components/solidus_admin/ui/forms/guidance/component_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -RSpec.describe SolidusAdmin::UI::Forms::Guidance::Component, type: :component do - describe "#initialize" do - it "uses given errors when form is bound to a model" do - form = double("form", object: double("model", errors: {})) - - component = described_class.new(builder: form, field: :name, hint: nil, errors: { name: ["can't be blank"] }) - - expect(component.errors?).to be(true) - end - - it "uses model errors when form is bound to a model and they are not given" do - form = double("form", object: double("model", errors: { name: ["can't be blank"] })) - - component = described_class.new(builder: form, field: :name, hint: nil, errors: nil) - - expect(component.errors?).to be(true) - end - - it "uses given errors when form is not bound to a model" do - form = double("form", object: nil) - - component = described_class.new(builder: form, field: :name, hint: nil, errors: { name: ["can't be blank"] }) - - expect(component.errors?).to be(true) - end - - it "raises an error when form is not bound to a model and errors are not given" do - form = double("form", object: nil) - - expect { described_class.new(builder: form, field: :name, errors: nil) }.to raise_error(ArgumentError) - end - end -end diff --git a/admin/spec/solidus_admin/form/element/component_spec.rb b/admin/spec/solidus_admin/form/element/component_spec.rb deleted file mode 100644 index eda06035b50..00000000000 --- a/admin/spec/solidus_admin/form/element/component_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" -require "solidus_admin/form/element/component" - -RSpec.describe SolidusAdmin::Form::Element::Component do - describe "#call" do - it "returns the given instance component" do - element = described_class.new(component: :component) - - expect( - element.call(double("form"), double("builder")) - ).to be(:component) - end - end -end diff --git a/admin/spec/solidus_admin/form/element/field_spec.rb b/admin/spec/solidus_admin/form/element/field_spec.rb deleted file mode 100644 index 131ab0251cc..00000000000 --- a/admin/spec/solidus_admin/form/element/field_spec.rb +++ /dev/null @@ -1,71 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" -require "solidus_admin/form/element/field" - -RSpec.describe SolidusAdmin::Form::Element::Field do - include SolidusAdmin::ComponentHelpers - - describe "#call" do - it "returns an instance of the given component" do - component = mock_component do - def initialize(builder:); end - end - builder = double("builder") - - element = described_class.new(component: component) - - expect( - element.call(double("form"), builder) - ).to be_a(component) - end - - it "initializes the component with the given attributes" do - component = mock_component do - attr_reader :builder, :attributes - - def initialize(builder:, **attributes) - @builder = builder - @attributes = attributes - end - end - attributes = { foo: :bar } - element = described_class.new(component: component, **attributes) - - result = element.call(double("form"), double("builder")) - - expect(result.attributes).to eq(attributes) - end - - it "initializes the component with the given builder" do - component = mock_component do - attr_reader :builder - - def initialize(builder:) - @builder = builder - end - end - builder = double("builder") - element = described_class.new(component: component) - - result = element.call(double("form"), builder) - - expect(result.builder).to be(builder) - end - - it "infers the component class from the form dependencies when given as a Symbol" do - text_field_component_class = mock_component do - def initialize(builder:); end - end - element = described_class.new(component: :text_field) - component = SolidusAdmin::UI::Forms::Form::Component.new(elements: [element]) - - allow(component).to receive(:component).and_call_original - allow(component).to receive(:component).with('ui/forms/text_field').and_return(text_field_component_class) - - result = element.call(component, double("builder")) - - expect(result).to be_a(text_field_component_class) - end - end -end diff --git a/admin/spec/solidus_admin/form/element/fieldset_spec.rb b/admin/spec/solidus_admin/form/element/fieldset_spec.rb deleted file mode 100644 index c7938db84aa..00000000000 --- a/admin/spec/solidus_admin/form/element/fieldset_spec.rb +++ /dev/null @@ -1,54 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" -require "solidus_admin/form/element/fieldset" -require "solidus_admin/form/element/html" - -RSpec.describe SolidusAdmin::Form::Element::Fieldset do - include SolidusAdmin::ComponentHelpers - - describe "#call" do - it "returns an instance of the given component" do - component = mock_component - element = described_class.new(component: component, elements: []) - - expect( - element.call(double("form"), double("builder")) - ).to be_a(component) - end - - it "initializes the component with the given attributes" do - component = mock_component do - attr_reader :attributes - - def initialize(**attributes) - @attributes = attributes - end - end - attributes = { foo: :bar } - element = described_class.new(component: component, elements: [], **attributes) - - result = element.call(double("form"), double("builder")) - - expect(result.attributes).to eq(attributes) - end - - it "gives the concatenation of the rendered elements as the content of the component" do - component = mock_component - elements = [ - SolidusAdmin::Form::Element::HTML.new(html: "foo"), - SolidusAdmin::Form::Element::HTML.new(html: "bar") - ] - element = described_class.new(component: component, elements: elements) - form = SolidusAdmin::UI::Forms::Form::Component.new(elements: [element]) - - # Workaround for view_context not being available in specs - expect(form).to receive(:render_element).with(elements[0], any_args).and_return("foo") - expect(form).to receive(:render_element).with(elements[1], any_args).and_return("bar") - - result = element.call(form, double("builder")) - - expect(result.content).to eq("foobar") - end - end -end diff --git a/admin/spec/solidus_admin/form/element/html_spec.rb b/admin/spec/solidus_admin/form/element/html_spec.rb deleted file mode 100644 index e6c0a7de0e8..00000000000 --- a/admin/spec/solidus_admin/form/element/html_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" -require "solidus_admin/form/element/html" - -RSpec.describe SolidusAdmin::Form::Element::HTML do - describe "#call" do - it "returns itself" do - element = described_class.new(html: "foo") - - expect( - element.call(double("form"), double("builder")) - ).to be(element) - end - end - - describe "#render_in" do - it "returns the given HTML" do - element = described_class.new(html: "foo") - - expect( - element.render_in(double("view_context")) - ).to eq("foo") - end - end -end