-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c64c79f
commit 6bde654
Showing
9 changed files
with
137 additions
and
26 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
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class User < ActiveRecord::Base | ||
end |
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
29 changes: 8 additions & 21 deletions
29
spec/internal/test/components/previews/view_component/form/label_component_preview.rb
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
22 changes: 22 additions & 0 deletions
22
spec/internal/test/components/previews/view_component/form/submit_component_preview.rb
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require "view_component/form/test_helpers" | ||
|
||
module ViewComponent | ||
module Form | ||
class SubmitComponentPreview < ViewComponent::Preview | ||
include ViewComponent::Form::TestHelpers | ||
|
||
def default | ||
# TODO: maybe stop passing object_name to components since it is accessing from form_builder (delegate in BaseComponent) | ||
render ViewComponent::Form::SubmitComponent.new(form_builder, form_builder.object_name) | ||
end | ||
|
||
private | ||
|
||
def form_builder | ||
instanciate_form_builder(User.new) | ||
end | ||
end | ||
end | ||
end |
35 changes: 35 additions & 0 deletions
35
spec/internal/test/components/previews/view_component/form/text_area_component_preview.rb
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
require "view_component/form/test_helpers" | ||
|
||
module ViewComponent | ||
module Form | ||
class TextAreaComponentPreview < ViewComponent::Preview | ||
include ViewComponent::Form::TestHelpers | ||
|
||
def default | ||
@object = User.new | ||
|
||
# TODO: maybe stop passing object_name to components since it is accessing from form_builder (delegate in BaseComponent) | ||
render_f ViewComponent::Form::TextAreaComponent, :first_name | ||
end | ||
|
||
def with_value | ||
@object = User.new(first_name: "John\John") | ||
|
||
render_f ViewComponent::Form::TextAreaComponent, :first_name | ||
end | ||
|
||
|
||
private | ||
|
||
def render_f(component_klass, *args, **options) | ||
options[:object] ||= @object | ||
|
||
builder = instanciate_form_builder(options[:object]) | ||
|
||
render component_klass.new(builder, builder.object_name, *args, options) | ||
end | ||
end | ||
end | ||
end |
35 changes: 35 additions & 0 deletions
35
spec/internal/test/components/previews/view_component/form/text_field_component_preview.rb
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
require "view_component/form/test_helpers" | ||
|
||
module ViewComponent | ||
module Form | ||
class TextFieldComponentPreview < ViewComponent::Preview | ||
include ViewComponent::Form::TestHelpers | ||
|
||
def default | ||
@object = User.new | ||
|
||
# TODO: maybe stop passing object_name to components since it is accessing from form_builder (delegate in BaseComponent) | ||
render_f ViewComponent::Form::TextFieldComponent, :first_name | ||
end | ||
|
||
def with_value | ||
@object = User.new(first_name: "John") | ||
|
||
render_f ViewComponent::Form::TextFieldComponent, :first_name | ||
end | ||
|
||
|
||
private | ||
|
||
def render_f(component_klass, *args, **options) | ||
options[:object] ||= @object | ||
|
||
builder = instanciate_form_builder(options[:object]) | ||
|
||
render component_klass.new(builder, builder.object_name, *args, options) | ||
end | ||
end | ||
end | ||
end |