Skip to content

Commit

Permalink
Use the correct type for component preview YARD param directives
Browse files Browse the repository at this point in the history
"[String]" didn't actually work, but since it defaults to "text" we
didn't notice.
  • Loading branch information
elia committed Aug 2, 2023
1 parent fc774dd commit c0c7e63
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def preview_signature
def preview_playground_yard_tags
return if attributes.blank?

attributes.map { |attr| "@param #{attr.name} [String]" }.join("\n ")
# See https://lookbook.build/guide/previews/params#input-types
attributes.map { |attr| "# @param #{attr.name} text" }.join("\n ")
end

def preview_playground_body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
class SolidusAdmin::UI::Badge::ComponentPreview < ViewComponent::Preview
include SolidusAdmin::Preview

# @param name [String]
# @param name text
def overview(name: "Label")
render_with_template(locals: { name: name })
end

# @param name [String]
# @param name text
# @param color select :color_options
# @param size select :size_options
def playground(name: "Label", color: :green, size: :m)
Expand Down
32 changes: 24 additions & 8 deletions admin/spec/generator/solidus_admin/component_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,32 @@

RSpec.describe SolidusAdmin::ComponentGenerator, type: :generator do
it "creates a component with the given name" do
run_generator %w[ui/foo]
run_generator %w[ui/foo bar baz]

aggregate_failures do
expect(engine_path('app/components/solidus_admin/ui/foo/component.rb').read).to include('class SolidusAdmin::UI::Foo::Component <')
expect(engine_path('app/components/solidus_admin/ui/foo/component.yml').read).to match(/^en:$/)
expect(engine_path('app/components/solidus_admin/ui/foo/component.html.erb').read).to start_with(%{<div class="<%= stimulus_id %>"})
expect(engine_path('app/components/solidus_admin/ui/foo/component.js').read).to include(%{export default class extends Controller})
expect(engine_path('spec/components/solidus_admin/ui/foo/component_spec.rb').read).to include(%{RSpec.describe SolidusAdmin::UI::Foo::Component})
expect(engine_path('spec/components/previews/solidus_admin/ui/foo/component_preview.rb').read).to include(%{class SolidusAdmin::UI::Foo::ComponentPreview < ViewComponent::Preview})
expect(engine_path('spec/components/previews/solidus_admin/ui/foo/component_preview/overview.html.erb').read).to include(%{<%= render component.new %>})
expect(engine_path('app/components/solidus_admin/ui/foo/component.rb').read)
.to include('class SolidusAdmin::UI::Foo::Component <')
.and include(%{def initialize(bar:, baz:)})

expect(engine_path('app/components/solidus_admin/ui/foo/component.yml').read)
.to match(/^en:$/)

expect(engine_path('app/components/solidus_admin/ui/foo/component.html.erb').read)
.to start_with(%{<div class="<%= stimulus_id %>"})

expect(engine_path('app/components/solidus_admin/ui/foo/component.js').read)
.to include(%{export default class extends Controller})

expect(engine_path('spec/components/solidus_admin/ui/foo/component_spec.rb').read)
.to include(%{RSpec.describe SolidusAdmin::UI::Foo::Component})

expect(engine_path('spec/components/previews/solidus_admin/ui/foo/component_preview.rb').read)
.to include(%{class SolidusAdmin::UI::Foo::ComponentPreview < ViewComponent::Preview})
.and include(%{# @param bar text})
.and include(%{# @param baz text})

expect(engine_path('spec/components/previews/solidus_admin/ui/foo/component_preview/overview.html.erb').read)
.to include(%{<%= render component.new(bar: "bar", baz: "baz") %>})
end
end

Expand Down

0 comments on commit c0c7e63

Please sign in to comment.