Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
josefarias committed Mar 8, 2024
1 parent 979ab72 commit b50d1e1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 38 deletions.
17 changes: 8 additions & 9 deletions app/presenters/hotwire_combobox/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def initialize \
view, autocomplete, id, name.to_s, value, form, async_src,
name_when_new, open, data, mobile_at, options, dialog_label

@combobox_attrs = input.reverse_merge(rest).with_indifferent_access
@combobox_attrs = input.reverse_merge(rest).deep_symbolize_keys
@association_name = association_name || infer_association_name
@custom_attrs = Hash.new { |h, k| h[k] = {} }
end
Expand All @@ -46,7 +46,9 @@ def custom_attrs_for(element, **attrs)
Valid elements are: #{CUSTOMIZABLE_ELEMENTS.join(", ")}.
MSG

@custom_attrs[element] = attrs
@custom_attrs[element] = attrs.deep_symbolize_keys.delete_if do |key, _|
PROTECTED_ATTRS.include? key
end
end


Expand Down Expand Up @@ -190,13 +192,10 @@ def pagination_attrs
:association_name, :custom_attrs

def customize(element, base: {})
custom = custom_attrs[element].dup.symbolize_keys.delete_if do |key, _|
PROTECTED_ATTRS.include? key
end

default = base.symbolize_keys.map do |key, value|
if value.is_a? String
[ key, view.token_list(value, custom.delete(key)) ]
custom = custom_attrs[element]
default = base.deep_symbolize_keys.map do |key, value|
if value.is_a?(String) || value.is_a?(Symbol)
[ key, view.token_list(value.to_s, custom.delete(key)) ]
else
[ key, value ]
end
Expand Down
9 changes: 5 additions & 4 deletions test/presenters/hotwire_combobox/component_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
class HotwireCombobox::ComponentTest < ApplicationViewTestCase
test "native html autocomplete is off by default" do
HotwireCombobox::Component.new(view, :foo).tap do |component|
assert_equal :off, component.input_attrs[:autocomplete]
assert_equal "off", component.input_attrs[:autocomplete]
end
end

test "native html autocomplete can be turned on" do
HotwireCombobox::Component.new(view, :foo, input: { autocomplete: :on }).tap do |component|
assert_equal :on, component.input_attrs[:autocomplete]
assert_equal "on", component.input_attrs[:autocomplete]
end
end

Expand All @@ -20,7 +20,7 @@ class HotwireCombobox::ComponentTest < ApplicationViewTestCase

assert_attrs html, tag_name: :input, id: "id-string"
assert_attrs html, tag_name: :input, name: "field-name"
assert_attrs html, tag_name: :input, role: :combobox
assert_attrs html, tag_name: :input, role: "combobox"
assert_attrs html, tag_name: :input, "aria-haspopup": "listbox"
assert_attrs html, tag_name: :input, "data-hw-combobox-target": "combobox"

Expand All @@ -32,6 +32,7 @@ class HotwireCombobox::ComponentTest < ApplicationViewTestCase
component.custom_attrs_for :input, class: "my-custom-class", data: { my_custom_attr: "value" }
html = render component

assert_attrs html, tag_name: :input, class: "hw-combobox__input my-custom-class", "data-my-custom-attr": "value"
assert_attrs html, tag_name: :input, class: "hw-combobox__input my-custom-class"
assert_attrs html, tag_name: :input, "data-my-custom-attr": "value"
end
end
49 changes: 24 additions & 25 deletions test/system/hotwire_combobox_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -674,37 +674,36 @@ class HotwireComboboxTest < ApplicationSystemTestCase
visit custom_attrs_path

assert_selector ".custom-class--fieldset"
assert_selector ".custom-class--hidden_field"
assert_selector ".custom-class--input"
assert_selector ".custom-class--handle"
assert_selector ".custom-class--listbox"
assert_selector ".custom-class--dialog"
assert_selector ".custom-class--dialog_wrapper"
assert_selector ".custom-class--dialog_label"
assert_selector ".custom-class--dialog_input"
assert_selector ".custom-class--dialog_listbox"
assert_selector ".custom-class--hidden_field", visible: :hidden
assert_selector ".custom-class--listbox", visible: :hidden
assert_selector ".custom-class--dialog", visible: :hidden
assert_selector ".custom-class--dialog_wrapper", visible: :hidden
assert_selector ".custom-class--dialog_label", visible: :hidden
assert_selector ".custom-class--dialog_input", visible: :hidden
assert_selector ".custom-class--dialog_listbox", visible: :hidden

assert_selector ".hw-combobox"
assert_selector ".hw-combobox__input"
assert_selector ".hw-combobox__handle"
assert_selector ".hw-combobox__listbox"
assert_selector ".hw-combobox__option"
assert_selector ".hw-combobox__option"
assert_selector ".hw-combobox__dialog"
assert_selector ".hw-combobox__dialog__label"
assert_selector ".hw-combobox__dialog__input"
assert_selector ".hw-combobox__dialog__listbox"

assert_selector "[data-customized-fieldset"
assert_selector "[data-customized-hidden-field"
assert_selector "[data-customized-input"
assert_selector "[data-customized-handle"
assert_selector "[data-customized-listbox"
assert_selector "[data-customized-dialog"
assert_selector "[data-customized-dialog-wrapper"
assert_selector "[data-customized-dialog-label"
assert_selector "[data-customized-dialog-input"
assert_selector "[data-customized-dialog-listbox"
assert_selector ".hw-combobox__listbox", visible: :hidden
assert_selector ".hw-combobox__option", visible: :hidden
assert_selector ".hw-combobox__dialog", visible: :hidden
assert_selector ".hw-combobox__dialog__label", visible: :hidden
assert_selector ".hw-combobox__dialog__input", visible: :hidden
assert_selector ".hw-combobox__dialog__listbox", visible: :hidden

assert_selector "[data-customized-fieldset]"
assert_selector "[data-customized-input]"
assert_selector "[data-customized-handle]"
assert_selector "[data-customized-hidden-field]", visible: :hidden
assert_selector "[data-customized-listbox]", visible: :hidden
assert_selector "[data-customized-dialog]", visible: :hidden
assert_selector "[data-customized-dialog-wrapper]", visible: :hidden
assert_selector "[data-customized-dialog-label]", visible: :hidden
assert_selector "[data-customized-dialog-input]", visible: :hidden
assert_selector "[data-customized-dialog-listbox]", visible: :hidden
end

private
Expand Down

0 comments on commit b50d1e1

Please sign in to comment.